From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: shell-script mode index Date: Fri, 27 Jun 2014 08:00:23 -0700 (PDT) Message-ID: References: <87y4wkyc50.fsf@motoko.kusanagi> <87pphu76zi.fsf@skimble.plus.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1403881271 31188 80.91.229.3 (27 Jun 2014 15:01:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 27 Jun 2014 15:01:11 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, Ken Goldman To: Sharon Kimble Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 27 17:01:04 2014 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 1X0Xe9-0002ln-Bj for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jun 2014 17:01:01 +0200 Original-Received: from localhost ([::1]:50811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0Xe8-0002Ns-EQ for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jun 2014 11:01:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39249) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0Xdp-0002NB-6p for help-gnu-emacs@gnu.org; Fri, 27 Jun 2014 11:00:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X0Xdh-0006Em-3c for help-gnu-emacs@gnu.org; Fri, 27 Jun 2014 11:00:41 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:31519) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0Xdg-0006Eg-Sr for help-gnu-emacs@gnu.org; Fri, 27 Jun 2014 11:00:33 -0400 Original-Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s5RF0TZm006459 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 Jun 2014 15:00:30 GMT Original-Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s5RF0OSp018558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 27 Jun 2014 15:00:24 GMT Original-Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s5RF0ONs018551; Fri, 27 Jun 2014 15:00:24 GMT In-Reply-To: <87pphu76zi.fsf@skimble.plus.com> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8 (707110) [OL 12.0.6691.5000 (x86)] X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 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:98431 Archived-At: > >> When I tried to do it outside a hook, I got an error for > >> fundamental-mode. > > > > Wrap the calls to `imenu*' in `ignore-errors'. > > I've been following this as I need an Imenu for latex-mode, but I don't > understand this. Could you give a code example please? If you tell some mode to invoke `imenu' or `imenu-add-to-menubar' or `imenu-add-menubar-index', and if that mode does not support Imenu (e.g., it has no usable value for `imenu-generic-expression'), then the function raises an error when it is invoked. You can wrap any code in `ignore-errors' to have it just return nil if it raises an error when evaluated: (something-that-raises an error) ; raises an error (ignore-errors (something-that-raises an error)) ; returns nil If you have an older version of Emacs, which does not have macro `ignore-errors', then use `condition-case' (this works in all Emacs versions): (condition-case nil (something-that-raises an error) (error nil)) ; Do nothing and return nil. I do this, for instance, in `imenu+.el' (http://www.emacswiki.org/ImenuMode#ImenuPlus): (defun imenup-add-defs-to-menubar () "Add \"Defs\" imenu entry to menu bar for current local keymap. See `imenu' for more information." (interactive) (imenu-add-to-menubar "Defs")) (add-hook 'lisp-mode-hook (lambda () (setq imenu-generic-expression lisp-imenu-generic-expression) (condition-case nil (imenup-add-defs-to-menubar) (error nil)))) Here, there should be no need to wrap with `condition-case', since `imenu-generic-expression' is defined (so Imenu is supported in Lisp mode). But I do it anyway. The point is that if you invoke some code that might raise an error, you can inhibit raising an error by wrapping that code in `ignore-errors'. That doesn't make the code magically "work"; it just prevents it from raising an error.