From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Colin Yates Newsgroups: gmane.emacs.help Subject: Re: Doing things only in a particular mode Date: Mon, 24 Aug 2015 18:30:34 +0100 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1440437459 25939 80.91.229.3 (24 Aug 2015 17:30:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 24 Aug 2015 17:30:59 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Joost Kremers Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 24 19:30:57 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 1ZTvaD-0004JJ-7T for geh-help-gnu-emacs@m.gmane.org; Mon, 24 Aug 2015 19:30:57 +0200 Original-Received: from localhost ([::1]:55773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTvaC-0006Ic-DR for geh-help-gnu-emacs@m.gmane.org; Mon, 24 Aug 2015 13:30:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTvZx-0006IQ-06 for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 13:30:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTvZt-0000xh-Qf for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 13:30:40 -0400 Original-Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]:33137) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTvZt-0000xW-Aq for help-gnu-emacs@gnu.org; Mon, 24 Aug 2015 13:30:37 -0400 Original-Received: by wijp15 with SMTP id p15so84647165wij.0 for ; Mon, 24 Aug 2015 10:30:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:from:to:cc:subject:in-reply-to:date:message-id :mime-version:content-type; bh=xmsh8V3l5C5MiK+wESlh8Zr6JQHJrOS8E4o1EY9zAEk=; b=TrmpeoOuTdhPEs4T+O4iqUn/wZKw8d+nBHzBpXGhq1JCOhqIp9nsKCthwNN80aAdTt 9+JlTzJMDqOG4f6vJxwsLGjyOBXnWCkNT4iwTWzZB2ChhAsIk5h1ymLp48rXW6pxflzI U4PNkLfR9gvp0+PNrhoE7l+BR/hsZheikC5uyN24l/HvYGXIOLWe9asSfKyjiDAG6ENV pxIIPwXZNFaRSQocbSiWziriwEvIKLJho5KV7GaBOyOFwdqVjKi3j/At1W7kEIoAhXPb 39MD7NNclC5ikix1ZCjY0k3EnkdWGP919Iv5QFhx6mi9sA4FhAGeUq/3cg/TSzzFcnpa GVdA== X-Received: by 10.180.39.201 with SMTP id r9mr29944428wik.92.1440437436669; Mon, 24 Aug 2015 10:30:36 -0700 (PDT) Original-Received: from localhost (cpc13-leic14-2-0-cust169.8-1.cable.virginm.net. [86.24.148.170]) by smtp.gmail.com with ESMTPSA id fb3sm17120955wib.21.2015.08.24.10.30.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Aug 2015 10:30:35 -0700 (PDT) In-reply-to: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::229 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:106803 Archived-At: Many thanks, this was exactly the type of info I was looking for. The name of the hook was valuable but advice on how to find the name was ever more appreciated. Thanks Joost! Joost Kremers writes: > 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 -- Sent with my mu4e