* shell-script mode index
@ 2014-06-24 14:56 Ken Goldman
2014-06-25 20:20 ` W. Greenhouse
2014-06-26 1:14 ` William Xu
0 siblings, 2 replies; 9+ messages in thread
From: Ken Goldman @ 2014-06-24 14:56 UTC (permalink / raw)
To: help-gnu-emacs
Is there an extension to shell-script mode that shows a function index,
like the index menu for C or Java?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: shell-script mode index
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 1:14 ` William Xu
1 sibling, 1 reply; 9+ messages in thread
From: W. Greenhouse @ 2014-06-25 20:20 UTC (permalink / raw)
To: help-gnu-emacs-mXXj517/zsQ
Ken Goldman <kgoldman-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org> writes:
> Is there an extension to shell-script mode that shows a function
> index, like the index menu for C or Java?
M-x imenu RET and M-x speedbar RET will both give you a menu of function
definitions in shell-script-mode: the former via minibuffer, the latter
via a separate Emacs frame.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: shell-script mode index
2014-06-25 20:20 ` W. Greenhouse
@ 2014-06-26 16:45 ` Ken Goldman
2014-06-26 17:05 ` Drew Adams
0 siblings, 1 reply; 9+ messages in thread
From: Ken Goldman @ 2014-06-26 16:45 UTC (permalink / raw)
To: help-gnu-emacs
On 6/25/2014 4:20 PM, W. Greenhouse wrote:
>
> Ken Goldman <kgoldman@us.ibm.com> writes:
>
>> Is there an extension to shell-script mode that shows a function
>> index, like the index menu for C or Java?
>
> M-x imenu RET and M-x speedbar RET will both give you a menu of function
> definitions in shell-script-mode: the former via minibuffer, the latter
> via a separate Emacs frame.
speedbar show the file without any expansion into functions.
imenu gives me a prompt "Index item" but does not create an index menu.
I'm glad to know it should work, but I wonder if I have to load some
package?
(This is 23.1.1 on RHEL Linux, if that matters).
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: shell-script mode index
2014-06-26 16:45 ` Ken Goldman
@ 2014-06-26 17:05 ` Drew Adams
2014-06-26 20:20 ` Ken Goldman
0 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2014-06-26 17:05 UTC (permalink / raw)
To: Ken Goldman, help-gnu-emacs
> imenu gives me a prompt "Index item" but does not create an index menu.
>
> I'm glad to know it should work, but I wonder if I have to load some
> package?
No. You just need to read the doc.
`C-h i m elisp i imenu'
`M-x imenu-add-menu-bar-index', then `M-x imenu'.
Or `M-x imenu-add-to-menu-bar FOO', then use menu-bar menu `FOO'.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: shell-script mode index
2014-06-26 17:05 ` Drew Adams
@ 2014-06-26 20:20 ` Ken Goldman
2014-06-26 20:38 ` Drew Adams
0 siblings, 1 reply; 9+ messages in thread
From: Ken Goldman @ 2014-06-26 20:20 UTC (permalink / raw)
To: help-gnu-emacs
On 6/26/2014 1:05 PM, Drew Adams wrote:
> `M-x imenu-add-menu-bar-index', then `M-x imenu'.
Thanks. That worked. I put this in .emacs:
(add-hook 'sh-mode-hook
(function (lambda ()
(setq imenu-sort-function 'imenu--sort-by-name)
(setq imenu-max-items 40)
(imenu buffer-file-name)
(imenu-add-to-menubar "index")
)))
I now have this (and lots of other code repeated) for a few hooks. Is
there a way to put this in some elisp code that says, 'Do this for any
mode that supports it?"
When I tried to do it outside a hook, I got an error for fundamental-mode.
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: shell-script mode index
2014-06-26 20:20 ` Ken Goldman
@ 2014-06-26 20:38 ` Drew Adams
2014-06-27 14:38 ` Sharon Kimble
0 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2014-06-26 20:38 UTC (permalink / raw)
To: Ken Goldman, help-gnu-emacs
> When I tried to do it outside a hook, I got an error for fundamental-mode.
Wrap the calls to `imenu*' in `ignore-errors'.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: shell-script mode index
2014-06-26 20:38 ` Drew Adams
@ 2014-06-27 14:38 ` Sharon Kimble
2014-06-27 15:00 ` Drew Adams
0 siblings, 1 reply; 9+ messages in thread
From: Sharon Kimble @ 2014-06-27 14:38 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs, Ken Goldman
[-- Attachment #1: Type: text/plain, Size: 518 bytes --]
Drew Adams <drew.adams@oracle.com> writes:
>> 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?
Thanks
Sharon.
--
A taste of linux = http://www.sharons.org.uk
my git repo = https://bitbucket.org/boudiccas/dots
TGmeds = http://www.tgmeds.org.uk
Debian testing, fluxbox 1.3.5, emacs 24.3.91.1
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: shell-script mode index
2014-06-27 14:38 ` Sharon Kimble
@ 2014-06-27 15:00 ` Drew Adams
0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2014-06-27 15:00 UTC (permalink / raw)
To: Sharon Kimble; +Cc: help-gnu-emacs, Ken Goldman
> >> 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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: shell-script mode index
2014-06-24 14:56 shell-script mode index Ken Goldman
2014-06-25 20:20 ` W. Greenhouse
@ 2014-06-26 1:14 ` William Xu
1 sibling, 0 replies; 9+ messages in thread
From: William Xu @ 2014-06-26 1:14 UTC (permalink / raw)
To: help-gnu-emacs
Ken Goldman <kgoldman@us.ibm.com> writes:
> Is there an extension to shell-script mode that shows a function index, like the
> index menu for C or Java?
M-x imenu
--
William
http://xwl.appspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-06-27 15:00 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-06-26 1:14 ` William Xu
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).