From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: Doing things only in a particular mode Date: 24 Aug 2015 17:18:00 GMT Message-ID: References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1440436819 15137 80.91.229.3 (24 Aug 2015 17:20:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 24 Aug 2015 17:20:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 24 19:20:19 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZTvPv-0004gg-7D for geh-help-gnu-emacs@m.gmane.org; Mon, 24 Aug 2015 19:20:19 +0200 Original-Received: from localhost ([::1]:55726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTvPu-0002YD-LB for geh-help-gnu-emacs@m.gmane.org; Mon, 24 Aug 2015 13:20:18 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 62 Original-X-Trace: individual.net swsJUMehh5JlQ7Fgw3UmnQ4tvIVdD37BrYM/Yia5uXHR6Xbu8r Cancel-Lock: sha1:mIsGY0adKa6minWyWZmsbaErbhE= Mail-Copies-To: nobody X-Editor: Emacs of course! User-Agent: slrn/pre1.0.0-18 (Linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:214518 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:106802 Archived-At: Colin Yates wrote: > (newbie warning). > > So I understand about (add-hook...) but I can't find the hook I > want. Basically, I have visual-line-mode turned on globally, but I want > to disable it when I view the headers in mu4e. > > The buffer is called *mu4e-headers* and I can see the major mode is > mu4e-headers but the following code has no effect: > > (add-hook 'mu4e-headers-hook > (lambda () > (visual-line-mode 0))) Well, the hook is actually called `mu4e-headers-mode-hook`, so if you use that, it should work. To check if a variable exists, or find one if you have some idea what it might be called, you can use `C-h v`, type the name and hit RET. TAB completion works, so typing e.g., `C-h v mu4e-headers-hook TAB` would have found the right variable for you. BTW, the general advice is to not use lambdas in hook variables, just function names. You might not really care, but if you want to be pedantically correct about things, you could write: (defun my-mu4e-headers-function () ; use whatever name you see fit (visual-line-mode -1)) (add-hook 'my-mu4e-headers-function) Note that I use `-1` as the argument to `visual-line-mode`. IIRC an argument of 0 would actually activate the mode. > I am not sure how 'hooks' are created - I searched through the source > code for my4e-headers-hook but couldn't find it. They are created automatically when you create a major or minor mode with `define-derived-mode` or `define-minor-mode`, so that's why you couldn't find it by grepping the source. > Assuming this is the right approach, how can I say 'when the major mode > is X then do this'. What is the idiomatic Emacs way? Well, one can argue about the meaning of "idiomatic", but here's how one could do it: (when (eq major-mode 'mu4e-headers-mode) (do this) (and that)) Note, however, that in a mode major hook, there's no need to use this, because if the mode were anything else, the hook wouldn't be run. It could be useful in an Elisp program or in a (function called in a) minor mode hook, though. HTH -- Joost Kremers joostkremers@fastmail.fm Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9)