Suppress emacs auto-complete in selected region

I use emacs to edit everything. On some of my LateX documents, I would like to automatically turn off autocomplete when I edit tables and code. Basically, I would like to have two tags, for example:

%%% BEGIN NO FILL %%% END NO FILL 

and nothing in between will be autocomplete.

Can anyone think of how to do this? I need to find out if the cursor is inside the area, and then switch the mode and will need to do this every time the cursor moves. Or is there a better way to do this?

+6
emacs elisp latex
source share
4 answers

Got it. Check this:

 (defun in-no-auto-fill-region () (> (save-excursion (or (search-backward "%%% BEGIN NO FILL" (point-min) t) 0)) (save-excursion (or (search-backward "%%% END NO FILL" (point-min) t) 0)) )) (defun previous-line-checking-auto-fill (arg) (interactive "P") (previous-line arg) (if (in-no-auto-fill-region) (turn-off-auto-fill) (turn-on-auto-fill))) (defun next-line-checking-auto-fill (arg) (interactive "P") (next-line arg) (if (in-no-auto-fill-region) (turn-off-auto-fill) (turn-on-auto-fill))) (add-hook 'LaTeX-mode-hook '(lambda nil (local-set-key "Cp" 'previous-line-checking-auto-fill) (local-set-key "Cn" 'next-line-checking-auto-fill) (auto-fill-mode 1) )) 
+1
source share

If you are using AUCTeX (you should be), you can check the LaTeX-indent-environment-list . Adding an environment to this variable will make (among other things) Mq not fill up the paragraph. Unfortunately, this does not look like automatic fill mode. The following largely unverified code added to LaTeX-mode-hook may do what you want.

 (setq auto-fill-function (lambda () (unless (> (save-excursion (or (search-backward "%%% BEGIN NO FILL" (point-min) t) 0)) (save-excursion (or (search-backward "%%% END NO FILL" (point-min) t) 0))) (do-auto-fill)))) 

This is very stupid and inefficient, but it seems to work quite quickly on my machine. It does not allow nesting and requires that you manually mark all sections that you do not want to fill. What I'm going to add to my .emacs (until I read your question, I did not understand how much it bothers me) is below the keys of the current environment, so there is no need for special markup (although it looks only at the most internal environment (I'm not sure what the problem is that will cause in practice)). The combination of these two functions remains as an exercise for the interested reader.

 ;; You can use the following to unset the variables and play around with them ;; (makunbound 'auto-fill-ignore-environments) ;; (makunbound 'auto-fill-ignore-environments-regexp) (defcustom auto-fill-ignore-environments (mapcar 'car LaTeX-indent-environment-list) "List of environments for which `auto-fill-mode' should be disabled. Used to generate `auto-fill-ignore-environments-regexp'." :type '(sexp) ) (defcustom auto-fill-ignore-environments-regexp (regexp-opt auto-fill-ignore-environments) "Regexp matching LaTeX environments for which `auto-fill-mode' should be disabled. If not set, automatically generated from `auto-fill-ignore-environments'" :type '(string) :set-after '(auto-fill-ignore-environments) ) (add-hook 'LaTeX-mode-hook (lambda () (setq auto-fill-function (lambda () (unless (string-match auto-fill-ignore-environments-regexp (LaTeX-current-environment)) (do-auto-fill)))))) 

I have never used defcustom before, so I'm sure that the part can be improved quite a bit.

+2
source share

Alternatively, you can disable autocomplete and use Mq to format paragraphs. I do not like autocomplete, so I use it in every mode.

0
source share

If you want to follow the path of advising / redefining all movement functions, this should help:

 (defmacro movement-advice (func) `(defadvice ,func (after ; run this after the original function is done (and point has moved) ;; Give it a unique name ,(intern (concat (symbol-name func) "-auto-fill-auto-off")) ;; Hopefully this satisfies the arguments of any function we can throw at it (&rest args) ;; turn it on activate ) "Turn auto-fill-mode on or off automatically." (auto-fill-mode (not (in-no-auto-fill-region))))) (dolist (func '(next-line previous-line forward-paragraph backward-paragraph mouse-drag-region ;; Whatever you use )) (eval `(movement-advice ,func))) 
0
source share

All Articles