In emacs, can I have one set of line break options for code and one for text?

After quite a bit of experimentation, I think I like:

(setq truncate-lines nil) (setq word-wrap t) 

for editing text but

 (setq truncate-lines t) (setq word-wrap nil) 

for programming.

In all modes, I like:

 (setq fill-column 80) 

so that I can use Mq and Cu Mq to translate the text into 80 columns, but also found that I do not like the auto-fill mode and will never want it to be turned on.

I am also not so addicted to visual-line-mode (or at least a bit that is not word-wrap )

Is there some kind of spell that I can put in my .emacs file that will make me happy?

I am happy to be happy: "all this just does what I want, and I no longer need to think about it."

+6
source share
3 answers

Use prog-mode-hook and text-mode-hook to set these variables:

 (add-hook 'text-mode-hook '(lambda () (setq truncate-lines nil word-wrap t))) 

and

 (add-hook 'prog-mode-hook '(lambda () (setq truncate-lines t word-wrap nil))) 
+7
source

Sorry for not giving the source code in my answer, but I can assure you that the setting you mean is possible. It only depends on your definition of "programming modes". Most modes have a so-called hook function (see http://www.gnu.org/software/emacs/manual/html_node/emacs/Hooks.html ). These are mainly functions that are executed when the mode loads. Such a hook then adjusts the settings you have in mind.

+2
source

(setq truncate-lines t) still not working?

Culprit may be a different way. The visual-line mode was mine (global-visual linear mode), so I had to enable the disable function:

 (add-hook 'neotree-mode-hook (lambda () (visual-line-mode -1) (setq truncate-lines t))) 
+1
source

Source: https://habr.com/ru/post/913650/


All Articles