From: Drew Adams <drew.adams@oracle.com>
To: Sharon Kimble <boudiccas@skimble.plus.com>
Cc: help-gnu-emacs@gnu.org, Ken Goldman <kgoldman@us.ibm.com>
Subject: RE: shell-script mode index
Date: Fri, 27 Jun 2014 08:00:23 -0700 (PDT) [thread overview]
Message-ID: <e2b65c13-5190-4388-8c96-f2083feffcf3@default> (raw)
In-Reply-To: <87pphu76zi.fsf@skimble.plus.com>
> >> 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.
next prev parent reply other threads:[~2014-06-27 15:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-24 14:56 shell-script mode index Ken Goldman
2014-06-25 20:20 ` W. Greenhouse
2014-06-26 16:45 ` Ken Goldman
2014-06-26 17:05 ` Drew Adams
2014-06-26 20:20 ` Ken Goldman
2014-06-26 20:38 ` Drew Adams
2014-06-27 14:38 ` Sharon Kimble
2014-06-27 15:00 ` Drew Adams [this message]
2014-06-26 1:14 ` William Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e2b65c13-5190-4388-8c96-f2083feffcf3@default \
--to=drew.adams@oracle.com \
--cc=boudiccas@skimble.plus.com \
--cc=help-gnu-emacs@gnu.org \
--cc=kgoldman@us.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).