Can't properly disable flyspell in org mode - emacs

I set up emacs to turn flyspell on by default for text mode using
(add-hook 'flyspell-mode-hook 'flyspell-buffer)
(add-hook 'text-mode-hook 'flyspell-mode)
I would like to disable it automatically in org mode files, and I did manage to disable it using a lambda function in the org mode hook:
(add-hook 'org-mode-hook (lambda () (flyspell-mode -1)))
This works, but the syntax highlight changes that flyspell did still remain, and interfere with org mode's syntax highlight. I also see in the minibuffer that flyspell does run when I visit that file, so apparently it is turned off only afterwards. How do I turn it off in such a way that would leave no trace of it in the org mode file, or better yet not run at all?

You can selectively enable flyspell in text-mode hook by checking the major-mode. The following will enable flyspell in text-mode and its derived modes except org-mode
(add-hook 'flyspell-mode-hook 'flyspell-buffer)
(add-hook 'text-mode-hook (lambda ()
(when (not (equal major-mode 'org-mode))
(flyspell-mode t))))

Regarding the first question (remove the highlightings), the following call should do it:
(flyspell-delete-all-overlays)
However, are you really, really, really sure you want to disable flyspell in Org mode??? Is there a really, really, really good reason for that?
If yes, shouldn't you solve that one, instead of trying the above?

Related

Disable fill in xml-mode

I'm trying to configure Emacs to not activate Auto-Fill when editing an XML document.
In my .emacs file, I add a hook so that text mode will have Auto-Fill on by default:
(add-hook 'text-mode-hook 'turn-on-auto-fill)
I have added a directory to my load path:
(add-to-list 'load-path "~/.emacs.d/lisp/")
Inside that directory, I have written a file xml.el for this workstation, and I have tried each of the following in it, to no avail:
(add-hook 'xml-mode-hook 'turn-off-auto-fill)
(add-hook 'xml-mode-hook 'auto-fill-mode)
(remove-hook 'xml-mode-hook 'turn-on-auto-fill)
(remove-hook 'xml-mode-hook 'auto-fill-mode)
How can I disable Auto-Fill in XML mode?
EDIT: It appears this is caused by my text-mode-hook mentioned above. How can I override this hook in nxml-mode?
Ah, nxml-mode derives from text-mode. That's slightly surprising to me (although on closer inspection, it does appear to be standard for markup language modes in Emacs).
In that case you can either disable it again in nxml-mode-hook (as text-mode-hook has already run by that point):
(add-hook 'nxml-mode-hook 'turn-off-auto-fill)
(n.b. you said in the comments that this didn't work for you, but it certainly works for me).
or else just change your text-mode-hook code to something like the following, in order to catch this case before auto-fill is enabled:
(defun my-text-mode-hook ()
"Custom behaviours for `text-mode'."
;; Enable `auto-fill-mode', except in `nxml-mode' (which is derived
;; from `text-mode').
(unless (eq major-mode 'nxml-mode)
(turn-on-auto-fill)))
(add-hook 'text-mode-hook 'my-text-mode-hook)

how to enable Show-Paren mode only for *.el files

How can I enable Show-Paren mode only for *.el files?
I have tried
(add-hook 'emacs-lisp-mode-hook '(lambda()
(show-paren-mode 1)
))
But it still enables Show-Paren mode for all the cases. Even in *scratch* buffer I have Show-Paren mode enabled.
As already said, show-paren-mode is a global minor mode. That said, one might be able to run it only on some buffer with something like:
(show-paren-mode) ;; activate the needed timer
(setq show-paren-mode ()) ;; The timer will do nothing if this is nil
(defun show-paren-local-mode ()
(interactive)
(make-local-variable 'show-paren-mode) ;; The value of shom-paren-mode will be local to this buffer.
(setq show-paren-mode t))
(add-hook 'emacs-lisp-mode-hook 'show-paren-local-mode)
It's untested, it might not work. Looking at the doc in might work, but looking at the code it might work. This might work only with some version of show-paren-mode.
show-paren-mode is a global minor-mode. It means exactly how it sounds.
This is very much by design, as most people (myself included) find this
minor-mode helpful across all buffers. Why do you want to disable it for any
file?
from the documentation
Show Paren mode is a global minor mode. When enabled, any
matching parenthesis is highlighted in show-paren-style' after
show-paren-delay' seconds of Emacs idle time.
Your code is correct. However, you should consider the fact that the *scratch* buffer's major mode is lisp-interaction-mode which derives from emacs-lisp-mode (which is mostly irrelevant) and the mode's definition:
(define-minor-mode show-paren-mode
"Toggle visualization of matching parens (Show Paren mode).
With a prefix argument ARG, enable Show Paren mode if ARG is
positive, and disable it otherwise. If called from Lisp, enable
the mode if ARG is omitted or nil.
Show Paren mode is a global minor mode. When enabled, any
matching parenthesis is highlighted in `show-paren-style' after
`show-paren-delay' seconds of Emacs idle time."
:global t :group 'paren-showing
...)
:global t is the key thing here - the mode is global and is enabled in all buffers regardless of their major mode.
I think you can use
(setq-default show-paren-data-function #'ignore)
(show-paren-mode)
to formally enable the mode but keeping it quiet. And then something like
(defun set-up-emacs-lisp-mode ()
(setq-local show-paren-data-function #'show-paren--default))
(add-hook 'emacs-lisp-mode-hook #'set-up-emacs-lisp-mode)
to enable it in Emacs Lisp buffers. I've not tested this set-up, only the opposite (usually enabled, disabled just in Text Mode).
I used to use (setq-local show-paren-mode nil) but this makes Emacs highlight the braces in Ido promps, so I prefer (setq-default show-paren-data-function #'ignore).

How can I disable auto-fill mode in Emacs?

Today I got my new PC (Windows 7, 32 bit) and installed Vincelt Goulets Emacs. The only other thing I did was updating Org-mode.
Now, I am stuck with auto-fill-mode on every time I start Emacs new, which I hate. I would like to turn auto-fill-mode off, for now and forever. I even deleted my .emacs file, but auto-fill-mode was still turned on.
The only solution that worked was (a) a nasty workaround or (b) always typing M-x auto-fill-mode every time I start Emacs anew.
Is there a solution?
To be clear, the only thing the current .emacs file contains is: '(inhibit-startup-screen t)
Add to your .emacs,
(auto-fill-mode -1)
If there are hooks for specific modes, you will need to zap those as well. My suspicion is that you do not actually have auto-fill-mode on by default in all modes, but with the information you have supplied, at least this should be a starting point.
A reasonable safeguard would be to also disable auto-fill mode from `text-mode-hook':
(remove-hook 'text-mode-hook #'turn-on-auto-fill)
You may need something similar for other modes as well.
Assuming that he has not made fundamental changes, you have several paths:
You can just turn off the mode globally in your .emacs file:
(turn-off-auto-fill)
;; ...or (auto-fill-mode -1)
Since Emacs of that vintage also turns on auto-fill for text-mode, add:
(remove-hook 'text-mode-hook 'turn-on-auto-fill)
That should account for all the default places, but check the major mode hooks if you have other modes enabling this automatically.
If you'd like to keep it turned-on in most text-mode while disable auto-fill in specific modes, e.g. org-mode in my case, you could use the following:
;; turn on auto-fill for text-mode
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; turn off auto-fill for org-mode
(add-hook 'org-mode-hook 'turn-off-auto-fill)

how to disable hl-line feature in specified mode

i enable hl-mode in global scope with the following code.
(global-hl-line-mode t)
to turn off hl-line feature in a specified mode. i do it with the following code.
(add-hook 'org-mode-hook (lambda () (global-hl-line-mode 0)))
but it turns off the hl-line feature for global scope.
how to disable hl-line feature in a specified mode?
There is often information and documentation in the Commentary
section in the source file.
[...]
;; You could make variable `global-hl-line-mode' buffer-local and set
;; it to nil to avoid highlighting specific buffers, when the global
;; mode is used.
[...]
Thus, you can put something like this in your .emacs.
(global-hl-line-mode)
(make-variable-buffer-local 'global-hl-line-mode)
(add-hook 'some-mode-hook (lambda () (setq global-hl-line-mode nil)))
...
use hl-line-mode insted of global-hl-line-mode.
EDIT: You're right. This doesn't work.
The commentary says that the global-mode isn't meant to be used. I take it to
mean that you can't selectively disable it once enabled.
I enable the hl-line-mode in major-mode hooks where I need it.
write the following line in your dotEmacs file, and use f5 to toggle the hl-line-mode
(global-set-key [f5] 'hl-line-mode)

Emacs disable modes

I'd like to disable line highlighting in term-mode. I tried this:
(add-hook 'term-mode-hook '(lambda () (global-hl-mode 0)))
but it complains about the symbol being void.
I have this further in my .emacs:
(global-hl-line-mode 1)
I agree with Ashutosh that that may be the source of your symbol error, but I'm not sure that that's the right approach anyways. I'm pretty sure that will disable highlighting everywhere, not just in terminal windows, when you load a terminal window.
I think the right thing is this:
(add-hook 'term-mode-hook '(lambda() (set (make-local-variable 'global-hl-line-mode) nil)))
...I'm going off hl-line.el where it says this:
;; You could make variable `global-hl-line-mode' buffer-local and set
;; it to nil to avoid highlighting specific buffers, when the global
;; mode is used.