From: Alan M. <ac...@mu...> - 2014-12-17 10:04:41
|
Hello, John. On Tue, Dec 16, 2014 at 03:25:41PM -0500, John Yates wrote: > Alan, > This thread hit close to home. I have frustrations with the new electric > behavior and wonder whether you have any words of wisdom. > My frustration is not with the indentation *per se* but rather with the > fact that it litters m source with unwanted trailing white space, made all > the more glaring because font locking high lights in in a garish color. You could chose a more restrained colour theme, or even individually customise the font-lock-... faces to something less garish. > Is there anyway to arrange for automatic removal of the indentation the > moment I leave a line which I have left empty? This would be worth a bug report (feature request) on bug...@gn..., or perhaps a discussion on ema...@gn.... I don't think there is an existing way to do what you want. I'm sure you're aware of M-x delete-trailing-whitespace, but that's not automatic. Something like the following (untested) should work. But it would delete _all_ trailing space from _all_ files, and this might not be what you want - it could leave lots of changed text files where the trailing space is meaningful, for example. What the following (untested) code does is to note the presence of trailing space on the current line in pre-command-hook, and then to delete it in post-command-hook. If the command executed changes the buffer, then this is not done. (defvar jy-EOL-with-trailing-space nil) (defvar jy-buffer-with-trailing-space nil) (defun jy-note-trailing-space () (save-excursion (end-of-line) (when (memq (char-before) '(?\ ?\t)) (setq jy-EOL-with-trailing-space (point)) (setq jy-buffer-with-trailing-space (current-buffer))))) (defun jy-exclude-change-commands (beg end old-len) (setq jy-EOL-with-trailing-space nil) (setq jy-buffer-with-trailling-space nil)) (defun jy-delete-trailing-space () (if (and jy-EOL-with-trailing-space jy-buffer-with-trailing-space) (with-current-buffer jy-buffer-with-trailing-space (if (not buffer-read-only) (save-excursion (goto-char jy-EOL-with-trailing-space) (while (memq (char-before) '(?\ ?\t)) (delete-char -1)))))) (setq jy-EOL-with-trailing-space nil) (setq jy-buffer-with-trailing-space nil)) (add-hook 'pre-command-hook 'jy-note-trailing-space) (add-hook 'after-change-functions 'jy-exclude-change-commands) (add-hook 'post-command-hook 'jy-delete-trailing-space t) > /john -- Alan Mackenzie (Nuremberg, Germany). |