(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.)
cjm
source share