How to make Emacs not highlight trailing whitespace in term? - emacs

I'm using this in my .emacs config
'(show-trailing-whitespace t)
And I'm generally very happy with it.
The only problem is that it highlights whitespace when I'm in 'M-x term' buffer and I have no control over that whitespace. How to prevent this?

Use this:
(add-hook
'term-mode-hook
(lambda() (setq show-trailing-whitespace nil)))

Related

How to disable auto-indentation on newline in js2-mode?

I'm editing React .jsx files, and I don't want to indent on newline, how to disable it?
M-x electric-indent-local-mode should do it if you're using Emacs-24.4.
What seems to work in Emacs 25.1.1 is setting electric-layout-mode to -1.
So In js2-mode-hook add:
(add-hook 'js2-mode-hook (lambda () (electric-layout-mode -1)))

How to turn off ‘tab’ highlighting in go buffers?

I’ve just started writing Go programs in Emacs. How can I turn off tabs highlighting in go-mode buffers? I use «whitespace» for whitespace chars highlighting. Go btw is the only mode where I don’t want tabs highlighted since tabs are standard formatting in Go.
Sincerely, Pavel.
To be clear, you're doing something like
(require 'whitespace)
(global-whitespace-mode t)
right? You can disable whitespace-mode for go-mode with
(setq whitespace-global-modes '(not go-mode))
There is a related question on emacs stack exchange.
I found that this
(add-hook 'go-mode-hook
(lambda ()
(add-hook 'before-save-hook 'gofmt-before-save)
(setq whitespace-style '(face empty trailing lines-tail))
(setq tab-width 4)
(setq indent-tabs-mode 1)))
Worked a bit better for me. Leaves whitespace-mode on but doesn't highlight tabs. Also runs go fmt before save and sets tab width to 4. I'm using prelude.
Add this line
(whitespace-toggle-options '(tabs)))
To your go-mode hook e.g
(use-package go-mode
:preface
(defun go-mode-config ()
(whitespace-toggle-options '(tabs)))
:config
(add-hook 'go-mode-hook (lambda ()
(go-mode-config))))
Taken from prelue go config

How do I disable electric indent on RET but still keep other electric characters (e.g., ‘{’)?

In Emacs 24.4, the default indentation behavior has been changed—new lines are now automatically indented. From the release notes:
*** `electric-indent-mode' is now enabled by default.
Typing RET reindents the current line and indents the new line.
`C-j' inserts a newline but does not indent. In some programming modes,
additional characters are electric (eg `{').
I prefer the old behavior, so I added
(electric-indent-mode 0)
to my .emacs file. However, this disables all electric characters, which is not what I intended.
Is there any way to disable the new behavior while still having characters like ‘{’ or ‘:’ trigger an indentation?
You want to remove ?\n from electric-indent-chars. You can do this globally with:
(setq electric-indent-chars (remq ?\n electric-indent-chars))
or only in a particular mode (e.g. C):
(add-hook 'c-mode-hook
(lambda ()
(setq-local electric-indent-chars (remq ?\n electric-indent-chars))))
By checking the documentation for c-electric-brace, I found that the behavior of electric characters is controlled by the buffer-local variable c-electric-flag. It worked after I added the following lines to my .emacs file:
(add-hook 'c-mode-hook
(lambda ()
(set 'c-electric-flag t)))
(add-hook 'c++-mode-hook
(lambda ()
(set 'c-electric-flag t)))

Emacs: Turn off indentation when doing a paragraph fill in LaTeX mode

When I am using emacs to edit a latex document the paragraph fill (Esc-q) does not do what I want. For example, something like:
The component \vn{%vec} is not similar to
When I use fill I get:
The component \vn{%vec} is not
% similar to
That is, emacs is taking "%" to be a comment character and filling the paragraph accordingly. However, "\vn" is a macro of mine that sets text in texttt mode and here "%" is simply a regular printable character so the paragraph fill has done things incorrectly.
So what I want is for paragraph fill to be the same it is as in text-mode. That is, no indentation and no adding extra characters. But I don't want to have to toggle between text-mode and latex-mode every time I want to paragraph fill. Is there any way to do this?
Thanks for the help. -- David
PS: Yes, I do know that if there are real comments at the end of lines then the test-mode fill will not do things correctly. But I never put comments at the end of lines so this will never bother me.
I found the solution. I put this in my init.el file:
(add-hook 'latex-mode-hook '(lambda() (setq comment-start nil)))
(add-hook 'tex-mode-hook '(lambda() (setq comment-start nil)))
(add-hook 'latex-mode-hook '(lambda() (setq fill-indent-according-to-mode nil)))
(add-hook 'tex-mode-hook '(lambda() (setq fill-indent-according-to-mode nil)))
I love emacs but the documentation (or lack thereof) can sometimes drive me crazy... :).
You can try:
(setq comment-start nil)
to handle this specific case.
What you're trying to fix is a symptom of the real problem -- latex-mode is
naively marking code after "%" as comment.
Does installing auctex-mode fix your problem?

emacs auto-fill-mode doesn't initialise

I want to enable line-wrapping without having to type 'M-x auto-fill-mode' everytime I start emacs. I've tried putting (setq auto-fill-mode 1) and (auto-fill-mode 1) in the .emacs file, but neither work. Why is this, and how do I fix it?
Thanks
It is a minor-mode so you need to enable it for the modes where you want it used. So, for example, if you want auto-fill-mode enabled in text mode, you need to add the following to your .emacs file:
(add-hook 'text-mode-hook '(lambda ()
(auto-fill-mode 1)))
auto-fill-mode is a minor mode so (setq auto-fill-mode 1) wont start it.
You can add a hook to start auto-fill-mode with the text-mode (with which it is normally used) or any other mode you normally use it with, by doing
(add-hook 'text-mode-hook 'turn-on-auto-fill)
Alternatively, if you want the auto-fill-mode on for all the files you edit. You can start it when any type of file is opened with:
(setq auto-mode-alist (cons '("*" . auto-fill-mode) auto-mode-alist))
But having it always on is irritating at times, so its better to bind the starting of the mode to a familiar key sequence
(global-set-key (kbd "C-c q") 'auto-fill-mode)