How can I disable auto-fill mode in Emacs? - 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)

Related

Emacs: Disable auto-fill minor mode when in idlwave major mode

In Emacs how do I stop the auto-fill minor mode from loading when I start the idlwave major mode?
So far I have been completely unsuccessful at figuring out how to do this. I have tried to use remove-hook for both idl-mode-hook and text-mode-hook without success.
You might have enabled auto-fill-mode as a global minor mode, so it is on in all buffers by default. If that is the case, the task is not so much not turning it on in idlwave-mode but rather turning it off.
Most major modes provide a special hook variable: it's a list containing functions that are called whenever that major mode is invoked. For instance, with the following line you can make sure that auto-fill-mode will get turned off each time a buffer goes into idlwave-mode:
(add-hook 'idlwave-mode-hook (lambda () (auto-fill-mode 0)))
Put the above line in your init file (e.g. ~/.emacs or ~/.emacs.d/init.el) and auto-fill-mode should be turned off in idlwave mode after you restarted Emacs.

How do I disable line numbers in Helm buffers?

I'm using linum to show line numbers. What I want is to have them enabled by default, but disabled in certain major modes, like eshell, compilation, etc.
This works well, but what I can't figure out is how to disable them in Helm buffers.
There doesn't seem to be a major mode I can hook into
(add-hook 'helm-before-initialize-hook '(lambda () (linum-mode 0))) turns off line numbers globally. Not sure how to disable linum for the current buffer only, since Helm buffers usually appear alongside another one
Tried advice around helm-find-files, but doesn't seem to work
I didn't have linum-off set up properly. It overrides a function which global-linum-mode calls, so the latter has to be active in order for it to work.
; init.el
(require 'linum-off)
(global-linum-mode t)

In Emacs, how to disable auto-fill-paragraph mode when in php-mode?

Normally, I need to enable the auto-fill-mode, so I have it turned on in .emacs. But when editting PHP in php-mode, I'd like to not use auto-fill-mode. Is there way to set it in .emacs such that when I'm in PHP mode, the auto-fill-paragraph mode is automatically turned off and when I leave php-mode, it's automatically turned on, barring other overriding?
Update: a closer examination of the .emacs revealed that auto-fill is set up by
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(column-number-mode t)
...
'(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
...)
Some major-modes inherit certain settings from other modes (e.g., text-mode is used by many popular major modes). The following code snippet can be used to disable a feature for a particular major-mode using its mode hook:
(add-hook 'php-mode-hook (lambda ()
(auto-fill-mode -1) ))
It is sometimes helpful to check and see whether a particular feature has been enabled globally or locally, which in turn can give a clue as to whether that feature has been inherited by a major mode. In this case, the documentation for auto-fill-mode states as follows -- https://www.gnu.org/software/emacs/manual/html_node/emacs/Auto-Fill.html:
"Auto Fill mode is a buffer-local minor mode (see Minor Modes) in which lines are broken automatically when they become too wide. Breaking happens only when you type a <SPC> or <RET>."

Can't properly disable flyspell in org mode

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?

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).