Emacs: Visual Linear Mode and Paragraph Paragraph

Now I am using Emacs 23 with visual line transform for text editing, but I continue to use Mq out of habit (thus adding trailing line endings). I wonder if there is a way to add a condition to disable a paragraph-paragraph (or remove the binding to Mq) for modes in which the visual line mode is turned on, but for re-enabling it for those in which I'm still using autofill mode? Thanks!

+6
emacs elisp
source share
3 answers
(defun maybe-fill-paragraph (&optional justify region) "Fill paragraph at or after point (see `fill-paragraph'). Does nothing if `visual-line-mode' is on." (interactive (progn (barf-if-buffer-read-only) (list (if current-prefix-arg 'full) t))) (or visual-line-mode (fill-paragraph justify region))) ;; Replace Mq with new binding: (global-set-key "\Mq" 'maybe-fill-paragraph) 

Instead of using global-set-key you can also rebuild Mq only in certain modes. (Or you can change the global snapping and then bind Mq to fill-paragraph in a specific mode.) Note that many modes are automatically loaded, so their layout may not be detected until the mode is activated. To establish a binding to a specific mode, I usually use this function:

 (add-hook 'text-mode-hook (defun cjm-fix-text-mode () (define-key text-mode-map "\Mq" 'maybe-fill-paragraph) (remove-hook 'text-mode-hook 'cjm-fix-text-mode))) 

( remove-hook not strictly necessary, but the function should only be run once.)

+7
source share

You can use advice for this.

For your .emacs:

 (defadvice fill-paragraph (around disable-for-visual-line-mode activate) (unless visual-line-mode ad-do-it)) 

This will change the paragraph to paragraph to do nothing when visual line mode is on. You can also add an error if you wish.

+5
source share

visual-linear mode has its own key map: visual-line-mode-map . I recommend reordering Mq only in this layout.

The map is defined as part of the launch, so you do not need eval-after-load. Just turn off snapping in this mode:

 (define-key visual-line-mode-map [remap fill-paragraph] 'ignore) 
+2
source share

All Articles