emacshorrors.com - Emacs Horrors - Index

Example domain paragraphs

Originally I planned to blog about a fun hack, porting the infamous cloud-to-butt browser extension to Emacs. The idea was that whenever you interact with subprocesses instances of “cloud” would be replaced with “butt”, I picked shell.el for ease of hacking [1] . The following snippet is loosely modeled after ansi-color-process-output , so pardon any weirdness.

( defun my-filter-shell-output ( string ) ( let (( start-marker comint-last-output-start ) ( end-marker ( process-mark ( get-buffer-process ( current-buffer ))))) ( save-excursion ( goto-char start-marker ) ( while ( search-forward "cloud" end-marker t ) ( replace-match "butt" ))))) ( with-eval-after-load 'shell ( add-hook 'comint-output-filter-functions 'my-filter-shell-output t )) The API is somewhat murky. A comint output filter function receives a string argument and is expected to modify the buffer. Th

[wasa@box ~]$ echo cloud echo butt butt [wasa@box ~]$ echo butt butt [wasa@box ~]$ echo ponies ponies Something is definitely wrong here, an extra line is printed if and only if the replacement would have happened. Most curiously, it doesn’t mirror the user input, but has the replacement as well. After debugging this a bit [2] I remembered that long time ago I’ve set comint-process-echoes because M-x shell kept printing the user input after sending it to the shell. Time to gaze into the abyss:

Links to emacshorrors.com (1)