Subject: bug#25585: 25.1; shell-script mode not providing proper support for finding variables at point

From: Bob Hepple <[email-masked]>
Date: Tue, 31 Jan 2017 00:39:23 +0000

One of the GNU Emacs maintainers eli-zaretski suggested that I post my
problem as a bug report:
https://www.reddit.com/r/emacs/comments/5qz6en/ctags_and_bash/:

'Report a bug against Shell-script Mode. It sounds like it doesn't
define proper support for finding variables at point, so xref uses a
generic facility, which is only mostly correct in this case.'

My original problem is as follows: (confirm that it also fails with emacs
-Q):

So I've now got ctags(1) to understand bash variables as well as
functions.

Now I can jump to the defining location with M-. (ref-find-definitions)-
all fine and dandy.

The only fly in the ointment is that when a bash variable is
concatenated with literal text, M-. wants to look for the entire text.
eg if I M-. on the variable in:

$foobar/bar/foo

... then it wants to search for foobar/bar/foo instead of just foobar.

It wouldn't be so bad if I could repeat-complex-command and edit the
search string but M-. doesn't appear to push the command there.

Short of re-writing all the code as "$foobar"/bar/foo is there something
I can set to fix this?

In case it's interesting, this is how I build TAGS:
DIRS=(
    dir1
    dir2
)

ctags_opts='--regex-sh=/^[ \t]*(local|export|declare)?[
\t]*([A-Za-z0-9_-]+)=/\2/v,variable,variables/'

find ${DIRS[@]} -name .svn -prune -o -print | while read F; do
    file -i "$F" | egrep -q 'shellscript|text/plain' && ctags -e
--languages=sh -a "$ctags_opts" "$F"
done

In GNU Emacs 25.1.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.20.9)
 of 2016-10-13 built on buildvm-05.phx2.fedoraproject.org
Windowing system distributor 'Fedora Project', version 11.0.11804000
System Description: Fedora release 24 (Twenty Four)

Configured using:
 'configure --build=x86_64-redhat-linux-gnu
 --host=x86_64-redhat-linux-gnu --program-prefix=
 --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr
 --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc
 --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64
 --libexecdir=/usr/libexec --localstatedir=/var
 --sharedstatedir=/var/lib --mandir=/usr/share/man
 --infodir=/usr/share/info --with-dbus --with-gif --with-jpeg --with-png
 --with-rsvg --with-tiff --with-xft --with-xpm --with-x-toolkit=gtk3
 --with-gpm=no --with-xwidgets build_alias=x86_64-redhat-linux-gnu
 host_alias=x86_64-redhat-linux-gnu 'CFLAGS=-DMAIL_USE_LOCKF -O2 -g
 -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4
 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
 -m64 -mtune=generic' LDFLAGS=-Wl,-z,relro
 PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND DBUS GCONF GSETTINGS NOTIFY
ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 XWIDGETS

Important settings:
  value of $LC_ALL: en_AU.utf8
  value of $LANG: C
  locale-coding-system: utf-8-unix

Major mode: Help

Minor modes in effect:
  global-flycheck-mode: t
  helm-mode: t
  shell-dirtrack-mode: t
  async-bytecomp-package-mode: t
  diff-auto-refine-mode: t
  delete-selection-mode: t
  show-paren-mode: t
  recentf-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
Setting up indent for shell type bash
Indentation variables are now local.
Indentation setup for shell type bash
ARCH appears unused. Verify it or export it. [SC2034]
Setting up indent for shell type sh
Indentation variables are now local.
Indentation setup for shell type sh
TARGET_ARCH appears unused. Verify it or export it. [SC2034] [3 times]
Type C-x 4 C-o RET to restore the other window.
Type "q" to restore previous buffer.

Load-path shadows:
/usr/share/emacs/site-lisp/gnus-bonus/nnir hides
/usr/share/emacs/25.1/lisp/gnus/nnir
/usr/share/emacs/site-lisp/gnus-bonus/nnnil hides
/usr/share/emacs/25.1/lisp/gnus/nnnil
/usr/share/emacs/site-lisp/gnus-bonus/spam-stat hides
/usr/share/emacs/25.1/lisp/gnus/spam-stat
/usr/share/emacs/site-lisp/goodies/browse-kill-ring hides
~/.config/emacs/browse-kill-ring
/usr/share/emacs/25.1/lisp/vc/vc-svn hides ~/.config/emacs/vc-svn

Features:
(shadow sort mail-extr emacsbug sendmail warnings apropos jka-compr
helm-command helm-elisp helm-eval edebug eieio-opt dabbrev pulse
ibuf-ext ibuffer locate find-dired ido winner grep etags xref project
misearch multi-isearch vc-svn hideshow sh-script smie executable
flycheck json map find-func subr-x dash indent-tools yafolding hydra lv
indent-tools-indentation-of helm-mode helm-files rx image-dired tramp
tramp-compat tramp-loaddefs trampver ucs-normalize shell pcomplete
dired-x dired-aux ffap thingatpt helm-buffers helm-elscreen helm-tags
helm-bookmark helm-adaptive helm-info bookmark helm-locate helm-grep
helm-regexp helm-external helm-net browse-url xml url url-proxy
url-privacy url-expand url-methods url-history url-cookie url-domsuf
url-util url-parse auth-source url-vars mailcap helm-utils compile
comint ansi-color helm-help helm-types helm-config helm-easymenu
async-bytecomp async helm helm-source cl-seq eieio-compat eieio
eieio-core helm-multi-match helm-lib finder-inf info package seq
browse-kill-ring hide-comnt psvn byte-opt bytecomp byte-compile cl-extra
cconv advice derived edmacro kmacro cl-macs cl gv log-edit message idna
format-spec rfc822 mml mml-sec password-cache epg epg-config gnus-util
mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045
ietf-drums mm-util help-fns help-mode mail-prsvr mailabbrev mail-utils
gmm-utils mailheader ring pcvs-util add-log diff-mode pp elp ediff-merg
ediff-wind ediff-diff ediff-mult ediff-help ediff-init ediff-util dired
highline speedbar sb-image ezimage dframe ps-ccrypt delsel server paren
recentf tree-widget wid-edit xcscope easymenu vc cl-loaddefs pcase
cl-lib vc-dispatcher emacs-goodies-loaddefs easy-mmode time-date
mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel x-win term/common-win x-dnd tool-bar dnd fontset
image regexp-opt fringe tabulated-list newcomment elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cl-generic cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese charscript case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer cl-preloaded nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote dbusbind inotify dynamic-setting
system-font-setting font-render-setting xwidget-internal move-toolbar
gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 526407 64788)
 (symbols 48 40045 0)
 (miscs 40 3384 1255)
 (strings 32 86658 8760)
 (string-bytes 1 2653873)
 (vectors 16 61835)
 (vector-slots 8 1055224 27352)
 (floats 8 479 585)
 (intervals 56 17632 351)
 (buffers 976 59)
 (heap 1024 153739 47906))