annotate lisp/progmodes/sh-script.el @ 36231:9fa7c8e6a6d5

(Fwindow_end): Handle case that WINDOW's buffer is not equal to the current buffer.
author Gerd Moellmann <gerd@gnu.org>
date Tue, 20 Feb 2001 16:00:18 +0000
parents f4733aab37df
children d5345decc9a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; sh-script.el --- shell-script editing commands for Emacs
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14148
diff changeset
2
25554
e52ba2d9f6d7 (sh-tmp-file): Use $TMPDIR, if defined, for sh.
Eli Zaretskii <eliz@gnu.org>
parents: 24906
diff changeset
3 ;; Copyright (C) 1993, 94, 95, 96, 97, 1999 by Free Software Foundation, Inc.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
23869
8d2bb5d1416a Update comment.
Karl Heuer <kwzh@gnu.org>
parents: 23589
diff changeset
5 ;; Author: Daniel Pfeiffer <occitan@esperanto.org>
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
6 ;; Version: 2.0f
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Maintainer: FSF
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
8 ;; Keywords: languages, unix
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14148
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14148
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14148
diff changeset
25 ;; Boston, MA 02111-1307, USA.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
29 ;; Major mode for editing shell scripts. Bourne, C and rc shells as well
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
30 ;; as various derivatives are supported and easily derived from. Structured
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
31 ;; statements can be inserted with one command or abbrev. Completion is
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
32 ;; available for filenames, variables known from the script, the shell and
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
33 ;; the environment as well as commands.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
34
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
35 ;;; Known Bugs:
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
37 ;; - In Bourne the keyword `in' is not anchored to case, for, select ...
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
38 ;; - Variables in `"' strings aren't fontified because there's no way of
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
39 ;; syntactically distinguishing those from `'' strings.
8257
bbf6304598d9 "Comment out" autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents: 8121
diff changeset
40
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
41 ;; Indentation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
42 ;; ===========
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
43 ;; Indentation for rc and es modes is very limited, but for Bourne shells
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
44 ;; and its derivatives it is quite customizable.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
45 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
46 ;; The following description applies to sh and derived shells (bash,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
47 ;; zsh, ...).
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
48 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
49 ;; There are various customization variables which allow tailoring to
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
50 ;; a wide variety of styles. Most of these variables are named
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
51 ;; sh-indent-for-XXX and sh-indent-after-XXX. For example.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
52 ;; sh-indent-after-if controls the indenting of a line following
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
53 ;; an if statement, and sh-indent-for-fi controls the indentation
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
54 ;; of the line containing the fi.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
55 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
56 ;; You can set each to a numeric value, but it is often more convenient
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
57 ;; to a symbol such as `+' which uses the value of variable `sh-basic-offset'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
58 ;; By changing this one variable you can increase or decrease how much
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
59 ;; indentation there is. Valid symbols:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
60 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
61 ;; + Indent right by sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
62 ;; - Indent left by sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
63 ;; ++ Indent right twice sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
64 ;; -- Indent left twice sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
65 ;; * Indent right half sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
66 ;; / Indent left half sh-basic-offset.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
67 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
68 ;; There are 4 commands to help set the indentation variables:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
69 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
70 ;; `sh-show-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
71 ;; This shows what variable controls the indentation of the current
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
72 ;; line and its value.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
73 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
74 ;; `sh-set-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
75 ;; This allows you to set the value of the variable controlling the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
76 ;; current line's indentation. You can enter a number or one of a
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
77 ;; number of special symbols to denote the value of sh-basic-offset,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
78 ;; or its negative, or half it, or twice it, etc. If you've used
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
79 ;; cc-mode this should be familiar. If you forget which symbols are
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
80 ;; valid simply press C-h at the prompt.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
81 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
82 ;; `sh-learn-line-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
83 ;; Simply make the line look the way you want it, then invoke this
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
84 ;; command. It will set the variable to the value that makes the line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
85 ;; indent like that. If called with a prefix argument then it will set
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
86 ;; the value to one of the symbols if applicable.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
87 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
88 ;; `sh-learn-buffer-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
89 ;; This is the deluxe function! It "learns" the whole buffer (use
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
90 ;; narrowing if you want it to process only part). It outputs to a
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
91 ;; buffer *indent* any conflicts it finds, and all the variables it has
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
92 ;; learned. This buffer is a sort of Occur mode buffer, allowing you to
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
93 ;; easily find where something was set. It is popped to automatically
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
94 ;; if there are any conflicts found or if `sh-popup-occur-buffer' is
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
95 ;; non-nil.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
96 ;; `sh-indent-comment' will be set if all comments follow the same
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
97 ;; pattern; if they don't it will be set to nil.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
98 ;; Whether `sh-basic-offset' is set is determined by variable
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
99 ;; `sh-learn-basic-offset'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
100 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
101 ;; Unfortunately, `sh-learn-buffer-indent' can take a long time to run
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
102 ;; (e.g. if there are large case statements). Perhaps it does not make
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
103 ;; sense to run it on large buffers: if lots of lines have different
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
104 ;; indentation styles it will produce a lot of diagnostics in the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
105 ;; *indent* buffer; if there is a consistent style then running
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
106 ;; `sh-learn-buffer-indent' on a small region of the buffer should
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
107 ;; suffice.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
108 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
109 ;; Saving indentation values
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
110 ;; -------------------------
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
111 ;; After you've learned the values in a buffer, how to you remember
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
112 ;; them? Originally I had hoped that `sh-learn-buffer-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
113 ;; would make this unnecessary; simply learn the values when you visit
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
114 ;; the buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
115 ;; You can do this automatically like this:
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
116 ;; (add-hook 'sh-set-shell-hook 'sh-learn-buffer-indent)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
117 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
118 ;; However... `sh-learn-buffer-indent' is extremely slow,
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
119 ;; especially on large-ish buffer. Also, if there are conflicts the
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
120 ;; "last one wins" which may not produce the desired setting.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
121 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
122 ;; So...There is a minimal way of being able to save indentation values and
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
123 ;; to reload them in another buffer or at another point in time.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
124 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
125 ;; Use `sh-name-style' to give a name to the indentation settings of
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
126 ;; the current buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
127 ;; Use `sh-load-style' to load indentation settings for the current
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
128 ;; buffer from a specific style.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
129 ;; Use `sh-save-styles-to-buffer' to write all the styles to a buffer
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
130 ;; in lisp code. You can then store it in a file and later use
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
131 ;; `load-file' to load it.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
132 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
133 ;; Indentation variables - buffer local or global?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
134 ;; ----------------------------------------------
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
135 ;; I think that often having them buffer-local makes sense,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
136 ;; especially if one is using `sh-learn-buffer-indent'. However, if
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
137 ;; a user sets values using customization, these changes won't appear
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
138 ;; to work if the variables are already local!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
139 ;;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
140 ;; To get round this, there is a variable `sh-make-vars-local' and 2
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
141 ;; functions: `sh-make-vars-local' and `sh-reset-indent-vars-to-global-values'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
142 ;;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
143 ;; If `sh-make-vars-local' is non-nil, then these variables become
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
144 ;; buffer local when the mode is established.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
145 ;; If this is nil, then the variables are global. At any time you
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
146 ;; can make them local with the command `sh-make-vars-local'.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
147 ;; Conversely, to update with the global values you can use the
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
148 ;; command `sh-reset-indent-vars-to-global-values'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
149 ;;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
150 ;; This may be awkward, but the intent is to cover all cases.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
151 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
152 ;; Awkward things, pitfalls
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
153 ;; ------------------------
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
154 ;; Indentation for a sh script is complicated for a number of reasons:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
155 ;;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
156 ;; 1. You can't format by simply looking at symbols, you need to look
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
157 ;; at keywords. [This is not the case for rc and es shells.]
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
158 ;; 2. The character ")" is used both as a matched pair "(" ... ")" and
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
159 ;; as a stand-alone symbol (in a case alternative). This makes
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
160 ;; things quite tricky!
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
161 ;; 3. Here-documents in a script should be treated "as is", and when
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
162 ;; they terminate we want to revert to the indentation of the line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
163 ;; containing the "<<" symbol.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
164 ;; 4. A line may be continued using the "\".
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
165 ;; 5. The character "#" (outside a string) normally starts a comment,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
166 ;; but it doesn't in the sequence "$#"!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
167 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
168 ;; To try and address points 2 3 and 5 I used a feature that cperl mode
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
169 ;; uses, that of a text's syntax property. This, however, has 2
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
170 ;; disadvantages:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
171 ;; 1. We need to scan the buffer to find which ")" symbols belong to a
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
172 ;; case alternative, to find any here documents, and handle "$#".
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
173 ;; 2. Setting the text property makes the buffer modified. If the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
174 ;; buffer is read-only buffer we have to cheat and bypass the read-only
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
175 ;; status. This is for cases where the buffer started read-only buffer
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
176 ;; but the user issued `toggle-read-only'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
177 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
178 ;; Bugs
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
179 ;; ----
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
180 ;; - Indenting many lines is slow. It currently does each line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
181 ;; independently, rather than saving state information.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
182 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
183 ;; - `sh-learn-buffer-indent' is extremely slow.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
184 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
185 ;; Richard Sharman <rsharman@pobox.com> June 1999.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
186
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 ;;; Code:
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 ;; page 1: variables and settings
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
190 ;; page 2: indentation stuff
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
191 ;; page 3: mode-command and utility functions
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
192 ;; page 4: statement syntax-commands for various shells
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
193 ;; page 5: various other commands
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194
32503
3470d692f2e0 Require skeleton and comint when
Dave Love <fx@gnu.org>
parents: 32480
diff changeset
195 (eval-when-compile
3470d692f2e0 Require skeleton and comint when
Dave Love <fx@gnu.org>
parents: 32480
diff changeset
196 (require 'skeleton)
3470d692f2e0 Require skeleton and comint when
Dave Love <fx@gnu.org>
parents: 32480
diff changeset
197 (require 'comint))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
198 (require 'executable)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
200
17068
d1391b21626f (sh-mode-hook, sh-set-shell-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents: 16839
diff changeset
201
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
202 (defgroup sh nil
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
203 "Shell programming utilities"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
204 :group 'unix
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
205 :group 'languages)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
206
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
207 (defgroup sh-script nil
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
208 "Shell script mode"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
209 :group 'sh
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
210 :prefix "sh-")
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
211
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
212
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
213 (defcustom sh-ancestor-alist
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
214 '((ash . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
215 (bash . jsh)
29109
0e45e6e90467 (sh-ancestor-alist): Add `bash2'.
Gerd Moellmann <gerd@gnu.org>
parents: 28923
diff changeset
216 (bash2 . jsh)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
217 (dtksh . ksh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
218 (es . rc)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
219 (itcsh . tcsh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
220 (jcsh . csh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
221 (jsh . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
222 (ksh . ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
223 (ksh88 . jsh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
224 (oash . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
225 (pdksh . ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
226 (posix . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
227 (tcsh . csh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
228 (wksh . ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
229 (wsh . sh)
23501
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
230 (zsh . ksh88)
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
231 (rpm . sh))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
232 "*Alist showing the direct ancestor of various shells.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
233 This is the basis for `sh-feature'. See also `sh-alias-alist'.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
234 By default we have the following three hierarchies:
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
235
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
236 csh C Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
237 jcsh C Shell with Job Control
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
238 tcsh Toronto C Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
239 itcsh ? Toronto C Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
240 rc Plan 9 Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
241 es Extensible Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
242 sh Bourne Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
243 ash ? Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
244 jsh Bourne Shell with Job Control
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
245 bash GNU Bourne Again Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
246 ksh88 Korn Shell '88
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
247 ksh Korn Shell '93
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
248 dtksh CDE Desktop Korn Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
249 pdksh Public Domain Korn Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
250 wksh Window Korn Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
251 zsh Z Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
252 oash SCO OA (curses) Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
253 posix IEEE 1003.2 Shell Standard
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
254 wsh ? Shell"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
255 :type '(repeat (cons symbol symbol))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
256 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
257
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
258
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
259 (defcustom sh-alias-alist
15950
c4ae4ea7fa7a (sh-alias-alist): Use gnu/linux, not lignux.
Richard M. Stallman <rms@gnu.org>
parents: 15677
diff changeset
260 (nconc (if (eq system-type 'gnu/linux)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
261 '((csh . tcsh)
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
262 (ksh . pdksh)))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
263 ;; for the time being
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
264 '((ksh . ksh88)
29109
0e45e6e90467 (sh-ancestor-alist): Add `bash2'.
Gerd Moellmann <gerd@gnu.org>
parents: 28923
diff changeset
265 (bash2 . bash)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
266 (sh5 . sh)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
267 "*Alist for transforming shell names to what they really are.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
268 Use this where the name of the executable doesn't correspond to the type of
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
269 shell it really is."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
270 :type '(repeat (cons symbol symbol))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
271 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
272
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
273
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
274 (defcustom sh-shell-file
16810
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
275 (or
16839
daaa2c5bb40a (sh-shell-file): Downcase and remove extension on shells in NT.
Richard M. Stallman <rms@gnu.org>
parents: 16810
diff changeset
276 ;; On MSDOS and Windows, collapse $SHELL to lower-case and remove
daaa2c5bb40a (sh-shell-file): Downcase and remove extension on shells in NT.
Richard M. Stallman <rms@gnu.org>
parents: 16810
diff changeset
277 ;; the executable extension, so comparisons with the list of
16810
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
278 ;; known shells work.
16839
daaa2c5bb40a (sh-shell-file): Downcase and remove extension on shells in NT.
Richard M. Stallman <rms@gnu.org>
parents: 16810
diff changeset
279 (and (memq system-type '(ms-dos windows-nt))
21925
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
280 (let* ((shell (getenv "SHELL"))
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
281 (shell-base
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
282 (and shell (file-name-nondirectory shell))))
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
283 ;; shell-script mode doesn't support DOS/Windows shells,
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
284 ;; so use the default instead.
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
285 (if (or (null shell)
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
286 (member (downcase shell-base)
21980
e73c0672d7b3 (sh-shell-file): Add cmdproxy to MS shells.
Richard M. Stallman <rms@gnu.org>
parents: 21925
diff changeset
287 '("command.com" "cmd.exe" "4dos.com" "ndos.com"
e73c0672d7b3 (sh-shell-file): Add cmdproxy to MS shells.
Richard M. Stallman <rms@gnu.org>
parents: 21925
diff changeset
288 "cmdproxy.exe")))
21925
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
289 "/bin/sh"
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
290 (file-name-sans-extension (downcase shell)))))
16810
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
291 (getenv "SHELL")
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
292 "/bin/sh")
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
293 "*The executable file name for the shell being programmed."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
294 :type 'string
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
295 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
296
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
297
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
298 (defcustom sh-shell-arg
14886
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
299 ;; bash does not need any options when run in a shell script,
14876
b39dde411ac8 (sh-shell-arg): Don't add any options for bash, ksh.
Richard M. Stallman <rms@gnu.org>
parents: 14849
diff changeset
300 '((bash)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
301 (csh . "-f")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
302 (pdksh)
14886
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
303 ;; Bill_Mann@praxisint.com says -p with ksh can do harm.
14876
b39dde411ac8 (sh-shell-arg): Don't add any options for bash, ksh.
Richard M. Stallman <rms@gnu.org>
parents: 14849
diff changeset
304 (ksh88)
14886
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
305 ;; -p means don't initialize functions from the environment.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
306 (rc . "-p")
14886
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
307 ;; Someone proposed -motif, but we don't want to encourage
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
308 ;; use of a non-free widget set.
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
309 (wksh)
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
310 ;; -f means don't run .zshrc.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
311 (zsh . "-f"))
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
312 "*Single argument string for the magic number. See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
313 :type '(repeat (cons (symbol :tag "Shell")
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
314 (choice (const :tag "No Arguments" nil)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
315 (string :tag "Arguments")
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
316 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
317 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
318 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
319 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
320
20395
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
321 (defcustom sh-imenu-generic-expression
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
322 `((sh
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
323 . ((nil "^\\s-*\\(function\\s-+\\)?\\([A-Za-z_][A-Za-z_0-9]+\\)\\s-*()" 2))))
35180
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
324 "*Alist of regular expressions for recognizing shell function definitions.
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
325 See `sh-feature' and `imenu-generic-expression'."
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
326 :type '(alist :key-type (symbol :tag "Shell")
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
327 :value-type (alist :key-type (choice :tag "Title"
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
328 string
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
329 (const :tag "None" nil))
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
330 :value-type
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
331 (repeat :tag "Regexp, index..." sexp)))
21669
9861518505cb *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20900
diff changeset
332 :group 'sh-script
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
333 :version "20.4")
20395
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
334
14195
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
335 (defvar sh-shell-variables nil
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
336 "Alist of shell variable names that should be included in completion.
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
337 These are used for completion in addition to all the variables named
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
338 in `process-environment'. Each element looks like (VAR . VAR), where
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
339 the car and cdr are the same symbol.")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
340
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
341 (defvar sh-shell-variables-initialized nil
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
342 "Non-nil if `sh-shell-variables' is initialized.")
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
343
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
344 (defun sh-canonicalize-shell (shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
345 "Convert a shell name SHELL to the one we should handle it as."
23589
660727693bf6 (sh-canonicalize-shell): Fix regexp.
Andreas Schwab <schwab@suse.de>
parents: 23511
diff changeset
346 (if (string-match "\\.exe\\'" shell)
23341
d29b6b51866f (sh-set-shell): Remove .exe suffix from shell name.
Richard M. Stallman <rms@gnu.org>
parents: 22783
diff changeset
347 (setq shell (substring shell 0 (match-beginning 0))))
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
348 (or (symbolp shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
349 (setq shell (intern shell)))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
350 (or (cdr (assq shell sh-alias-alist))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
351 shell))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
352
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
353 (defvar sh-shell (sh-canonicalize-shell (file-name-nondirectory sh-shell-file))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
354 "The shell being programmed. This is set by \\[sh-set-shell].")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
355
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
356 ;;; I turned off this feature because it doesn't permit typing commands
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
357 ;;; in the usual way without help.
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
358 ;;;(defvar sh-abbrevs
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
359 ;;; '((csh eval sh-abbrevs shell
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
360 ;;; "switch" 'sh-case
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
361 ;;; "getopts" 'sh-while-getopts)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
362
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
363 ;;; (es eval sh-abbrevs shell
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
364 ;;; "function" 'sh-function)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
365
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
366 ;;; (ksh88 eval sh-abbrevs sh
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
367 ;;; "select" 'sh-select)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
368
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
369 ;;; (rc eval sh-abbrevs shell
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
370 ;;; "case" 'sh-case
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
371 ;;; "function" 'sh-function)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
372
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
373 ;;; (sh eval sh-abbrevs shell
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
374 ;;; "case" 'sh-case
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
375 ;;; "function" 'sh-function
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
376 ;;; "until" 'sh-until
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
377 ;;; "getopts" 'sh-while-getopts)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
378
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
379 ;;; ;; The next entry is only used for defining the others
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
380 ;;; (shell "for" sh-for
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
381 ;;; "loop" sh-indexed-loop
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
382 ;;; "if" sh-if
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
383 ;;; "tmpfile" sh-tmp-file
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
384 ;;; "while" sh-while)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
385
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
386 ;;; (zsh eval sh-abbrevs ksh88
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
387 ;;; "repeat" 'sh-repeat))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
388 ;;; "Abbrev-table used in Shell-Script mode. See `sh-feature'.
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
389 ;;;Due to the internal workings of abbrev tables, the shell name symbol is
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
390 ;;;actually defined as the table for the like of \\[edit-abbrevs].")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
391
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
394 (easy-mmode-defsyntax sh-mode-syntax-table
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
395 '((?\# . "<")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
396 (?\^l . ">#")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
397 (?\n . ">#")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
398 (?\" . "\"\"")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
399 (?\' . "\"'")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
400 (?\` . "\"`")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
401 (?! . "_")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
402 (?% . "_")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
403 (?: . "_")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
404 (?. . "_")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
405 (?^ . "_")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
406 (?~ . "_")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
407 (?< . ".")
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
408 (?> . "."))
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
409 "Syntax-table used in Shell-Script mode.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (defvar sh-mode-map
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
413 (let ((map (make-sparse-keymap))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
414 (menu-map (make-sparse-keymap "Insert")))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (define-key map "\C-c(" 'sh-function)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (define-key map "\C-c\C-w" 'sh-while)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (define-key map "\C-c\C-u" 'sh-until)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
418 (define-key map "\C-c\C-t" 'sh-tmp-file)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (define-key map "\C-c\C-s" 'sh-select)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
420 (define-key map "\C-c\C-r" 'sh-repeat)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
421 (define-key map "\C-c\C-o" 'sh-while-getopts)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (define-key map "\C-c\C-l" 'sh-indexed-loop)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (define-key map "\C-c\C-i" 'sh-if)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (define-key map "\C-c\C-f" 'sh-for)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (define-key map "\C-c\C-c" 'sh-case)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
426 (define-key map "\C-c?" 'sh-show-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
427 (define-key map "\C-c=" 'sh-set-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
428 (define-key map "\C-c<" 'sh-learn-line-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
429 (define-key map "\C-c>" 'sh-learn-buffer-indent)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
430
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (define-key map "=" 'sh-assignment)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (define-key map "\C-c+" 'sh-add)
13469
5bda9e4d85eb (sh-mode-map): Put sh-execute-region on C-M-x.
Richard M. Stallman <rms@gnu.org>
parents: 13391
diff changeset
433 (define-key map "\C-\M-x" 'sh-execute-region)
5bda9e4d85eb (sh-mode-map): Put sh-execute-region on C-M-x.
Richard M. Stallman <rms@gnu.org>
parents: 13391
diff changeset
434 (define-key map "\C-c\C-x" 'executable-interpret)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
435 (define-key map "<" 'sh-maybe-here-document)
12864
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
436 (define-key map "(" 'skeleton-pair-insert-maybe)
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
437 (define-key map "{" 'skeleton-pair-insert-maybe)
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
438 (define-key map "[" 'skeleton-pair-insert-maybe)
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
439 (define-key map "'" 'skeleton-pair-insert-maybe)
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
440 (define-key map "`" 'skeleton-pair-insert-maybe)
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
441 (define-key map "\"" 'skeleton-pair-insert-maybe)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
442
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
443 (substitute-key-definition 'complete-tag 'comint-dynamic-complete
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 map (current-global-map))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (substitute-key-definition 'newline-and-indent 'sh-newline-and-indent
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 map (current-global-map))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (substitute-key-definition 'delete-backward-char
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 'backward-delete-char-untabify
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 map (current-global-map))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (define-key map "\C-c:" 'sh-set-shell)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (substitute-key-definition 'beginning-of-defun
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 'sh-beginning-of-compound-command
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 map (current-global-map))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (substitute-key-definition 'backward-sentence 'sh-beginning-of-command
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 map (current-global-map))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (substitute-key-definition 'forward-sentence 'sh-end-of-command
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 map (current-global-map))
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
458 (define-key map [menu-bar insert] (cons "Insert" menu-map))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
459 (define-key menu-map [sh-while] '("While Loop" . sh-while))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
460 (define-key menu-map [sh-until] '("Until Loop" . sh-until))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
461 (define-key menu-map [sh-tmp-file] '("Temporary File" . sh-tmp-file))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
462 (define-key menu-map [sh-select] '("Select Statement" . sh-select))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
463 (define-key menu-map [sh-repeat] '("Repeat Loop" . sh-repeat))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
464 (define-key menu-map [sh-getopts] '("Options Loop" . sh-while-getopts))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
465 (define-key menu-map [sh-indexed-loop] '("Indexed Loop" . sh-indexed-loop))
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
466 (define-key menu-map [sh-if] '("If Statement" . sh-if))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
467 (define-key menu-map [sh-for] '("For Loop" . sh-for))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
468 (define-key menu-map [sh-case] '("Case Statement" . sh-case))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 map)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 "Keymap used in Shell-Script mode.")
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
474 (defcustom sh-dynamic-complete-functions
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
475 '(shell-dynamic-complete-environment-variable
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
476 shell-dynamic-complete-command
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
477 comint-dynamic-complete-filename)
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
478 "*Functions for doing TAB dynamic completion."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
479 :type '(repeat function)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
480 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
483 (defcustom sh-require-final-newline
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
484 '((csh . t)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
485 (pdksh . t)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
486 (rc eval . require-final-newline)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
487 (sh eval . require-final-newline))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
488 "*Value of `require-final-newline' in Shell-Script mode buffers.
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
489 See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
490 :type '(repeat (cons (symbol :tag "Shell")
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
491 (choice (const :tag "require" t)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
492 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
493 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
494 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
495 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
498 (defcustom sh-assignment-regexp
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
499 '((csh . "\\<\\([a-zA-Z0-9_]+\\)\\(\\[.+\\]\\)?[ \t]*[-+*/%^]?=")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
500 ;; actually spaces are only supported in let/(( ... ))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
501 (ksh88 . "\\<\\([a-zA-Z0-9_]+\\)\\(\\[.+\\]\\)?[ \t]*\\([-+*/%&|~^]\\|<<\\|>>\\)?=")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
502 (rc . "\\<\\([a-zA-Z0-9_*]+\\)[ \t]*=")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
503 (sh . "\\<\\([a-zA-Z0-9_]+\\)="))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
504 "*Regexp for the variable name and what may follow in an assignment.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
505 First grouping matches the variable name. This is upto and including the `='
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
506 sign. See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
507 :type '(repeat (cons (symbol :tag "Shell")
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
508 (choice regexp
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
509 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
510 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
511 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
512 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
515 (defcustom sh-indentation 4
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
516 "The width for further indentation in Shell-Script mode."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
517 :type 'integer
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
518 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
521 (defcustom sh-remember-variable-min 3
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
522 "*Don't remember variables less than this length for completing reads."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
523 :type 'integer
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
524 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
527 (defvar sh-header-marker nil
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
528 "When non-nil is the end of header for prepending by \\[sh-execute-region].
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
529 That command is also used for setting this variable.")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
530
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
531
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
532 (defcustom sh-beginning-of-command
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
533 "\\([;({`|&]\\|\\`\\|[^\\]\n\\)[ \t]*\\([/~a-zA-Z0-9:]\\)"
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 "*Regexp to determine the beginning of a shell command.
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
535 The actual command starts at the beginning of the second \\(grouping\\)."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
536 :type 'regexp
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
537 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
539
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
540 (defcustom sh-end-of-command
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
541 "\\([/~a-zA-Z0-9:]\\)[ \t]*\\([;#)}`|&]\\|$\\)"
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 "*Regexp to determine the end of a shell command.
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
543 The actual command ends at the end of the first \\(grouping\\)."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
544 :type 'regexp
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
545 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
549 (defvar sh-here-document-word "EOF"
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 "Word to delimit here documents.")
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
552 (defvar sh-test
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
553 '((sh "[ ]" . 3)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
554 (ksh88 "[[ ]]" . 4))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
555 "Initial input in Bourne if, while and until skeletons. See `sh-feature'.")
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
556
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
558 ;; customized this out of sheer bravado. not for the faint of heart.
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
559 ;; but it *did* have an asterisk in the docstring!
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
560 (defcustom sh-builtins
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
561 '((bash eval sh-append posix
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
562 "alias" "bg" "bind" "builtin" "declare" "dirs" "enable" "fc" "fg"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
563 "help" "history" "jobs" "kill" "let" "local" "popd" "pushd" "source"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
564 "suspend" "typeset" "unalias")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
565
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
566 ;; The next entry is only used for defining the others
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
567 (bourne eval sh-append shell
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
568 "eval" "export" "getopts" "newgrp" "pwd" "read" "readonly"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
569 "times" "ulimit")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
570
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
571 (csh eval sh-append shell
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
572 "alias" "chdir" "glob" "history" "limit" "nice" "nohup" "rehash"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
573 "setenv" "source" "time" "unalias" "unhash")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
574
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
575 (dtksh eval identity wksh)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
576
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
577 (es "access" "apids" "cd" "echo" "eval" "false" "let" "limit" "local"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
578 "newpgrp" "result" "time" "umask" "var" "vars" "wait" "whatis")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
579
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
580 (jsh eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
581 "bg" "fg" "jobs" "kill" "stop" "suspend")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
582
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
583 (jcsh eval sh-append csh
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
584 "bg" "fg" "jobs" "kill" "notify" "stop" "suspend")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
585
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
586 (ksh88 eval sh-append bourne
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
587 "alias" "bg" "false" "fc" "fg" "jobs" "kill" "let" "print" "time"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
588 "typeset" "unalias" "whence")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
589
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
590 (oash eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
591 "checkwin" "dateline" "error" "form" "menu" "newwin" "oadeinit"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
592 "oaed" "oahelp" "oainit" "pp" "ppfile" "scan" "scrollok" "wattr"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
593 "wclear" "werase" "win" "wmclose" "wmmessage" "wmopen" "wmove"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
594 "wmtitle" "wrefresh")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
595
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
596 (pdksh eval sh-append ksh88
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
597 "bind")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
598
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
599 (posix eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
600 "command")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
601
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
602 (rc "builtin" "cd" "echo" "eval" "limit" "newpgrp" "shift" "umask" "wait"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
603 "whatis")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
604
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
605 (sh eval sh-append bourne
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
606 "hash" "test" "type")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
607
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
608 ;; The next entry is only used for defining the others
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
609 (shell "cd" "echo" "eval" "set" "shift" "umask" "unset" "wait")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
610
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
611 (wksh eval sh-append ksh88
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
612 "Xt[A-Z][A-Za-z]*")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
613
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
614 (zsh eval sh-append ksh88
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
615 "autoload" "bindkey" "builtin" "chdir" "compctl" "declare" "dirs"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
616 "disable" "disown" "echotc" "enable" "functions" "getln" "hash"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
617 "history" "integer" "limit" "local" "log" "popd" "pushd" "r"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
618 "readonly" "rehash" "sched" "setopt" "source" "suspend" "true"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
619 "ttyctl" "type" "unfunction" "unhash" "unlimit" "unsetopt" "vared"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
620 "which"))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
621 "*List of all shell builtins for completing read and fontification.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
622 Note that on some systems not all builtins are available or some are
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
623 implemented as aliases. See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
624 :type '(repeat (cons (symbol :tag "Shell")
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
625 (choice (repeat string)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
626 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
627 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
628 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
629 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
630
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
631
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
632
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
633 (defcustom sh-leading-keywords
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
634 '((csh "else")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
635
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
636 (es "true" "unwind-protect" "whatis")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
637
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
638 (rc "else")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
639
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
640 (sh "do" "elif" "else" "if" "then" "trap" "type" "until" "while"))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
641 "*List of keywords that may be immediately followed by a builtin or keyword.
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
642 Given some confusion between keywords and builtins depending on shell and
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
643 system, the distinction here has been based on whether they influence the
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
644 flow of control or syntax. See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
645 :type '(repeat (cons (symbol :tag "Shell")
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
646 (choice (repeat string)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
647 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
648 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
649 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
650 :group 'sh-script)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
651
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
652
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
653 (defcustom sh-other-keywords
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
654 '((bash eval sh-append bourne
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
655 "bye" "logout")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
656
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
657 ;; The next entry is only used for defining the others
16810
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
658 (bourne eval sh-append sh
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
659 "function")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
660
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
661 (csh eval sh-append shell
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
662 "breaksw" "default" "end" "endif" "endsw" "foreach" "goto"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
663 "if" "logout" "onintr" "repeat" "switch" "then" "while")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
664
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
665 (es "break" "catch" "exec" "exit" "fn" "for" "forever" "fork" "if"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
666 "return" "throw" "while")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
667
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
668 (ksh88 eval sh-append bourne
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
669 "select")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
670
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
671 (rc "break" "case" "exec" "exit" "fn" "for" "if" "in" "return" "switch"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
672 "while")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
673
16810
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
674 (sh eval sh-append shell
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
675 "done" "esac" "fi" "for" "in" "return")
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
676
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
677 ;; The next entry is only used for defining the others
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
678 (shell "break" "case" "continue" "exec" "exit")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
679
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
680 (zsh eval sh-append bash
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
681 "select"))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
682 "*List of keywords not in `sh-leading-keywords'.
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
683 See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
684 :type '(repeat (cons (symbol :tag "Shell")
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
685 (choice (repeat string)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
686 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
687 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
688 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
689 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
693 (defvar sh-variables
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
694 '((bash eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
695 "allow_null_glob_expansion" "auto_resume" "BASH" "BASH_VERSION"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
696 "cdable_vars" "ENV" "EUID" "FCEDIT" "FIGNORE" "glob_dot_filenames"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
697 "histchars" "HISTFILE" "HISTFILESIZE" "history_control" "HISTSIZE"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
698 "hostname_completion_file" "HOSTTYPE" "IGNOREEOF" "ignoreeof"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
699 "LINENO" "MAIL_WARNING" "noclobber" "nolinks" "notify"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
700 "no_exit_on_failed_exec" "NO_PROMPT_VARS" "OLDPWD" "OPTERR" "PPID"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
701 "PROMPT_COMMAND" "PS4" "pushd_silent" "PWD" "RANDOM" "REPLY"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
702 "SECONDS" "SHLVL" "TMOUT" "UID")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
703
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
704 (csh eval sh-append shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
705 "argv" "cdpath" "child" "echo" "histchars" "history" "home"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
706 "ignoreeof" "mail" "noclobber" "noglob" "nonomatch" "path" "prompt"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
707 "shell" "status" "time" "verbose")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
708
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
709 (es eval sh-append shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
710 "apid" "cdpath" "CDPATH" "history" "home" "ifs" "noexport" "path"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
711 "pid" "prompt" "signals")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
712
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
713 (jcsh eval sh-append csh
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
714 "notify")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
715
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
716 (ksh88 eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
717 "ENV" "ERRNO" "FCEDIT" "FPATH" "HISTFILE" "HISTSIZE" "LINENO"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
718 "OLDPWD" "PPID" "PS3" "PS4" "PWD" "RANDOM" "REPLY" "SECONDS"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
719 "TMOUT")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
720
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
721 (oash eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
722 "FIELD" "FIELD_MAX" "LAST_KEY" "OALIB" "PP_ITEM" "PP_NUM")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
723
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
724 (rc eval sh-append shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
725 "apid" "apids" "cdpath" "CDPATH" "history" "home" "ifs" "path" "pid"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
726 "prompt" "status")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
727
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
728 (sh eval sh-append shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
729 "CDPATH" "IFS" "OPTARG" "OPTIND" "PS1" "PS2")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
730
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
731 ;; The next entry is only used for defining the others
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
732 (shell "COLUMNS" "EDITOR" "HOME" "HUSHLOGIN" "LANG" "LC_COLLATE"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
733 "LC_CTYPE" "LC_MESSAGES" "LC_MONETARY" "LC_NUMERIC" "LC_TIME"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
734 "LINES" "LOGNAME" "MAIL" "MAILCHECK" "MAILPATH" "PAGER" "PATH"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
735 "SHELL" "TERM" "TERMCAP" "TERMINFO" "VISUAL")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
736
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
737 (tcsh eval sh-append csh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
738 "addsuffix" "ampm" "autocorrect" "autoexpand" "autolist"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
739 "autologout" "chase_symlinks" "correct" "dextract" "edit" "el"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
740 "fignore" "gid" "histlit" "HOST" "HOSTTYPE" "HPATH"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
741 "ignore_symlinks" "listjobs" "listlinks" "listmax" "matchbeep"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
742 "nobeep" "NOREBIND" "oid" "printexitvalue" "prompt2" "prompt3"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
743 "pushdsilent" "pushdtohome" "recexact" "recognize_only_executables"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
744 "rmstar" "savehist" "SHLVL" "showdots" "sl" "SYSTYPE" "tcsh" "term"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
745 "tperiod" "tty" "uid" "version" "visiblebell" "watch" "who"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
746 "wordchars")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
747
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
748 (zsh eval sh-append ksh88
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
749 "BAUD" "bindcmds" "cdpath" "DIRSTACKSIZE" "fignore" "FIGNORE" "fpath"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
750 "HISTCHARS" "hostcmds" "hosts" "HOSTS" "LISTMAX" "LITHISTSIZE"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
751 "LOGCHECK" "mailpath" "manpath" "NULLCMD" "optcmds" "path" "POSTEDIT"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
752 "prompt" "PROMPT" "PROMPT2" "PROMPT3" "PROMPT4" "psvar" "PSVAR"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
753 "READNULLCMD" "REPORTTIME" "RPROMPT" "RPS1" "SAVEHIST" "SPROMPT"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
754 "STTY" "TIMEFMT" "TMOUT" "TMPPREFIX" "varcmds" "watch" "WATCH"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
755 "WATCHFMT" "WORDCHARS" "ZDOTDIR"))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
756 "List of all shell variables available for completing read.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
757 See `sh-feature'.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
759
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
760 ;;; Font-Lock support
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
761
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
762 (defface sh-heredoc-face
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
763 '((((class color)
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
764 (background dark))
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
765 (:foreground "yellow" :bold t))
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
766 (((class color)
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
767 (background light))
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
768 (:foreground "tan" ))
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
769 (t
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
770 (:bold t)))
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
771 "Face to show a here-document"
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
772 :group 'sh-indentation)
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
773 (defvar sh-heredoc-face 'sh-heredoc-face)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
776 (defvar sh-font-lock-keywords
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
777 '((csh eval sh-append shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
778 '("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
779 font-lock-variable-name-face))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
780
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
781 (es eval sh-append executable-font-lock-keywords
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
782 '("\\$#?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\)" 1
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
783 font-lock-variable-name-face))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
785 (rc eval identity es)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
787 (sh eval sh-append shell
20900
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
788 ;; Variable names.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
789 '("\\$\\({#?\\)?\\([A-Za-z_][A-Za-z0-9_]*\\|[-#?@!]\\)" 2
20900
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
790 font-lock-variable-name-face)
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
791 ;; Function names.
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
792 '("^\\(\\sw+\\)[ \t]*(" 1 font-lock-function-name-face)
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
793 '("\\<\\(function\\)\\>[ \t]*\\(\\sw+\\)?"
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
794 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
796 ;; The next entry is only used for defining the others
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
797 (shell eval sh-append executable-font-lock-keywords
14849
e36c046e28b1 (sh-font-lock-keywords): Highlight \ only with non-alphanumeric char.
Richard M. Stallman <rms@gnu.org>
parents: 14418
diff changeset
798 '("\\\\[^A-Za-z0-9]" 0 font-lock-string-face)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
799 '("\\${?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\|[$*_]\\)" 1
23501
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
800 font-lock-variable-name-face))
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
801 (rpm eval sh-append rpm2
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
802 '("%{?\\(\\sw+\\)" 1 font-lock-keyword-face))
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
803 (rpm2 eval sh-append shell
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
804 '("^\\(\\sw+\\):" 1 font-lock-variable-name-face)))
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
805 "Default expressions to highlight in Shell Script modes. See `sh-feature'.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
807 (defvar sh-font-lock-keywords-1
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
808 '((sh "[ \t]in\\>"))
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
809 "Subdued level highlighting for Shell Script modes.")
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
810
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
811 (defvar sh-font-lock-keywords-2 ()
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
812 "Gaudy level highlighting for Shell Script modes.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
814 ;; These are used for the syntax table stuff (derived from cperl-mode).
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
815 ;; Note: parse-sexp-lookup-properties must be set to t for it to work.
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
816 (defconst sh-st-punc (string-to-syntax "."))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
817 (defconst sh-here-doc-syntax (string-to-syntax "|")) ;; generic string
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
818
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
819 (defun sh-font-lock-heredoc (start string quoted)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
820 "Determine the syntax of the \\n after a <<HEREDOC."
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
821 (unless (sh-in-comment-or-string start)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
822 ;; We're looking at <<STRING, so we add "^STRING$" to the syntactic
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
823 ;; font-lock keywords to detect the end of this here document.
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
824 (let ((ere (concat
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
825 "^" (if quoted "[ \t]*")
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
826 (regexp-quote (replace-regexp-in-string "['\"]" "" string))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
827 "\\(\n\\)")))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
828 (unless (assoc ere font-lock-syntactic-keywords)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
829 (let* ( ;; A rough regexp that should find us back.
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
830 (sre (concat "<<\\(-\\)?\\s-*['\"]?"
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
831 (regexp-quote string) "['\"]?[ \t\n]"))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
832 (code `(cond
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
833 ((save-excursion (re-search-backward ,sre nil t))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
834 ;; This ^STRING$ is indeed following a <<STRING
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
835 sh-here-doc-syntax)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
836 ((not (save-excursion (re-search-forward ,sre nil t)))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
837 ;; There's no <<STRING either before or after us,
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
838 ;; so we should remove this now obsolete entry.
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
839 (setq font-lock-syntactic-keywords
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
840 (delq (assoc ,ere font-lock-syntactic-keywords)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
841 font-lock-syntactic-keywords))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
842 nil))))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
843 ;; Use destructive update so the new keyword gets used right away.
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
844 (setq font-lock-syntactic-keywords
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
845 (nconc font-lock-syntactic-keywords
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
846 (list (font-lock-compile-keyword `(,ere 1 ,code))))))))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
847 sh-here-doc-syntax))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
848
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
849 (defun sh-font-lock-paren (start)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
850 (save-excursion
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
851 (goto-char start)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
852 ;; Skip through all patterns
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
853 (while
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
854 (progn
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
855 (forward-comment (- (point-max)))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
856 ;; Skip through one pattern
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
857 (while
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
858 (or (/= 0 (skip-syntax-backward "w_"))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
859 (/= 0 (skip-chars-backward "?*/"))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
860 (when (memq (char-before) '(?\" ?\'))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
861 (condition-case nil (progn (backward-sexp 1) t)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
862 (error nil)))))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
863 (forward-comment (- (point-max)))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
864 (when (eq (char-before) ?|)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
865 (backward-char 1) t)))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
866 (when (save-excursion (backward-char 2) (looking-at ";;\\|in"))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
867 sh-st-punc)))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
868
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
869 (defconst sh-font-lock-syntactic-keywords
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
870 ;; Mark a `#' character as having punctuation syntax in a variable reference.
20420
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
871 ;; Really we should do this properly. From Chet Ramey and Brian Fox:
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
872 ;; "A `#' begins a comment when it is unquoted and at the beginning of a
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
873 ;; word. In the shell, words are separated by metacharacters."
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
874 ;; To do this in a regexp would be slow as it would be anchored to the right.
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
875 ;; But I can't be bothered to write a function to do it properly and
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
876 ;; efficiently. So we only do it properly for `#' in variable references and
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
877 ;; do it efficiently by anchoring the regexp to the left.
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
878 `(("\\${?[^}#\n\t ]*\\(##?\\)" 1 ,sh-st-punc)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
879 ;; Find HEREDOC starters and add a corresponding rule for the ender.
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
880 ("[^<>]<<\\(-\\)?\\s-*\\(\\(['\"][^'\"]+['\"]\\|\\sw\\|\\s_\\)+\\).*\\(\n\\)"
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
881 4 (sh-font-lock-heredoc
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
882 (match-beginning 0) (match-string 2) (match-end 1)))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
883 ;; Distinguish the special close-paren in `case'.
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
884 (")" 0 (sh-font-lock-paren (match-beginning 0)))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
885
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
886 (defun sh-font-lock-syntactic-face-function (state)
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
887 (if (nth 3 state)
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
888 (if (char-valid-p (nth 3 state))
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
889 font-lock-string-face
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
890 sh-heredoc-face)
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
891 font-lock-comment-face))
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
892
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
893 (defgroup sh-indentation nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
894 "Variables controlling indentation in shell scripts.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
895
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
896 Note: customizing these variables will not affect existing buffers if
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
897 `sh-make-vars-local' is no-nil. See the documentation for
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
898 variable `sh-make-vars-local', command `sh-make-vars-local'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
899 and command `sh-reset-indent-vars-to-global-values'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
900 :group 'sh-script)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
901
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
902
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
903 (defcustom sh-set-shell-hook nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
904 "*Hook run by `sh-set-shell'."
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
905 :type 'hook
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
906 :group 'sh-script)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
907
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
908 (defcustom sh-mode-hook nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
909 "*Hook run by `sh-mode'."
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
910 :type 'hook
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
911 :group 'sh-script)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
912
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
913 (defcustom sh-learn-basic-offset nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
914 "*When `sh-guess-basic-offset' should learn `sh-basic-offset'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
915
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
916 nil mean: never.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
917 t means: only if there seems to be an obvious value.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
918 Anything else means: whenever we have a \"good guess\" as to the value."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
919 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
920 (const :tag "Never" nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
921 (const :tag "Only if sure" t)
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
922 (const :tag "If have a good guess" usually))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
923 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
924
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
925 (defcustom sh-popup-occur-buffer nil
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
926 "*Controls when `sh-learn-buffer-indent' pops the *indent* buffer.
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
927 If t it is always shown. If nil, it is shown only when there
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
928 are conflicts."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
929 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
930 (const :tag "Only when there are conflicts." nil)
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
931 (const :tag "Always" t))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
932 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
933
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
934 (defcustom sh-blink t
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
935 "*If non-nil, `sh-show-indent' shows the line indentation is relative to.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
936 The position on the line is not necessarily meaningful.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
937 In some cases the line will be the matching keyword, but this is not
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
938 always the case."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
939 :type 'boolean
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
940 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
941
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
942 (defcustom sh-first-lines-indent 0
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
943 "*The indentation of the first non-blank non-comment line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
944 Usually 0 meaning first column.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
945 Can be set to a number, or to nil which means leave it as is."
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
946 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
947 (const :tag "Leave as is" nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
948 (integer :tag "Column number"
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
949 :menu-tag "Indent to this col (0 means first col)" ))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
950 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
951
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
952
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
953 (defcustom sh-basic-offset 4
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
954 "*The default indentation increment.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
955 This value is used for the + and - symbols in an indentation variable."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
956 :type 'integer
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
957 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
958
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
959 (defcustom sh-indent-comment nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
960 "*How a comment line is to be indented.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
961 nil means leave it as it is;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
962 t means indent it as a normal line, aligning it to previous non-blank
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
963 non-comment line;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
964 a number means align to that column, e.g. 0 means fist column."
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
965 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
966 (const :tag "Leave as is." nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
967 (const :tag "Indent as a normal line." t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
968 (integer :menu-tag "Indent to this col (0 means first col)."
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
969 :tag "Indent to column number.") )
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
970 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
971
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
972
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
973 (defvar sh-debug nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
974 "Enable lots of debug messages - if function `sh-debug' is enabled.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
975
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
976
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
977 ;; Uncomment this defun and comment the defmacro for debugging.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
978 ;; (defun sh-debug (&rest args)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
979 ;; "For debugging: display message ARGS if variable SH-DEBUG is non-nil."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
980 ;; (if sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
981 ;; (apply 'message args)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
982 (defmacro sh-debug (&rest args))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
983
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
984 (defconst sh-symbol-list
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
985 '((const :tag "+ " :value +
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
986 :menu-tag "+ Indent right by sh-basic-offset")
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
987 (const :tag "- " :value -
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
988 :menu-tag "- Indent left by sh-basic-offset")
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
989 (const :tag "++" :value ++
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
990 :menu-tag "++ Indent right twice sh-basic-offset")
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
991 (const :tag "--" :value --
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
992 :menu-tag "-- Indent left twice sh-basic-offset")
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
993 (const :tag "* " :value *
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
994 :menu-tag "* Indent right half sh-basic-offset")
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
995 (const :tag "/ " :value /
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
996 :menu-tag "/ Indent left half sh-basic-offset")))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
997
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
998 (defcustom sh-indent-for-else 0
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
999 "*How much to indent an else relative to an if. Usually 0."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1000 :type `(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1001 (integer :menu-tag "A number (positive=>indent right)"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1002 :tag "A number")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1003 (const :tag "--") ;; separator!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1004 ,@ sh-symbol-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1005 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1006 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1007
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1008 (defconst sh-number-or-symbol-list
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1009 (append '((integer :menu-tag "A number (positive=>indent right)"
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1010 :tag "A number")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1011 (const :tag "--")) ; separator
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1012 sh-symbol-list))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1013
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1014 (defcustom sh-indent-for-fi 0
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1015 "*How much to indent a fi relative to an if. Usually 0."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1016 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1017 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1018
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1019 (defcustom sh-indent-for-done '0
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1020 "*How much to indent a done relative to its matching stmt. Usually 0."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1021 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1022 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1023
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1024 (defcustom sh-indent-after-else '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1025 "*How much to indent a statement after an else statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1026 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1027 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1028
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1029 (defcustom sh-indent-after-if '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1030 "*How much to indent a statement after an if statement.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1031 This includes lines after else and elif statements, too, but
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1032 does not affect then else elif or fi statements themselves."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1033 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1034 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1035
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1036 (defcustom sh-indent-for-then '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1037 "*How much to indent an then relative to an if."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1038 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1039 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1040
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1041 (defcustom sh-indent-for-do '*
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1042 "*How much to indent a do statement.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1043 This is relative to the statement before the do, i.e. the
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1044 while until or for statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1045 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1046 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1047
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1048 (defcustom sh-indent-after-do '*
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1049 "*How much to indent a line after a do statement.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1050 This is used when the do is the first word of the line.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1051 This is relative to the statement before the do, e.g. a
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1052 while for repeat or select statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1053 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1054 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1055
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1056 (defcustom sh-indent-after-loop-construct '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1057 "*How much to indent a statement after a loop construct.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1058
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1059 This variable is used when the keyword \"do\" is on the same line as the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1060 loop statement (e.g. \"until\", \"while\" or \"for\").
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1061 If the do is on a line by itself, then `sh-indent-after-do' is used instead."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1062 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1063 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1064
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1065
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1066 (defcustom sh-indent-after-done 0
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1067 "*How much to indent a statement after a \"done\" keyword.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1068 Normally this is 0, which aligns the \"done\" to the matching
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1069 looping construct line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1070 Setting it non-zero allows you to have the \"do\" statement on a line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1071 by itself and align the done under to do."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1072 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1073 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1074
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1075 (defcustom sh-indent-for-case-label '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1076 "*How much to indent a case label statement.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1077 This is relative to the line containing the case statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1078 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1079 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1080
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1081 (defcustom sh-indent-for-case-alt '++
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1082 "*How much to indent statements after the case label.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1083 This is relative to the line containing the case statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1084 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1085 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1086
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1087
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1088 (defcustom sh-indent-for-continuation '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1089 "*How much to indent for a continuation statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1090 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1091 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1092
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1093 (defcustom sh-indent-after-open '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1094 "*How much to indent after a line with an opening parenthesis or brace.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1095 For an open paren after a function `sh-indent-after-function' is used."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1096 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1097 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1098
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1099 (defcustom sh-indent-after-function '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1100 "*How much to indent after a function line."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1101 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1102 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1103
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1104 ;; These 2 are for the rc shell:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1105
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1106 (defcustom sh-indent-after-switch '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1107 "*How much to indent a case statement relative to the switch statement.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1108 This is for the rc shell."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1109 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1110 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1111
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1112 (defcustom sh-indent-after-case '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1113 "*How much to indent a statement relative to the case statement.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1114 This is for the rc shell."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1115 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1116 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1117
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1118 ;; Internal use - not designed to be changed by the user:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1119
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1120 (defun sh-mkword-regexpr (word)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1121 "Make a regexp which matches WORD as a word.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1122 This specifically excludes an occurrence of WORD followed by
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1123 punctuation characters like '-'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1124 (concat word "\\([^-a-z0-9_]\\|$\\)"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1125
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1126 (defconst sh-re-done (sh-mkword-regexpr "done"))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1127
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1128
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1129 (defconst sh-kws-for-done
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1130 '((sh . ( "while" "until" "for" ) )
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1131 (bash . ( "while" "until" "for" "select" ) )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1132 (ksh88 . ( "while" "until" "for" "select" ) )
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1133 (zsh . ( "while" "until" "for" "repeat" "select" ) ) )
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1134 "Which keywords can match the word `done' in this shell.")
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1135
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1136
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1137 (defconst sh-indent-supported
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1138 '((sh . t)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1139 (csh . nil)
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1140 (rc . t))
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1141 "Shell types that shell indenting can do something with.")
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1142
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1143 (defvar sh-indent-supported-here nil
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1144 "Non-nil if we support indentation for the current buffer's shell type.")
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1145
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1146 (defconst sh-electric-rparen-needed
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1147 '((sh . t))
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1148 "Non-nil if the shell type needs an electric handling of case alternatives.")
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1149
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1150 (defconst sh-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1151 '(
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1152 sh-basic-offset sh-first-lines-indent sh-indent-after-case
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1153 sh-indent-after-do sh-indent-after-done
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1154 sh-indent-after-else
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1155 sh-indent-after-if
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1156 sh-indent-after-loop-construct
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1157 sh-indent-after-open
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1158 sh-indent-comment
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1159 sh-indent-for-case-alt
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1160 sh-indent-for-case-label
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1161 sh-indent-for-continuation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1162 sh-indent-for-do
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1163 sh-indent-for-done
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1164 sh-indent-for-else
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1165 sh-indent-for-fi
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1166 sh-indent-for-then
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1167 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1168 "A list of variables used by script mode to control indentation.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1169 This list is used when switching between buffer-local and global
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1170 values of variables, and for the commands using indentation styles.")
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1171
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1172 (defvar sh-make-vars-local t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1173 "*Controls whether indentation variables are local to the buffer.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1174 If non-nil, indentation variables are made local initially.
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1175 If nil, you can later make the variables local by invoking
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1176 command `sh-make-vars-local'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1177 The default is t because I assume that in one Emacs session one is
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1178 frequently editing existing scripts with different styles.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1179
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1180
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 ;; mode-command and utility functions
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1182
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1183 ;;;###autoload
14195
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
1184 (put 'sh-mode 'mode-class 'special)
14221
cd28284abca4 (sh-mode): Add autoload cookie.
Erik Naggum <erik@naggum.no>
parents: 14211
diff changeset
1185
cd28284abca4 (sh-mode): Add autoload cookie.
Erik Naggum <erik@naggum.no>
parents: 14211
diff changeset
1186 ;;;###autoload
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1187 (define-derived-mode sh-mode nil "Shell-script"
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1188 "Major mode for editing shell scripts.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1189 This mode works for many shells, since they all have roughly the same syntax,
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1190 as far as commands, arguments, variables, pipes, comments etc. are concerned.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1191 Unless the file's magic number indicates the shell, your usual shell is
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1192 assumed. Since filenames rarely give a clue, they are not further analyzed.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1193
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1194 This mode adapts to the variations between shells (see `sh-set-shell') by
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1195 means of an inheritance based feature lookup (see `sh-feature'). This
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1196 mechanism applies to all variables (including skeletons) that pertain to
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1197 shell-specific features.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1198
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1199 The default style of this mode is that of Rosenblatt's Korn shell book.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1200 The syntax of the statements varies with the shell being used. The
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1201 following commands are available, based on the current shell's syntax:
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1202
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1203 \\[sh-case] case statement
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1204 \\[sh-for] for loop
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1205 \\[sh-function] function definition
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1206 \\[sh-if] if statement
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1207 \\[sh-indexed-loop] indexed loop from 1 to n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1208 \\[sh-while-getopts] while getopts loop
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1209 \\[sh-repeat] repeat loop
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1210 \\[sh-select] select loop
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1211 \\[sh-until] until loop
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1212 \\[sh-while] while loop
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1213
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1214 For sh and rc shells indentation commands are:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1215 \\[sh-show-indent] Show the variable controlling this line's indentation.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1216 \\[sh-set-indent] Set then variable controlling this line's indentation.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1217 \\[sh-learn-line-indent] Change the indentation variable so this line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1218 would indent to the way it currently is.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1219 \\[sh-learn-buffer-indent] Set the indentation variables so the
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1220 buffer indents as it currently is indented.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1221
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1222
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1223 \\[backward-delete-char-untabify] Delete backward one position, even if it was a tab.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 \\[sh-newline-and-indent] Delete unquoted space and indent new line same as this one.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 \\[sh-end-of-command] Go to end of successive commands.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 \\[sh-beginning-of-command] Go to beginning of successive commands.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1227 \\[sh-set-shell] Set this buffer's shell, and maybe its magic number.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1228 \\[sh-execute-region] Have optional header and region be executed in a subshell.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1229
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1230 \\[sh-maybe-here-document] Without prefix, following an unquoted < inserts here document.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1231 {, (, [, ', \", `
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1232 Unless quoted with \\, insert the pairs {}, (), [], or '', \"\", ``.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1233
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1234 If you generally program a shell different from your login shell you can
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1235 set `sh-shell-file' accordingly. If your shell's file name doesn't correctly
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1236 indicate what shell it is use `sh-alias-alist' to translate.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1237
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1238 If your shell gives error messages with line numbers, you can use \\[executable-interpret]
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1239 with your script for an edit-interpret-debug cycle."
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1240 (make-local-variable 'skeleton-end-hook)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1241 (make-local-variable 'paragraph-start)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1242 (make-local-variable 'paragraph-separate)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1243 (make-local-variable 'comment-start)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1244 (make-local-variable 'comment-start-skip)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1245 (make-local-variable 'require-final-newline)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1246 (make-local-variable 'sh-header-marker)
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1247 (make-local-variable 'sh-shell-file)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1248 (make-local-variable 'sh-shell)
12864
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
1249 (make-local-variable 'skeleton-pair-alist)
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
1250 (make-local-variable 'skeleton-pair-filter)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1251 (make-local-variable 'comint-dynamic-complete-functions)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1252 (make-local-variable 'comint-prompt-regexp)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1253 (make-local-variable 'font-lock-defaults)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1254 (make-local-variable 'skeleton-filter)
12887
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
1255 (make-local-variable 'skeleton-newline-indent-rigidly)
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
1256 (make-local-variable 'sh-shell-variables)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
1257 (make-local-variable 'sh-shell-variables-initialized)
20395
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
1258 (make-local-variable 'imenu-generic-expression)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1259 (make-local-variable 'sh-indent-supported-here)
26813
da094b0ffe3c Fix for when font-lock mode is active.
Gerd Moellmann <gerd@gnu.org>
parents: 25986
diff changeset
1260 (make-local-variable 'font-lock-unfontify-region-function)
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1261 (setq skeleton-end-hook (lambda ()
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1262 (or (eolp) (newline) (indent-relative)))
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
1263 paragraph-start (concat page-delimiter "\\|$")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1264 paragraph-separate paragraph-start
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1265 comment-start "# "
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1266 comint-dynamic-complete-functions sh-dynamic-complete-functions
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1267 ;; we can't look if previous line ended with `\'
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1268 comint-prompt-regexp "^[ \t]*"
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1269 font-lock-defaults
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1270 `((sh-font-lock-keywords
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
1271 sh-font-lock-keywords-1 sh-font-lock-keywords-2)
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
1272 nil nil
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
1273 ((?/ . "w") (?~ . "w") (?. . "w") (?- . "w") (?_ . "w")) nil
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1274 (font-lock-syntactic-keywords
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1275 ;; Copy so we can use destructive update in `sh-font-lock-heredoc'.
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1276 . ,(copy-sequence sh-font-lock-syntactic-keywords))
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1277 (font-lock-syntactic-face-function
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1278 . sh-font-lock-syntactic-face-function))
12864
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
1279 skeleton-pair-alist '((?` _ ?`))
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
1280 skeleton-pair-filter 'sh-quoted-p
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1281 skeleton-further-elements '((< '(- (min sh-indentation
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1282 (current-column)))))
12887
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
1283 skeleton-filter 'sh-feature
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1284 skeleton-newline-indent-rigidly t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1285 sh-indent-supported-here nil)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1286 (set (make-local-variable 'parse-sexp-ignore-comments) t)
16552
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1287 ;; Parse or insert magic number for exec, and set all variables depending
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1288 ;; on the shell thus determined.
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1289 (let ((interpreter
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1290 (save-excursion
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1291 (goto-char (point-min))
23501
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
1292 (cond ((looking-at "#![ \t]?\\([^ \t\n]*/bin/env[ \t]\\)?\\([^ \t\n]+\\)")
24730
e1cb8de8ffb2 (sh-mode): Do not fail if buffer has no
Karl Heuer <kwzh@gnu.org>
parents: 23869
diff changeset
1293 (match-string 2))
e1cb8de8ffb2 (sh-mode): Do not fail if buffer has no
Karl Heuer <kwzh@gnu.org>
parents: 23869
diff changeset
1294 ((and buffer-file-name
e1cb8de8ffb2 (sh-mode): Do not fail if buffer has no
Karl Heuer <kwzh@gnu.org>
parents: 23869
diff changeset
1295 (string-match "\\.m?spec$" buffer-file-name))
23501
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
1296 "rpm")))))
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1297 (sh-set-shell (or interpreter sh-shell-file) nil nil)))
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1298
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1299 ;;;###autoload
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1300 (defalias 'shell-script-mode 'sh-mode)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1301
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1302
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1303 (defun sh-font-lock-keywords (&optional keywords)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1304 "Function to get simple fontification based on `sh-font-lock-keywords'.
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1305 This adds rules for comments and assignments."
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1306 (sh-feature sh-font-lock-keywords
23511
8b4cdcbaf071 (sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents: 23501
diff changeset
1307 (when (stringp (sh-feature sh-assignment-regexp))
8b4cdcbaf071 (sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents: 23501
diff changeset
1308 (lambda (list)
8b4cdcbaf071 (sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents: 23501
diff changeset
1309 `((,(sh-feature sh-assignment-regexp)
8b4cdcbaf071 (sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents: 23501
diff changeset
1310 1 font-lock-variable-name-face)
8b4cdcbaf071 (sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents: 23501
diff changeset
1311 ,@keywords
8b4cdcbaf071 (sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents: 23501
diff changeset
1312 ,@list)))))
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1313
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1314 (defun sh-font-lock-keywords-1 (&optional builtins)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1315 "Function to get better fontification including keywords."
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1316 (let ((keywords (concat "\\([;(){}`|&]\\|^\\)[ \t]*\\(\\(\\("
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1317 (mapconcat 'identity
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1318 (sh-feature sh-leading-keywords)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1319 "\\|")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1320 "\\)[ \t]+\\)?\\("
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1321 (mapconcat 'identity
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1322 (append (sh-feature sh-leading-keywords)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1323 (sh-feature sh-other-keywords))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1324 "\\|")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1325 "\\)")))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1326 (sh-font-lock-keywords
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1327 `(,@(if builtins
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1328 `((,(concat keywords "[ \t]+\\)?\\("
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1329 (mapconcat 'identity (sh-feature sh-builtins) "\\|")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1330 "\\)\\>")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1331 (2 font-lock-keyword-face nil t)
16478
fb944e4dc708 Use new face.
Simon Marshall <simon@gnu.org>
parents: 16468
diff changeset
1332 (6 font-lock-builtin-face))
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1333 ,@(sh-feature sh-font-lock-keywords-2)))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1334 (,(concat keywords "\\)\\>")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1335 2 font-lock-keyword-face)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1336 ,@(sh-feature sh-font-lock-keywords-1)))))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1337
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1338 (defun sh-font-lock-keywords-2 ()
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1339 "Function to get better fontification including keywords and builtins."
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1340 (sh-font-lock-keywords-1 t))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1341
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1343 (defvar sh-regexp-for-done nil
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1344 "A buffer-local regexp to match opening keyword for done.")
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1345
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1346 (defvar sh-kw-alist nil
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1347 "A buffer-local, since it is shell-type dependent, list of keywords.")
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1348
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1349 ;; ( key-word first-on-this on-prev-line )
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1350 ;; This is used to set `sh-kw-alist' which is a list of sublists each
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1351 ;; having 3 elements:
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1352 ;; a keyword
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1353 ;; a rule to check when the keyword appears on "this" line
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1354 ;; a rule to check when the keyword appears on "the previous" line
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1355 ;; The keyword is usually a string and is the first word on a line.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1356 ;; If this keyword appears on the line whose indentation is to be
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1357 ;; calculated, the rule in element 2 is called. If this returns
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1358 ;; non-zero, the resulting point (which may be changed by the rule)
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1359 ;; is used as the default indentation.
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1360 ;; If it returned false or the keyword was not found in the table,
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1361 ;; then the keyword from the previous line is looked up and the rule
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1362 ;; in element 3 is called. In this case, however,
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1363 ;; `sh-get-indent-info' does not stop but may keep going and test
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1364 ;; other keywords against rules in element 3. This is because the
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1365 ;; preceding line could have, for example, an opening "if" and an
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1366 ;; opening "while" keyword and we need to add the indentation offsets
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1367 ;; for both.
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1368 ;;
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1369 (defconst sh-kw
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1370 '((sh
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1371 ("if" nil sh-handle-prev-if)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1372 ("elif" sh-handle-this-else sh-handle-prev-else)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1373 ("else" sh-handle-this-else sh-handle-prev-else)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1374 ("fi" sh-handle-this-fi sh-handle-prev-fi)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1375 ("then" sh-handle-this-then sh-handle-prev-then)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1376 ("(" nil sh-handle-prev-open)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1377 ("{" nil sh-handle-prev-open)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1378 ("[" nil sh-handle-prev-open)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1379 ("}" sh-handle-this-close nil)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1380 (")" sh-handle-this-close nil)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1381 ("]" sh-handle-this-close nil)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1382 ("case" nil sh-handle-prev-case)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1383 ("esac" sh-handle-this-esac sh-handle-prev-esac)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1384 (case-label nil sh-handle-after-case-label) ;; ???
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1385 (";;" nil sh-handle-prev-case-alt-end) ;; ???
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1386 ("done" sh-handle-this-done sh-handle-prev-done)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1387 ("do" sh-handle-this-do sh-handle-prev-do))
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1388
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1389 ;; Note: we don't need specific stuff for bash and zsh shells;
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1390 ;; the regexp `sh-regexp-for-done' handles the extra keywords
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1391 ;; these shells use.
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1392 (rc
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1393 ("{" nil sh-handle-prev-open)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1394 ("}" sh-handle-this-close nil)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1395 ("case" sh-handle-this-rc-case sh-handle-prev-rc-case))))
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1396
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1397
14148
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1398 (defun sh-set-shell (shell &optional no-query-flag insert-flag)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1399 "Set this buffer's shell to SHELL (a string).
16552
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1400 Makes this script executable via `executable-set-magic', and sets up the
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1401 proper starting #!-line, if INSERT-FLAG is non-nil.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1402 Calls the value of `sh-set-shell-hook' if set."
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1403 (interactive (list (completing-read "Name or path of shell: "
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1404 interpreter-mode-alist
14148
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1405 (lambda (x) (eq (cdr x) 'sh-mode)))
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1406 (eq executable-query 'function)
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1407 t))
23589
660727693bf6 (sh-canonicalize-shell): Fix regexp.
Andreas Schwab <schwab@suse.de>
parents: 23511
diff changeset
1408 (if (string-match "\\.exe\\'" shell)
23341
d29b6b51866f (sh-set-shell): Remove .exe suffix from shell name.
Richard M. Stallman <rms@gnu.org>
parents: 22783
diff changeset
1409 (setq shell (substring shell 0 (match-beginning 0))))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1410 (setq sh-shell (intern (file-name-nondirectory shell))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1411 sh-shell (or (cdr (assq sh-shell sh-alias-alist))
14148
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1412 sh-shell))
16552
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1413 (if insert-flag
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1414 (setq sh-shell-file
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1415 (executable-set-magic shell (sh-feature sh-shell-arg)
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1416 no-query-flag insert-flag)))
14148
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1417 (setq require-final-newline (sh-feature sh-require-final-newline)
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1418 ;;; local-abbrev-table (sh-feature sh-abbrevs)
16535
d5eeca7cdaf2 (sh-mode-syntax-table): Turn on comment syntax for #,
Richard M. Stallman <rms@gnu.org>
parents: 16533
diff changeset
1419 comment-start-skip "#+[\t ]*"
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1420 mode-line-process (format "[%s]" sh-shell)
14195
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
1421 sh-shell-variables nil
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
1422 sh-shell-variables-initialized nil
20395
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
1423 imenu-generic-expression (sh-feature sh-imenu-generic-expression)
23341
d29b6b51866f (sh-set-shell): Remove .exe suffix from shell name.
Richard M. Stallman <rms@gnu.org>
parents: 22783
diff changeset
1424 imenu-case-fold-search nil)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1425 (dolist (var (sh-feature sh-variables))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1426 (sh-remember-variable var))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1427 (make-local-variable 'indent-line-function)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1428 (if (setq sh-indent-supported-here (sh-feature sh-indent-supported))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1429 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1430 (message "Setting up indent for shell type %s" sh-shell)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1431 (set (make-local-variable 'parse-sexp-lookup-properties) t)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1432 (set (make-local-variable 'sh-kw-alist) (sh-feature sh-kw))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1433 (let ((regexp (sh-feature sh-kws-for-done)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1434 (if regexp
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1435 (set (make-local-variable 'sh-regexp-for-done)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1436 (sh-mkword-regexpr (regexp-opt regexp t)))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1437 (message "setting up indent stuff")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1438 ;; sh-mode has already made indent-line-function local
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1439 ;; but do it in case this is called before that.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1440 (setq indent-line-function 'sh-indent-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1441 (if sh-make-vars-local
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1442 (sh-make-vars-local))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1443 (message "Indentation setup for shell type %s" sh-shell))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1444 (message "No indentation for this shell type.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1445 (setq indent-line-function 'sh-basic-indent-line))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1446 (run-hooks 'sh-set-shell-hook))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1447
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1448
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1449
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1450 (defun sh-feature (list &optional function)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1451 "Index ALIST by the current shell.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1452 If ALIST isn't a list where every element is a cons, it is returned as is.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1453 Else indexing follows an inheritance logic which works in two ways:
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1454
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1455 - Fall back on successive ancestors (see `sh-ancestor-alist') as long as
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1456 the alist contains no value for the current shell.
24906
01882044b37a (sh-feature): If nothing is known about the given shell, use the
Richard M. Stallman <rms@gnu.org>
parents: 24899
diff changeset
1457 The ultimate default is always `sh'.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1458
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1459 - If the value thus looked up is a list starting with `eval' its `cdr' is
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1460 first evaluated. If that is also a list and the first argument is a
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1461 symbol in ALIST it is not evaluated, but rather recursively looked up in
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1462 ALIST to allow the function called to define the value for one shell to be
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1463 derived from another shell. While calling the function, is the car of the
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1464 alist element is the current shell.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1465 The value thus determined is physically replaced into the alist.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1466
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1467 Optional FUNCTION is applied to the determined value and the result is cached
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1468 in ALIST."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1469 (or (if (consp list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1470 (let ((l list))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1471 (while (and l (consp (car l)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1472 (setq l (cdr l)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1473 (if l list)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1474 (if function
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1475 (cdr (assoc (setq function (cons sh-shell function)) list)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1476 (let ((sh-shell sh-shell)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1477 elt val)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1478 (while (and sh-shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1479 (not (setq elt (assq sh-shell list))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1480 (setq sh-shell (cdr (assq sh-shell sh-ancestor-alist))))
24906
01882044b37a (sh-feature): If nothing is known about the given shell, use the
Richard M. Stallman <rms@gnu.org>
parents: 24899
diff changeset
1481 ;; If the shell is not known, treat it as sh.
01882044b37a (sh-feature): If nothing is known about the given shell, use the
Richard M. Stallman <rms@gnu.org>
parents: 24899
diff changeset
1482 (unless elt
01882044b37a (sh-feature): If nothing is known about the given shell, use the
Richard M. Stallman <rms@gnu.org>
parents: 24899
diff changeset
1483 (setq elt (assq 'sh list)))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1484 (if (and (consp (setq val (cdr elt)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1485 (eq (car val) 'eval))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1486 (setcdr elt
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1487 (setq val
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1488 (eval (if (consp (setq val (cdr val)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1489 (let ((sh-shell (car (cdr val)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1490 function)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1491 (if (assq sh-shell list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1492 (setcar (cdr val)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1493 (list 'quote
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1494 (sh-feature list))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1495 val)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1496 val)))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1497 (if function
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1498 (nconc list
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1499 (list (cons function
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1500 (setq sh-shell (car function)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1501 val (funcall (cdr function) val))))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1502 val)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1503
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1504
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1505
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1506 ;;; I commented this out because nobody calls it -- rms.
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1507 ;;;(defun sh-abbrevs (ancestor &rest list)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1508 ;;; "Iff it isn't, define the current shell as abbrev table and fill that.
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1509 ;;;Abbrev table will inherit all abbrevs from ANCESTOR, which is either an abbrev
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1510 ;;;table or a list of (NAME1 EXPANSION1 ...). In addition it will define abbrevs
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1511 ;;;according to the remaining arguments NAMEi EXPANSIONi ...
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1512 ;;;EXPANSION may be either a string or a skeleton command."
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1513 ;;; (or (if (boundp sh-shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1514 ;;; (symbol-value sh-shell))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1515 ;;; (progn
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1516 ;;; (if (listp ancestor)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1517 ;;; (nconc list ancestor))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1518 ;;; (define-abbrev-table sh-shell ())
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1519 ;;; (if (vectorp ancestor)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1520 ;;; (mapatoms (lambda (atom)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1521 ;;; (or (eq atom 0)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1522 ;;; (define-abbrev (symbol-value sh-shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1523 ;;; (symbol-name atom)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1524 ;;; (symbol-value atom)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1525 ;;; (symbol-function atom))))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1526 ;;; ancestor))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1527 ;;; (while list
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1528 ;;; (define-abbrev (symbol-value sh-shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1529 ;;; (car list)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1530 ;;; (if (stringp (car (cdr list)))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1531 ;;; (car (cdr list))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1532 ;;; "")
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1533 ;;; (if (symbolp (car (cdr list)))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1534 ;;; (car (cdr list))))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1535 ;;; (setq list (cdr (cdr list)))))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1536 ;;; (symbol-value sh-shell)))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1537
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1538
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1539 (defun sh-append (ancestor &rest list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1540 "Return list composed of first argument (a list) physically appended to rest."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1541 (nconc list ancestor))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1542
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1543
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1544 (defun sh-modify (skeleton &rest list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1545 "Modify a copy of SKELETON by replacing I1 with REPL1, I2 with REPL2 ..."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1546 (setq skeleton (copy-sequence skeleton))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1547 (while list
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1548 (setcar (or (nthcdr (car list) skeleton)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1549 (error "Index %d out of bounds" (car list)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1550 (car (cdr list)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1551 (setq list (nthcdr 2 list)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1552 skeleton)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1553
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1554
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1555 (defun sh-basic-indent-line ()
19480
7f11f103a0ca (sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 18382
diff changeset
1556 "Indent a line for Sh mode (shell script mode).
7f11f103a0ca (sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 18382
diff changeset
1557 Indent as far as preceding non-empty line, then by steps of `sh-indentation'.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1558 Lines containing only comments are considered empty."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1559 (interactive)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1560 (let ((previous (save-excursion
19480
7f11f103a0ca (sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 18382
diff changeset
1561 (while (and (progn (beginning-of-line)
7f11f103a0ca (sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 18382
diff changeset
1562 (not (bobp)))
14211
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1563 (progn
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1564 (forward-line -1)
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1565 (back-to-indentation)
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1566 (or (eolp)
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1567 (eq (following-char) ?#)))))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1568 (current-column)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1569 current)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1570 (save-excursion
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1571 (indent-to (if (eq this-command 'newline-and-indent)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1572 previous
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1573 (if (< (current-column)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1574 (setq current (progn (back-to-indentation)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1575 (current-column))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1576 (if (eolp) previous 0)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1577 (delete-region (point)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1578 (progn (beginning-of-line) (point)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1579 (if (eolp)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1580 (max previous (* (1+ (/ current sh-indentation))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1581 sh-indentation))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1582 (* (1+ (/ current sh-indentation)) sh-indentation))))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1583 (if (< (current-column) (current-indentation))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1584 (skip-chars-forward " \t"))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1585
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1586
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1587 (defun sh-execute-region (start end &optional flag)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1588 "Pass optional header and region to a subshell for noninteractive execution.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1589 The working directory is that of the buffer, and only environment variables
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1590 are already set which is why you can mark a header within the script.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1591
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1592 With a positive prefix ARG, instead of sending region, define header from
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1593 beginning of buffer to point. With a negative prefix ARG, instead of sending
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1594 region, clear header."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1595 (interactive "r\nP")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1596 (if flag
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1597 (setq sh-header-marker (if (> (prefix-numeric-value flag) 0)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1598 (point-marker)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1599 (if sh-header-marker
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1600 (save-excursion
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1601 (let (buffer-undo-list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1602 (goto-char sh-header-marker)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1603 (append-to-buffer (current-buffer) start end)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1604 (shell-command-on-region (point-min)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1605 (setq end (+ sh-header-marker
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1606 (- end start)))
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1607 sh-shell-file)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1608 (delete-region sh-header-marker end)))
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1609 (shell-command-on-region start end (concat sh-shell-file " -")))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1610
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1611
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1612 (defun sh-remember-variable (var)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1613 "Make VARIABLE available for future completing reads in this buffer."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1614 (or (< (length var) sh-remember-variable-min)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1615 (getenv var)
14195
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
1616 (assoc var sh-shell-variables)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1617 (push (cons var var) sh-shell-variables))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1618 var)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1619
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1620
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1621
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1622 (defun sh-quoted-p ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1623 "Is point preceded by an odd number of backslashes?"
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1624 (eq -1 (% (save-excursion (skip-chars-backward "\\\\")) 2)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1625
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1626 ;; Indentation stuff.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1627 (defun sh-must-be-shell-mode ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1628 "Signal an error if not in Shell-script mode."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1629 (unless (eq major-mode 'sh-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1630 (error "This buffer is not in Shell-script mode")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1631
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1632 (defun sh-must-support-indent ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1633 "*Signal an error if the shell type for this buffer is not supported.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1634 Also, the buffer must be in Shell-script mode."
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1635 (sh-must-be-shell-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1636 (unless sh-indent-supported-here
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1637 (error "This buffer's shell type is not supported for this command")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1638
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1639 (defun sh-make-vars-local ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1640 "Make the indentation variables local to this buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1641 Normally they already are local. This command is provided in case
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1642 variable `sh-make-vars-local' has been set to nil.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1643
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1644 To revert all these variables to the global values, use
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1645 command `sh-reset-indent-vars-to-global-values'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1646 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1647 (sh-must-be-shell-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1648 (mapcar 'make-local-variable sh-var-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1649 (message "Indentation variable are now local."))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1650
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1651 (defun sh-reset-indent-vars-to-global-values ()
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1652 "Reset local indentation variables to the global values.
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1653 Then, if variable `sh-make-vars-local' is non-nil, make them local."
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1654 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1655 (sh-must-be-shell-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1656 (mapcar 'kill-local-variable sh-var-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1657 (if sh-make-vars-local
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1658 (mapcar 'make-local-variable sh-var-list)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1659
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1660
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1661 ;; Theoretically these are only needed in shell and derived modes.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1662 ;; However, the routines which use them are only called in those modes.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1663 (defconst sh-special-keywords "then\\|do")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1664
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1665 (defun sh-help-string-for-variable (var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1666 "Construct a string for `sh-read-variable' when changing variable VAR ."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1667 (let ((msg (documentation-property var 'variable-documentation))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1668 (msg2 ""))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1669 (unless (memq var '(sh-first-lines-indent sh-indent-comment))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1670 (setq msg2
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1671 (format "\n
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1672 You can enter a number (positive to increase indentation,
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1673 negative to decrease indentation, zero for no change to indentation).
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1674
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1675 Or, you can enter one of the following symbols which are relative to
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1676 the value of variable `sh-basic-offset'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1677 which in this buffer is currently %s.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1678
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1679 \t%s."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1680 sh-basic-offset
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1681 (mapconcat (lambda (x)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1682 (nth (1- (length x)) x))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1683 sh-symbol-list "\n\t"))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1684 (concat
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1685 ;; The following shows the global not the local value!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1686 ;; (format "Current value of %s is %s\n\n" var (symbol-value var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1687 msg msg2)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1688
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1689 (defun sh-read-variable (var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1690 "Read a new value for indentation variable VAR."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1691 (interactive "*variable? ") ;; to test
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1692 (let ((minibuffer-help-form `(sh-help-string-for-variable
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1693 (quote ,var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1694 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1695 (setq val (read-from-minibuffer
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1696 (format "New value for %s (press %s for help): "
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1697 var (single-key-description help-char))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1698 (format "%s" (symbol-value var))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1699 nil t))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1700 val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1701
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1702
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1703
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1704 (defun sh-in-comment-or-string (start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1705 "Return non-nil if START is in a comment or string."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1706 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1707 (let (state)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1708 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1709 (setq state (parse-partial-sexp (point) start nil nil nil t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1710 (or (nth 3 state)(nth 4 state)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1711
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1712 (defun sh-goto-matching-if ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1713 "Go to the matching if for a fi.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1714 This handles nested if..fi pairs."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1715 (let ((found (sh-find-prev-matching "\\bif\\b" "\\bfi\\b" 1)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1716 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1717 (goto-char found))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1718
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1719
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1720 ;; Functions named sh-handle-this-XXX are called when the keyword on the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1721 ;; line whose indentation is being handled contain XXX;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1722 ;; those named sh-handle-prev-XXX are when XXX appears on the previous line.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1723
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1724 (defun sh-handle-prev-if ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1725 (list '(+ sh-indent-after-if)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1726
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1727 (defun sh-handle-this-else ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1728 (if (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1729 ;; (list "aligned to if")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1730 (list "aligned to if" '(+ sh-indent-for-else))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1731 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1732 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1733
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1734 (defun sh-handle-prev-else ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1735 (if (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1736 (list '(+ sh-indent-after-if))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1737 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1738
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1739 (defun sh-handle-this-fi ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1740 (if (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1741 (list "aligned to if" '(+ sh-indent-for-fi))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1742 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1743 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1744
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1745 (defun sh-handle-prev-fi ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1746 ;; Why do we have this rule? Because we must go back to the if
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1747 ;; to get its indent. We may continue back from there.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1748 ;; We return nil because we don't have anything to add to result,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1749 ;; the side affect of setting align-point is all that matters.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1750 ;; we could return a comment (a string) but I can't think of a good one...
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1751 (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1752 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1753
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1754 (defun sh-handle-this-then ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1755 (let ((p (sh-goto-matching-if)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1756 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1757 (list '(+ sh-indent-for-then))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1758 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1759
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1760 (defun sh-handle-prev-then ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1761 (let ((p (sh-goto-matching-if)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1762 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1763 (list '(+ sh-indent-after-if))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1764 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1765
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1766 (defun sh-handle-prev-open ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1767 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1768 (let ((x (sh-prev-stmt)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1769 (if (and x
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1770 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1771 (goto-char x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1772 (or
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1773 (looking-at "function\\b")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1774 (looking-at "\\s-*\\S-+\\s-*()")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1775 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1776 (list '(+ sh-indent-after-function))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1777 (list '(+ sh-indent-after-open)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1778 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1779
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1780 (defun sh-handle-this-close ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1781 (forward-char 1) ;; move over ")"
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1782 (if (sh-safe-forward-sexp -1)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1783 (list "aligned to opening paren")))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1784
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1785 (defun sh-goto-matching-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1786 (let ((found (sh-find-prev-matching "\\bcase\\b" "\\besac\\b" 1)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1787 (if found (goto-char found))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1788
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1789 (defun sh-handle-prev-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1790 ;; This is typically called when point is on same line as a case
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1791 ;; we shouldn't -- and can't find prev-case
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1792 (if (looking-at ".*\\<case\\>")
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1793 (list '(+ sh-indent-for-case-label))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1794 (error "We don't seem to be on a line with a case"))) ;; debug
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1795
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1796 (defun sh-handle-this-esac ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1797 (if (sh-goto-matching-case)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1798 (list "aligned to matching case")))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1799
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1800 (defun sh-handle-prev-esac ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1801 (if (sh-goto-matching-case)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1802 (list "matching case")))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1803
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1804 (defun sh-handle-after-case-label ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1805 (if (sh-goto-matching-case)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1806 (list '(+ sh-indent-for-case-alt))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1807
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1808 (defun sh-handle-prev-case-alt-end ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1809 (if (sh-goto-matching-case)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1810 (list '(+ sh-indent-for-case-label))))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1811
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1812 (defun sh-safe-forward-sexp (&optional arg)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1813 "Try and do a `forward-sexp', but do not error.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1814 Return new point if successful, nil if an error occurred."
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1815 (condition-case nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1816 (progn
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1817 (forward-sexp (or arg 1))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1818 (point)) ;; return point if successful
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1819 (error
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1820 (sh-debug "oops!(1) %d" (point))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1821 nil))) ;; return nil if fail
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1822
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1823 (defun sh-goto-match-for-done ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1824 (let ((found (sh-find-prev-matching sh-regexp-for-done sh-re-done 1)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1825 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1826 (goto-char found))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1827
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1828 (defun sh-handle-this-done ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1829 (if (sh-goto-match-for-done)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1830 (list "aligned to do stmt" '(+ sh-indent-for-done))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1831
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1832 (defun sh-handle-prev-done ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1833 (if (sh-goto-match-for-done)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1834 (list "previous done")))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1835
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1836 (defun sh-handle-this-do ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1837 (if (sh-goto-match-for-done)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1838 (list '(+ sh-indent-for-do))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1839
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1840 (defun sh-handle-prev-do ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1841 (cond
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1842 ((save-restriction
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1843 (narrow-to-region
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1844 (point)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1845 (save-excursion
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1846 (beginning-of-line)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1847 (point)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1848 (sh-goto-match-for-done))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1849 (sh-debug "match for done found on THIS line")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1850 (list '(+ sh-indent-after-loop-construct)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1851 ((sh-goto-match-for-done)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1852 (sh-debug "match for done found on PREV line")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1853 (list '(+ sh-indent-after-do)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1854 (t
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1855 (message "match for done NOT found")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1856 nil)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1857
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1858 ;; for rc:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1859 (defun sh-find-prev-switch ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1860 "Find the line for the switch keyword matching this line's case keyword."
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1861 (re-search-backward "\\<switch\\>" nil t))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1862
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1863 (defun sh-handle-this-rc-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1864 (if (sh-find-prev-switch)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1865 (list '(+ sh-indent-after-switch))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1866 ;; (list '(+ sh-indent-for-case-label))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1867 nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1868
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1869 (defun sh-handle-prev-rc-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1870 (list '(+ sh-indent-after-case)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1871
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1872 (defun sh-check-rule (n thing)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1873 (let ((rule (nth n (assoc thing sh-kw-alist)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1874 (val nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1875 (if rule
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1876 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1877 (setq val (funcall rule))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1878 (sh-debug "rule (%d) for %s at %d is %s\n-> returned %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1879 n thing (point) rule val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1880 val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1881
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1882
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1883 (defun sh-get-indent-info ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1884 "Return indent-info for this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1885 This is a list. nil means the line is to be left as is.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1886 Otherwise it contains one or more of the following sublists:
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1887 \(t NUMBER\) NUMBER is the base location in the buffer that indentation is
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1888 relative to. If present, this is always the first of the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1889 sublists. The indentation of the line in question is
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1890 derived from the indentation of this point, possibly
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1891 modified by subsequent sublists.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1892 \(+ VAR\)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1893 \(- VAR\) Get the value of variable VAR and add to or subtract from
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1894 the indentation calculated so far.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1895 \(= VAR\) Get the value of variable VAR and *replace* the
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1896 indentation with its value. This only occurs for
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1897 special variables such as `sh-indent-comment'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1898 STRING This is ignored for the purposes of calculating
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1899 indentation, it is printed in certain cases to help show
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1900 what the indentation is based on."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1901 ;; See comments before `sh-kw'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1902 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1903 (let ((prev-kw nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1904 (prev-stmt nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1905 (have-result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1906 depth-bol depth-eol
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1907 this-kw
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1908 (state nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1909 state-bol
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1910 (depth-prev-bol nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1911 start
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1912 func val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1913 (result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1914 prev-lines-indent
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1915 (prev-list nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1916 (this-list nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1917 (align-point nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1918 prev-line-end x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1919 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1920 ;; Note: setting result to t means we are done and will return nil.
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1921 ;;(This function never returns just t.)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1922 (cond
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1923 ((and (boundp 'font-lock-string-face)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1924 (equal (get-text-property (point) 'face) font-lock-string-face))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1925 (setq result t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1926 (setq have-result t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1927 ((looking-at "\\s-*#") ; was (equal this-kw "#")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1928 (if (bobp)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1929 (setq result t) ;; return nil if 1st line!
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1930 (setq result (list '(= sh-indent-comment)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1931 ;; we still need to get previous line in case
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1932 ;; sh-indent-comment is t (indent as normal)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1933 (setq align-point (sh-prev-line nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1934 (setq have-result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1935 ))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1936 ) ;; cond
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1937
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1938 (unless have-result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1939 ;; Continuation lines are handled specially
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1940 (if (sh-this-is-a-continuation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1941 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1942 ;; We assume the line being continued is already
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1943 ;; properly indented...
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1944 ;; (setq prev-line-end (sh-prev-line))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1945 (setq align-point (sh-prev-line nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1946 (setq result (list '(+ sh-indent-for-continuation)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1947 (setq have-result t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1948 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1949 (skip-chars-forward " \t")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1950 (setq this-kw (sh-get-kw)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1951
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1952 ;; Handle "this" keyword: first word on the line we're
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1953 ;; calculating indentation info for.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1954 (if this-kw
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1955 (if (setq val (sh-check-rule 1 this-kw))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1956 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1957 (setq align-point (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1958 (sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1959 "this - setting align-point to %d" align-point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1960 (setq result (append result val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1961 (setq have-result t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1962 ;; set prev-line to continue processing remainder
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1963 ;; of this line as a previous line
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1964 (setq prev-line-end (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1965 ))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1966
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1967 (unless have-result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1968 (setq prev-line-end (sh-prev-line 'end)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1969
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1970 (if prev-line-end
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1971 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1972 ;; We start off at beginning of this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1973 ;; Scan previous statements while this is <=
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1974 ;; start of previous line.
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1975 (setq start (point)) ;; for debug only
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1976 (goto-char prev-line-end)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1977 (setq x t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1978 (while (and x (setq x (sh-prev-thing)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1979 (sh-debug "at %d x is: %s result is: %s" (point) x result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1980 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1981 ((and (equal x ")")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1982 (equal (get-text-property (1- (point)) 'syntax-table)
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1983 sh-st-punc))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1984 (sh-debug "Case label) here")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1985 (setq x 'case-label)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1986 (if (setq val (sh-check-rule 2 x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1987 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1988 (setq result (append result val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1989 (setq align-point (point))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1990 (forward-char -1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1991 (skip-chars-forward "[a-z0-9]*?")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1992 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1993 ((string-match "[])}]" x)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1994 (setq x (sh-safe-forward-sexp -1))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1995 (if x
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1996 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1997 (setq align-point (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1998 (setq result (append result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1999 (list "aligned to opening paren")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2000 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2001 ((string-match "[[({]" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2002 (sh-debug "Checking special thing: %s" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2003 (if (setq val (sh-check-rule 2 x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2004 (setq result (append result val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2005 (forward-char -1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2006 (setq align-point (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2007 ((string-match "[\"'`]" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2008 (sh-debug "Skipping back for %s" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2009 ;; this was oops-2
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2010 (setq x (sh-safe-forward-sexp -1)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2011 ((stringp x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2012 (sh-debug "Checking string %s at %s" x (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2013 (if (setq val (sh-check-rule 2 x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2014 ;; (or (eq t (car val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2015 ;; (eq t (car (car val))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2016 (setq result (append result val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2017 ;; not sure about this test Wed Jan 27 23:48:35 1999
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2018 (setq align-point (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2019 (unless (bolp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2020 (forward-char -1)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2021 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2022 (error "Don't know what to do with %s" x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2023 )
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2024 ) ;; while
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2025 (sh-debug "result is %s" result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2026 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2027 (sh-debug "No prev line!")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2028 (sh-debug "result: %s align-point: %s" result align-point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2029 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2030
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2031 (if align-point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2032 ;; was: (setq result (append result (list (list t align-point))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2033 (setq result (append (list (list t align-point)) result))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2034 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2035 (sh-debug "result is now: %s" result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2036
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2037 (or result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2038 (if prev-line-end
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2039 (setq result (list (list t prev-line-end)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2040 (setq result (list (list '= 'sh-first-lines-indent)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2041 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2042
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2043 (if (eq result t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2044 (setq result nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2045 (sh-debug "result is: %s" result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2046 result
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2047 ) ;; let
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2048 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2049
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2050
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2051 (defun sh-get-indent-var-for-line (&optional info)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2052 "Return the variable controlling indentation for this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2053 If there is not [just] one such variable, return a string
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2054 indicating the problem.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2055 If INFO is supplied it is used, else it is calculated."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2056 (let ((var nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2057 (result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2058 (reason nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2059 sym elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2060 (or info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2061 (setq info (sh-get-indent-info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2062 (if (null info)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2063 (setq result "this line to be left as is")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2064 (while (and info (null result))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2065 (setq elt (car info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2066 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2067 ((stringp elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2068 (setq reason elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2069 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2070 ((not (listp elt))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2071 (error "sh-get-indent-var-for-line invalid elt: %s" elt))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2072 ;; so it is a list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2073 ((eq t (car elt))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2074 ) ;; nothing
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2075 ((symbolp (setq sym (nth 1 elt)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2076 ;; A bit of a kludge - when we see the sh-indent-comment
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2077 ;; ignore other variables. Otherwise it is tricky to
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2078 ;; "learn" the comment indentation.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2079 (if (eq var 'sh-indent-comment)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2080 (setq result var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2081 (if var
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2082 (setq result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2083 "this line is controlled by more than 1 variable.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2084 (setq var sym))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2085 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2086 (error "sh-get-indent-var-for-line invalid list elt: %s" elt)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2087 (setq info (cdr info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2088 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2089 (or result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2090 (setq result var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2091 (or result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2092 (setq result reason))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2093 (if (null result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2094 ;; e.g. just had (t POS)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2095 (setq result "line has default indentation"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2096 result))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2097
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2098
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2099
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2100 ;; Finding the previous line isn't trivial.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2101 ;; We must *always* go back one more and see if that is a continuation
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2102 ;; line -- it is the PREVIOUS line which is continued, not the one
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2103 ;; we are going to!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2104 ;; Also, we want to treat a whole "here document" as one big line,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2105 ;; because we may want to a align to the beginning of it.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2106 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2107 ;; What we do:
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2108 ;; - go back to previous non-empty line
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2109 ;; - if this is in a here-document, go to the beginning of it
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2110 ;; - while previous line is continued, go back one line
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2111 (defun sh-prev-line (&optional end)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2112 "Back to end of previous non-comment non-empty line.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2113 Go to beginning of logical line unless END is non-nil, in which case
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2114 we go to the end of the previous line and do not check for continuations."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2115 (sh-must-be-shell-mode)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2116 (save-excursion
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2117 (beginning-of-line)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2118 (forward-comment (- (point-max)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2119 (unless end (beginning-of-line))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2120 (when (and (not (bobp))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2121 (boundp 'font-lock-string-face)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2122 (equal (get-text-property (1- (point)) 'face)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2123 font-lock-string-face))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2124 (let ((p1 (previous-single-property-change (1- (point)) 'face)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2125 (when p1
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2126 (goto-char p1)
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2127 (if end
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2128 (end-of-line)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2129 (beginning-of-line)))))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2130 (unless end
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2131 ;; we must check previous lines to see if they are continuation lines
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2132 ;; if so, we must return position of first of them
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2133 (while (and (sh-this-is-a-continuation)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2134 (>= 0 (forward-line -1))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2135 (beginning-of-line)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2136 (skip-chars-forward " \t"))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2137 (point)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2138
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2139
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2140 (defun sh-prev-stmt ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2141 "Return the address of the previous stmt or nil."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2142 ;; This is used when we are trying to find a matching keyword.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2143 ;; Searching backward for the keyword would certainly be quicker, but
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2144 ;; it is hard to remove "false matches" -- such as if the keyword
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2145 ;; appears in a string or quote. This way is slower, but (I think) safer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2146 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2147 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2148 (let ((going t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2149 (start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2150 (found nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2151 (prev nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2152 (skip-chars-backward " \t;|&({[")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2153 (while (and (not found)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2154 (not (bobp))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2155 going)
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2156 ;; Do a backward-sexp if possible, else backup bit by bit...
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2157 (if (sh-safe-forward-sexp -1)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2158 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2159 (if (looking-at sh-special-keywords)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2160 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2161 (setq found prev))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2162 (setq prev (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2163 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2164 ;; backward-sexp failed
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2165 (if (zerop (skip-chars-backward " \t()[\]{};`'"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2166 (forward-char -1))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2167 (if (bolp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2168 (let ((back (sh-prev-line nil)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2169 (if back
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2170 (goto-char back)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2171 (setq going nil)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2172 (unless found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2173 (skip-chars-backward " \t")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2174 (if (or (and (bolp) (not (sh-this-is-a-continuation)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2175 (eq (char-before) ?\;)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2176 (looking-at "\\s-*[|&]"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2177 (setq found (point)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2178 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2179 (goto-char found))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2180 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2181 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2182 (skip-chars-forward " \t|&({[")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2183 (setq found (point))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2184 (if (>= (point) start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2185 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2186 (debug "We didn't move!")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2187 (setq found nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2188 (or found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2189 (sh-debug "Did not find prev stmt.")))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2190 found)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2191
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2192
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2193 (defun sh-get-word ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2194 "Get a shell word skipping whitespace from point."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2195 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2196 (skip-chars-forward "\t ")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2197 (let ((start (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2198 (while
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2199 (if (looking-at "[\"'`]")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2200 (sh-safe-forward-sexp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2201 ;; (> (skip-chars-forward "^ \t\n\"'`") 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2202 (> (skip-chars-forward "-_a-zA-Z\$0-9") 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2203 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2204 (buffer-substring start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2205 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2206
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2207 (defun sh-prev-thing ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2208 "Return the previous thing this logical line."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2209 ;; This is called when `sh-get-indent-info' is working backwards on
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2210 ;; the previous line(s) finding what keywords may be relevant for
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2211 ;; indenting. It moves over sexps if possible, and will stop
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2212 ;; on a ; and at the beginning of a line if it is not a continuation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2213 ;; line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2214 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2215 ;; Added a kludge for ";;"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2216 ;; Possible return values:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2217 ;; nil - nothing
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2218 ;; a string - possibly a keyword
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2219 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2220 (if (bolp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2221 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2222 (let ((going t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2223 c n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2224 min-point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2225 (start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2226 (found nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2227 (save-restriction
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2228 (narrow-to-region
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2229 (if (sh-this-is-a-continuation)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2230 (setq min-point (sh-prev-line nil))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2231 (save-excursion
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2232 (beginning-of-line)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2233 (setq min-point (point))))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2234 (point))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2235 (skip-chars-backward " \t;")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2236 (unless (looking-at "\\s-*;;")
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2237 (skip-chars-backward "^)}];\"'`({[")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2238 (setq c (char-before))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2239 (sh-debug "stopping at %d c is %s start=%d min-point=%d"
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2240 (point) c start min-point)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2241 (if (< (point) min-point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2242 (error "point %d < min-point %d" (point) min-point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2243 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2244 ((looking-at "\\s-*;;")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2245 ;; (message "Found ;; !")
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2246 ";;")
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2247 ((or (eq c ?\n)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2248 (eq c nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2249 (eq c ?\;))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2250 (save-excursion
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2251 ;; skip forward over white space newline and \ at eol
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2252 (skip-chars-forward " \t\n\\\\")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2253 (sh-debug "Now at %d start=%d" (point) start)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2254 (if (>= (point) start)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2255 (progn
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2256 (sh-debug "point: %d >= start: %d" (point) start)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2257 nil)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2258 (sh-get-word))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2259 ))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2260 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2261 ;; c -- return a string
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2262 (char-to-string c)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2263 ))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2264 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2265
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2266
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2267 (defun sh-this-is-a-continuation ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2268 "Return non-nil if current line is a continuation of previous line."
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2269 (save-excursion
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2270 (and (zerop (forward-line -1))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2271 (looking-at ".*\\\\$")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2272 (not (nth 4 (parse-partial-sexp (match-beginning 0) (match-end 0)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2273 nil nil nil t))))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2274
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2275 (defun sh-get-kw (&optional where and-move)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2276 "Return first word of line from WHERE.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2277 If AND-MOVE is non-nil then move to end of word."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2278 (let ((start (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2279 (if where
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2280 (goto-char where))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2281 (prog1
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2282 (buffer-substring (point)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2283 (progn (skip-chars-forward "^ \t\n;")(point)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2284 (unless and-move
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2285 (goto-char start)))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2286
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2287 (defun sh-find-prev-matching (open close &optional depth)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2288 "Find a matching token for a set of opening and closing keywords.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2289 This takes into account that there may be nested open..close pairings.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2290 OPEN and CLOSE are regexps denoting the tokens to be matched.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2291 Optional parameter DEPTH (usually 1) says how many to look for."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2292 (let ((parse-sexp-ignore-comments t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2293 prev)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2294 (setq depth (or depth 1))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2295 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2296 (condition-case nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2297 (while (and
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2298 (/= 0 depth)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2299 (not (bobp))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2300 (setq prev (sh-prev-stmt)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2301 (goto-char prev)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2302 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2303 (if (looking-at "\\\\\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2304 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2305 (forward-char 2)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2306 (skip-chars-forward " \t")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2307 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2308 ((looking-at open)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2309 (setq depth (1- depth))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2310 (sh-debug "found open at %d - depth = %d" (point) depth))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2311 ((looking-at close)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2312 (setq depth (1+ depth))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2313 (sh-debug "found close - depth = %d" depth))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2314 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2315 ))))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2316 (error nil))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2317 (if (eq depth 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2318 prev ;; (point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2319 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2320 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2321
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2322
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2323 (defun sh-var-value (var &optional ignore-error)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2324 "Return the value of variable VAR, interpreting symbols.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2325 It can also return t or nil.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2326 If an illegal value is found, throw an error unless Optional argument
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2327 IGNORE-ERROR is non-nil."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2328 (let ((val (symbol-value var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2329 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2330 ((numberp val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2331 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2332 ((eq val t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2333 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2334 ((null val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2335 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2336 ((eq val '+)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2337 sh-basic-offset)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2338 ((eq val '-)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2339 (- sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2340 ((eq val '++)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2341 (* 2 sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2342 ((eq val '--)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2343 (* 2 (- sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2344 ((eq val '*)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2345 (/ sh-basic-offset 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2346 ((eq val '/)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2347 (/ (- sh-basic-offset) 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2348 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2349 (if ignore-error
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2350 (progn
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2351 (message "Don't know how to handle %s's value of %s" var val)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2352 0)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2353 (error "Don't know how to handle %s's value of %s" var val))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2354 ))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2355
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2356 (defun sh-set-var-value (var value &optional no-symbol)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2357 "Set variable VAR to VALUE.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2358 Unless optional argument NO-SYMBOL is non-nil, then if VALUE is
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2359 can be represented by a symbol then do so."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2360 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2361 (no-symbol
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2362 (set var value))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2363 ((= value sh-basic-offset)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2364 (set var '+))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2365 ((= value (- sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2366 (set var '-))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2367 ((eq value (* 2 sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2368 (set var '++))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2369 ((eq value (* 2 (- sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2370 (set var '--))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2371 ((eq value (/ sh-basic-offset 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2372 (set var '*))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2373 ((eq value (/ (- sh-basic-offset) 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2374 (set var '/))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2375 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2376 (set var value)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2377 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2378
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2379
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2380 (defun sh-calculate-indent (&optional info)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2381 "Return the indentation for the current line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2382 If INFO is supplied it is used, else it is calculated from current line."
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2383 (let ((ofs 0)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2384 (base-value 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2385 elt a b var val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2386 (or info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2387 (setq info (sh-get-indent-info)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2388 (when info
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2389 (while info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2390 (sh-debug "info: %s ofs=%s" info ofs)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2391 (setq elt (car info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2392 (cond
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2393 ((stringp elt)) ;; do nothing?
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2394 ((listp elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2395 (setq a (car (car info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2396 (setq b (nth 1 (car info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2397 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2398 ((eq a t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2399 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2400 (goto-char b)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2401 (setq val (current-indentation)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2402 (setq base-value val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2403 ((symbolp b)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2404 (setq val (sh-var-value b))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2405 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2406 ((eq a '=)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2407 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2408 ((null val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2409 ;; no indentation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2410 ;; set info to nil so we stop immediately
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2411 (setq base-value nil ofs nil info nil))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2412 ((eq val t) (setq ofs 0)) ;; indent as normal line
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2413 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2414 ;; The following assume the (t POS) come first!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2415 (setq ofs val base-value 0)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2416 (setq info nil)))) ;; ? stop now
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2417 ((eq a '+) (setq ofs (+ ofs val)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2418 ((eq a '-) (setq ofs (- ofs val)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2419 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2420 (error "sh-calculate-indent invalid a a=%s b=%s" a b))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2421 (t
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2422 (error "sh-calculate-indent invalid elt: a=%s b=%s" a b))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2423 (t
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2424 (error "sh-calculate-indent invalid elt %s" elt)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2425 (sh-debug "a=%s b=%s val=%s base-value=%s ofs=%s"
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2426 a b val base-value ofs)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2427 (setq info (cdr info)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2428 ;; return value:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2429 (sh-debug "at end: base-value: %s ofs: %s" base-value ofs)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2430
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2431 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2432 ((or (null base-value)(null ofs))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2433 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2434 ((and (numberp base-value)(numberp ofs))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2435 (sh-debug "base (%d) + ofs (%d) = %d"
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2436 base-value ofs (+ base-value ofs))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2437 (+ base-value ofs)) ;; return value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2438 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2439 (error "sh-calculate-indent: Help. base-value=%s ofs=%s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2440 base-value ofs)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2441 nil)))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2442
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2443
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2444 (defun sh-indent-line ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2445 "Indent the current line."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2446 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2447 (sh-must-be-shell-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2448 (let ((indent (sh-calculate-indent)) shift-amt beg end
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2449 (pos (- (point-max) (point))))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2450 (when indent
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2451 (beginning-of-line)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2452 (setq beg (point))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2453 (skip-chars-forward " \t")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2454 (setq shift-amt (- indent (current-column)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2455 (unless (zerop shift-amt)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2456 (delete-region beg (point))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2457 (indent-to indent))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2458 ;; If initial point was within line's indentation,
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2459 ;; position after the indentation. Else stay at same point in text.
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2460 (if (> (- (point-max) pos) (point))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2461 (goto-char (- (point-max) pos))))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2462
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2463
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2464 (defun sh-blink (blinkpos &optional msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2465 "Move cursor momentarily to BLINKPOS and display MSG."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2466 ;; We can get here without it being a number on first line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2467 (if (numberp blinkpos)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2468 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2469 (goto-char blinkpos)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2470 (message msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2471 (sit-for blink-matching-delay))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2472 (message msg)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2473
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2474 (defun sh-show-indent (arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2475 "Show the how the currently line would be indented.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2476 This tells you which variable, if any, controls the indentation of
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2477 this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2478 If optional arg ARG is non-null (called interactively with a prefix),
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2479 a pop up window describes this variable.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2480 If variable `sh-blink' is non-nil then momentarily go to the line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2481 we are indenting relative to, if applicable."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2482 (interactive "P")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2483 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2484 (let* ((info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2485 (var (sh-get-indent-var-for-line info))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2486 (curr-indent (current-indentation))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2487 val msg)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2488 (if (stringp var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2489 (message (setq msg var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2490 (setq val (sh-calculate-indent info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2491
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2492 (if (eq curr-indent val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2493 (setq msg (format "%s is %s" var (symbol-value var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2494 (setq msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2495 (if val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2496 (format "%s (%s) would change indent from %d to: %d"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2497 var (symbol-value var) curr-indent val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2498 (format "%s (%s) would leave line as is"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2499 var (symbol-value var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2500 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2501 (if (and arg var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2502 (describe-variable var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2503 (if sh-blink
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2504 (let ((info (sh-get-indent-info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2505 (if (and info (listp (car info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2506 (eq (car (car info)) t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2507 (sh-blink (nth 1 (car info)) msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2508 (message msg)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2509 (message msg))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2510 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2511
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2512 (defun sh-set-indent ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2513 "Set the indentation for the current line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2514 If the current line is controlled by an indentation variable, prompt
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2515 for a new value for it."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2516 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2517 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2518 (let* ((info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2519 (var (sh-get-indent-var-for-line info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2520 val val0 new-val old-val indent-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2521 (if (stringp var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2522 (message (format "Cannot set indent - %s" var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2523 (setq old-val (symbol-value var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2524 (setq val (sh-read-variable var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2525 (condition-case nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2526 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2527 (set var val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2528 (setq indent-val (sh-calculate-indent info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2529 (if indent-val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2530 (message "Variable: %s Value: %s would indent to: %d"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2531 var (symbol-value var) indent-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2532 (message "Variable: %s Value: %s would leave line as is."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2533 var (symbol-value var)))
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2534 ;; I'm not sure about this, indenting it now?
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2535 ;; No. Because it would give the impression that an undo would
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2536 ;; restore thing, but the value has been altered.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2537 ;; (sh-indent-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2538 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2539 (error
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2540 (set var old-val)
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2541 (message "Bad value for %s, restoring to previous value %s"
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2542 var old-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2543 (sit-for 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2544 nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2545 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2546
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2547
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2548 (defun sh-learn-line-indent (arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2549 "Learn how to indent a line as it currently is indented.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2550
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2551 If there is an indentation variable which controls this line's indentation,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2552 then set it to a value which would indent the line the way it
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2553 presently is.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2554
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2555 If the value can be represented by one of the symbols then do so
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2556 unless optional argument ARG (the prefix when interactive) is non-nil."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2557 (interactive "*P")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2558 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2559 ;; I'm not sure if we show allow learning on an empty line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2560 ;; Though it might occasionally be useful I think it usually
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2561 ;; would just be confusing.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2562 (if (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2563 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2564 (looking-at "\\s-*$"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2565 (message "sh-learn-line-indent ignores empty lines.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2566 (let* ((info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2567 (var (sh-get-indent-var-for-line info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2568 ival sval diff new-val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2569 (no-symbol arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2570 (curr-indent (current-indentation)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2571 (cond
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2572 ((stringp var)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2573 (message (format "Cannot learn line - %s" var)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2574 ((eq var 'sh-indent-comment)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2575 ;; This is arbitrary...
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2576 ;; - if curr-indent is 0, set to curr-indent
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2577 ;; - else if it has the indentation of a "normal" line,
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2578 ;; then set to t
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2579 ;; - else set to curr-indent.
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2580 (setq sh-indent-comment
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2581 (if (= curr-indent 0)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2582 0
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2583 (let* ((sh-indent-comment t)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2584 (val2 (sh-calculate-indent info)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2585 (if (= val2 curr-indent)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2586 t
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2587 curr-indent))))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2588 (message "%s set to %s" var (symbol-value var))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2589 )
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2590 ((numberp (setq sval (sh-var-value var)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2591 (setq ival (sh-calculate-indent info))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2592 (setq diff (- curr-indent ival))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2593
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2594 (sh-debug "curr-indent: %d ival: %d diff: %d var:%s sval %s"
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2595 curr-indent ival diff var sval)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2596 (setq new-val (+ sval diff))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2597 ;;; I commented out this because someone might want to replace
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2598 ;;; a value of `+' with the current value of sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2599 ;;; or vice-versa.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2600 ;;; (if (= 0 diff)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2601 ;;; (message "No change needed!")
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2602 (sh-set-var-value var new-val no-symbol)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2603 (message "%s set to %s" var (symbol-value var))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2604 )
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2605 (t
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2606 (debug)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2607 (message "Cannot change %s" var))))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2608
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2609
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2610
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2611 (defun sh-mark-init (buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2612 "Initialize a BUFFER to be used by `sh-mark-line'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2613 (let ((main-buffer (current-buffer)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2614 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2615 (set-buffer (get-buffer-create buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2616 (erase-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2617 (occur-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2618 (setq occur-buffer main-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2619 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2620
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2621
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2622 (defun sh-mark-line (message point buffer &optional add-linenum occur-point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2623 "Insert MESSAGE referring to location POINT in current buffer into BUFFER.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2624 Buffer BUFFER is in `occur-mode'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2625 If ADD-LINENUM is non-nil the message is preceded by the line number.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2626 If OCCUR-POINT is non-nil then the line is marked as a new occurrence
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2627 so that `occur-next' and `occur-prev' will work."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2628 (let ((m1 (make-marker))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2629 (main-buffer (current-buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2630 start
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2631 (line ""))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2632 (when point
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2633 (set-marker m1 point (current-buffer))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2634 (if add-linenum
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2635 (setq line (format "%d: " (1+ (count-lines 1 point))))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2636 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2637 (if (get-buffer buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2638 (set-buffer (get-buffer buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2639 (set-buffer (get-buffer-create buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2640 (occur-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2641 (setq occur-buffer main-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2642 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2643 (goto-char (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2644 (setq start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2645 (insert line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2646 (if occur-point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2647 (setq occur-point (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2648 (insert message)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2649 (if point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2650 (put-text-property start (point) 'mouse-face 'highlight))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2651 (insert "\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2652 (if point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2653 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2654 (put-text-property start (point) 'occur m1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2655 (if occur-point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2656 (put-text-property occur-point (1+ occur-point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2657 'occur-point t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2658 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2659 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2660
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2661
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2662
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2663 ;; Is this really worth having?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2664 (defvar sh-learned-buffer-hook nil
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2665 "*An abnormal hook, called with an alist of learned variables.")
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2666 ;;; Example of how to use sh-learned-buffer-hook
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2667 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2668 ;; (defun what-i-learned (list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2669 ;; (let ((p list))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2670 ;; (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2671 ;; (set-buffer "*scratch*")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2672 ;; (goto-char (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2673 ;; (insert "(setq\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2674 ;; (while p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2675 ;; (insert (format " %s %s \n"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2676 ;; (nth 0 (car p)) (nth 1 (car p))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2677 ;; (setq p (cdr p)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2678 ;; (insert ")\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2679 ;; )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2680 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2681 ;; (add-hook 'sh-learned-buffer-hook 'what-i-learned)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2682
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2683
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2684 ;; Originally this was sh-learn-region-indent (beg end)
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2685 ;; However, in practice this was awkward so I changed it to
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2686 ;; use the whole buffer. Use narrowing if needbe.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2687 (defun sh-learn-buffer-indent (&optional arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2688 "Learn how to indent the buffer the way it currently is.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2689
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2690 Output in buffer \"*indent*\" shows any lines which have conflicting
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2691 values of a variable, and the final value of all variables learned.
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2692 This buffer is popped to automatically if there are any discrepancies.
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2693
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2694 If no prefix ARG is given, then variables are set to numbers.
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2695 If a prefix arg is given, then variables are set to symbols when
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2696 applicable -- e.g. to symbol `+' if the value is that of the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2697 basic indent.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2698 If a positive numerical prefix is given, then `sh-basic-offset'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2699 is set to the prefix's numerical value.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2700 Otherwise, sh-basic-offset may or may not be changed, according
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2701 to the value of variable `sh-learn-basic-offset'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2702
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2703 Abnormal hook `sh-learned-buffer-hook' if non-nil is called when the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2704 function completes. The function is abnormal because it is called
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2705 with an alist of variables learned. This feature may be changed or
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2706 removed in the future.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2707
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2708 This command can often take a long time to run."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2709 (interactive "P")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2710 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2711 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2712 (goto-char (point-min))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2713 (let ((learned-var-list nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2714 (out-buffer "*indent*")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2715 (num-diffs 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2716 last-pos
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2717 previous-set-info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2718 (max 17)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2719 vec
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2720 msg
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2721 (comment-col nil) ;; number if all same, t if seen diff values
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2722 (comments-always-default t) ;; nil if we see one not default
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2723 initial-msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2724 (specified-basic-offset (and arg (numberp arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2725 (> arg 0)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2726 (linenum 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2727 suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2728 (setq vec (make-vector max 0))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2729 (sh-mark-init out-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2730
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2731 (if specified-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2732 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2733 (setq sh-basic-offset arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2734 (setq initial-msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2735 (format "Using specified sh-basic-offset of %d"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2736 sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2737 (setq initial-msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2738 (format "Initial value of sh-basic-offset: %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2739 sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2740
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2741 (while (< (point) (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2742 (setq linenum (1+ linenum))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2743 ;; (if (zerop (% linenum 10))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2744 (message "line %d" linenum)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2745 ;; )
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2746 (unless (looking-at "\\s-*$") ;; ignore empty lines!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2747 (let* ((sh-indent-comment t) ;; info must return default indent
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2748 (info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2749 (var (sh-get-indent-var-for-line info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2750 sval ival diff new-val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2751 (curr-indent (current-indentation)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2752 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2753 ((null var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2754 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2755 ((stringp var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2756 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2757 ((numberp (setq sval (sh-var-value var 'no-error)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2758 ;; the numberp excludes comments since sval will be t.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2759 (setq ival (sh-calculate-indent))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2760 (setq diff (- curr-indent ival))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2761 (setq new-val (+ sval diff))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2762 (sh-set-var-value var new-val 'no-symbol)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2763 (unless (looking-at "\\s-*#") ;; don't learn from comments
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2764 (if (setq previous-set-info (assoc var learned-var-list))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2765 (progn
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2766 ;; it was already there, is it same value ?
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2767 (unless (eq (symbol-value var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2768 (nth 1 previous-set-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2769 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2770 (format "Variable %s was set to %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2771 var (symbol-value var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2772 (point) out-buffer t t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2773 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2774 (format " but was previously set to %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2775 (nth 1 previous-set-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2776 (nth 2 previous-set-info) out-buffer t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2777 (setq num-diffs (1+ num-diffs))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2778 ;; (delete previous-set-info learned-var-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2779 (setcdr previous-set-info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2780 (list (symbol-value var) (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2781 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2782 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2783 (setq learned-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2784 (append (list (list var (symbol-value var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2785 (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2786 learned-var-list)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2787 (if (numberp new-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2788 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2789 (sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2790 "This line's indent value: %d" new-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2791 (if (< new-val 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2792 (setq new-val (- new-val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2793 (if (< new-val max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2794 (aset vec new-val (1+ (aref vec new-val))))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2795 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2796 ((eq var 'sh-indent-comment)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2797 (unless (= curr-indent (sh-calculate-indent info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2798 ;; this is not the default indentation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2799 (setq comments-always-default nil)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2800 (if comment-col ;; then we have see one before
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2801 (or (eq comment-col curr-indent)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2802 (setq comment-col t)) ;; seen a different one
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2803 (setq comment-col curr-indent))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2804 ))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2805 (t
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2806 (sh-debug "Cannot learn this line!!!")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2807 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2808 (sh-debug
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2809 "at %s learned-var-list is %s" (point) learned-var-list)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2810 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2811 (forward-line 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2812 ) ;; while
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2813 (if sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2814 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2815 (setq msg (format
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2816 "comment-col = %s comments-always-default = %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2817 comment-col comments-always-default))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2818 ;; (message msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2819 (sh-mark-line msg nil out-buffer)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2820 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2821 ((eq comment-col 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2822 (setq msg "\nComments are all in 1st column.\n"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2823 (comments-always-default
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2824 (setq msg "\nComments follow default indentation.\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2825 (setq comment-col t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2826 ((numberp comment-col)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2827 (setq msg (format "\nComments are in col %d." comment-col)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2828 (t
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2829 (setq msg "\nComments seem to be mixed, leaving them as is.\n")
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2830 (setq comment-col nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2831 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2832 (sh-debug msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2833 (sh-mark-line msg nil out-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2834
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2835 (sh-mark-line initial-msg nil out-buffer t t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2836
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2837 (setq suggested (sh-guess-basic-offset vec))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2838
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2839 (if (and suggested (not specified-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2840 (let ((new-value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2841 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2842 ;; t => set it if we have a single value as a number
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2843 ((and (eq sh-learn-basic-offset t) (numberp suggested))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2844 suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2845 ;; other non-nil => set it if only one value was found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2846 (sh-learn-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2847 (if (numberp suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2848 suggested
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2849 (if (= (length suggested) 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2850 (car suggested))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2851 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2852 nil))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2853 (if new-value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2854 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2855 (setq learned-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2856 (append (list (list 'sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2857 (setq sh-basic-offset new-value)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2858 (point-max)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2859 learned-var-list))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2860 ;; Not sure if we need to put this line in, since
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2861 ;; it will appear in the "Learned variable settings".
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2862 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2863 (format "Changed sh-basic-offset to: %d" sh-basic-offset)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2864 nil out-buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2865 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2866 (if (listp suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2867 (format "Possible value(s) for sh-basic-offset: %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2868 (mapconcat 'int-to-string suggested " "))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2869 (format "Suggested sh-basic-offset: %d" suggested))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2870 nil out-buffer))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2871
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2872
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2873 (setq learned-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2874 (append (list (list 'sh-indent-comment comment-col (point-max)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2875 learned-var-list))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2876 (setq sh-indent-comment comment-col)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2877 (let ((name (buffer-name))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2878 (lines (if (and (eq (point-min) 1)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2879 (eq (point-max) (1+ (buffer-size))))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2880 ""
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2881 (format "lines %d to %d of "
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2882 (1+ (count-lines 1 (point-min)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2883 (1+ (count-lines 1 (point-max))))))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2884 )
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2885 (sh-mark-line "\nLearned variable settings:" nil out-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2886 (if arg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2887 ;; Set learned variables to symbolic rather than numeric
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2888 ;; values where possible.
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2889 (dolist (learned-var (reverse learned-var-list))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2890 (let ((var (car learned-var))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2891 (val (nth 1 learned-var)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2892 (when (and (not (eq var 'sh-basic-offset))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2893 (numberp val))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2894 (sh-set-var-value var val)))))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2895 (dolist (learned-var (reverse learned-var-list))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2896 (let ((var (car learned-var)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2897 (sh-mark-line (format " %s %s" var (symbol-value var))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2898 (nth 2 learned-var) out-buffer)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2899 (save-excursion
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2900 (set-buffer out-buffer)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2901 (goto-char (point-min))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2902 (insert
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2903 (format "Indentation values for buffer %s.\n" name)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2904 (format "%d indentation variable%s different values%s\n\n"
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2905 num-diffs
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2906 (if (= num-diffs 1)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2907 " has" "s have")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2908 (if (zerop num-diffs)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2909 "." ":"))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2910 )))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2911 ;; Are abnormal hooks considered bad form?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2912 (run-hook-with-args 'sh-learned-buffer-hook learned-var-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2913 (if (or sh-popup-occur-buffer (> num-diffs 0))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2914 (pop-to-buffer out-buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2915 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2916
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2917 (defun sh-guess-basic-offset (vec)
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2918 "See if we can determine a reasonable value for `sh-basic-offset'.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2919 This is experimental, heuristic and arbitrary!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2920 Argument VEC is a vector of information collected by
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2921 `sh-learn-buffer-indent'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2922 Return values:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2923 number - there appears to be a good single value
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2924 list of numbers - no obvious one, here is a list of one or more
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2925 reasonable choices
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2926 nil - we couldn't find a reasonable one."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2927 (let* ((max (1- (length vec)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2928 (i 1)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2929 (totals (make-vector max 0))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2930 (return nil)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2931 j)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2932 (while (< i max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2933 (aset totals i (+ (aref totals i) (* 4 (aref vec i))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2934 (setq j (/ i 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2935 (if (zerop (% i 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2936 (aset totals i (+ (aref totals i) (aref vec (/ i 2)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2937 (if (< (* i 2) max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2938 (aset totals i (+ (aref totals i) (aref vec (* i 2)))))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2939 (setq i (1+ i)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2940
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2941 (let ((x nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2942 (result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2943 tot sum p)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2944 (setq i 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2945 (while (< i max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2946 (if (/= (aref totals i) 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2947 (setq x (append x (list (cons i (aref totals i))))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2948 (setq i (1+ i)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2949
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2950 (setq x (sort x (lambda (a b) (> (cdr a) (cdr b)))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2951 (setq tot (apply '+ (append totals nil)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2952 (sh-debug (format "vec: %s\ntotals: %s\ntot: %d"
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2953 vec totals tot))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2954 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2955 ((zerop (length x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2956 (message "no values!")) ;; we return nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2957 ((= (length x) 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2958 (message "only value is %d" (car (car x)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2959 (setq result (car (car x)))) ;; return single value
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2960 ((> (cdr (car x)) (/ tot 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2961 ;; 1st is > 50%
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2962 (message "basic-offset is probably %d" (car (car x)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2963 (setq result (car (car x)))) ;; again, return a single value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2964 ((>= (cdr (car x)) (* 2 (cdr (car (cdr x)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2965 ;; 1st is >= 2 * 2nd
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2966 (message "basic-offset could be %d" (car (car x)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2967 (setq result (car (car x))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2968 ((>= (+ (cdr (car x))(cdr (car (cdr x)))) (/ tot 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2969 ;; 1st & 2nd together >= 50% - return a list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2970 (setq p x sum 0 result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2971 (while (and p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2972 (<= (setq sum (+ sum (cdr (car p)))) (/ tot 2)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2973 (setq result (append result (list (car (car p)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2974 (setq p (cdr p)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2975 (message "Possible choices for sh-basic-offset: %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2976 (mapconcat 'int-to-string result " ")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2977 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2978 (message "No obvious value for sh-basic-offset. Perhaps %d"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2979 (car (car x)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2980 ;; result is nil here
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2981 ))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2982 result)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2983
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2984 ;; ========================================================================
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2985
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2986 ;; Styles -- a quick and dirty way of saving the indentation settings.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2987
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2988 (defvar sh-styles-alist nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2989 "A list of all known shell indentation styles.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2990
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2991 (defun sh-name-style (name &optional confirm-overwrite)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2992 "Name the current indentation settings as a style called NAME.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2993 If this name exists, the command will prompt whether it should be
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2994 overwritten if
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2995 - - it was called interactively with a prefix argument, or
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2996 - - called non-interactively with optional CONFIRM-OVERWRITE non-nil."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2997 ;; (interactive "sName for this style: ")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2998 (interactive
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2999 (list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3000 (read-from-minibuffer "Name for this style? " )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3001 (not current-prefix-arg)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3002 (let ((slist (cons name
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3003 (mapcar (lambda (var) (cons var (symbol-value var)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3004 sh-var-list)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3005 (style (assoc name sh-styles-alist)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3006 (if style
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3007 (if (and confirm-overwrite
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3008 (not (y-or-n-p "This style exists. Overwrite it? ")))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3009 (message "Not changing style %s" name)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3010 (message "Updating style %s" name)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3011 (setcdr style (cdr slist)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3012 (message "Creating new style %s" name)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3013 (push slist sh-styles-alist))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3014
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3015 (defun sh-load-style (name)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3016 "Set shell indentation values for this buffer from those in style NAME."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3017 (interactive (list (completing-read
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3018 "Which style to use for this buffer? "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3019 sh-styles-alist nil t)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3020 (let ((sl (assoc name sh-styles-alist)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3021 (if (null sl)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3022 (error "sh-load-style - style %s not known" name)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3023 (dolist (var (cdr sl))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3024 (set (car var) (cdr var))))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3025
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3026 (defun sh-save-styles-to-buffer (buff)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3027 "Save all current styles in elisp to buffer BUFF.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3028 This is always added to the end of the buffer."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3029 (interactive (list
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3030 (read-from-minibuffer "Buffer to save styles in? " "*scratch*")))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3031 (with-current-buffer (get-buffer-create buff)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3032 (goto-char (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3033 (insert "\n")
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3034 (pp `(setq sh-styles-alist ',sh-styles-alist) (current-buffer))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3035
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3036
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3037
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3038 ;; statement syntax-commands for various shells
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3039
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3040 ;; You are welcome to add the syntax or even completely new statements as
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3041 ;; appropriate for your favorite shell.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3042
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3043 (define-skeleton sh-case
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3044 "Insert a case/switch statement. See `sh-feature'."
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3045 (csh "expression: "
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3046 "switch( " str " )" \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3047 > "case " (read-string "pattern: ") ?: \n
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3048 > _ \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3049 "breaksw" \n
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3050 ( "other pattern, %s: "
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3051 < "case " str ?: \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3052 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3053 "breaksw" \n)
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3054 < "default:" \n
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3055 > _ \n
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3056 resume:
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3057 < < "endsw")
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3058 (es)
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3059 (rc "expression: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3060 > "switch( " str " ) {" \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3061 > "case " (read-string "pattern: ") \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3062 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3063 ( "other pattern, %s: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3064 "case " str > \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3065 > _ \n)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3066 "case *" > \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3067 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3068 resume:
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3069 ?} > )
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3070 (sh "expression: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3071 > "case " str " in" \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3072 > (read-string "pattern: ")
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3073 (propertize ")" 'syntax-table sh-st-punc)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3074 \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3075 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3076 ";;" \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3077 ( "other pattern, %s: "
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3078 > str (propertize ")" 'syntax-table sh-st-punc) \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3079 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3080 ";;" \n)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3081 > "*" (propertize ")" 'syntax-table sh-st-punc) \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3082 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3083 resume:
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3084 "esac" > ))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3085
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3086 (define-skeleton sh-for
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3087 "Insert a for loop. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3088 (csh eval sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3089 1 ""
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3090 2 "foreach "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3091 4 " ( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3092 6 " )"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3093 15 '<
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3094 16 "end"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3095 )
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3096 (es eval sh-modify rc
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3097 4 " = ")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3098 (rc eval sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3099 2 "for( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3100 6 " ) {"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3101 15 ?} )
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3102 (sh "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3103 > "for " str " in " _ "; do" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3104 > _ | ?$ & (sh-remember-variable str) \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3105 "done" > ))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3106
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3107
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3108
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3109 (define-skeleton sh-indexed-loop
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3110 "Insert an indexed loop from 1 to n. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3111 (bash eval identity posix)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3112 (csh "Index variable: "
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3113 "@ " str " = 1" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3114 "while( $" str " <= " (read-string "upper limit: ") " )" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3115 > _ ?$ str \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3116 "@ " str "++" \n
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3117 < "end")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3118 (es eval sh-modify rc
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3119 4 " =")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3120 (ksh88 "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3121 > "integer " str "=0" \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3122 > "while (( ( " str " += 1 ) <= "
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3123 (read-string "upper limit: ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3124 " )); do" \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3125 > _ ?$ (sh-remember-variable str) > \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3126 "done" > )
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3127 (posix "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3128 > str "=1" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3129 "while [ $" str " -le "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3130 (read-string "upper limit: ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3131 " ]; do" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3132 > _ ?$ str \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3133 str ?= (sh-add (sh-remember-variable str) 1) \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3134 "done" > )
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3135 (rc "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3136 > "for( " str " in" " `{awk 'BEGIN { for( i=1; i<="
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3137 (read-string "upper limit: ")
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3138 "; i++ ) print i }'`}) {" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3139 > _ ?$ (sh-remember-variable str) \n
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3140 ?} >)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3141 (sh "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3142 > "for " str " in `awk 'BEGIN { for( i=1; i<="
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3143 (read-string "upper limit: ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3144 "; i++ ) print i }'`; do" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3145 > _ ?$ (sh-remember-variable str) \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3146 "done" > ))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3147
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3148
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3149 (defun sh-shell-initialize-variables ()
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3150 "Scan the buffer for variable assignments.
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3151 Add these variables to `sh-shell-variables'."
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3152 (message "Scanning buffer `%s' for variable assignments..." (buffer-name))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3153 (save-excursion
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3154 (goto-char (point-min))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3155 (setq sh-shell-variables-initialized t)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3156 (while (search-forward "=" nil t)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3157 (sh-assignment 0)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3158 (message "Scanning buffer `%s' for variable assignments...done"
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3159 (buffer-name)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3160
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3161 (defvar sh-add-buffer)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3162
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3163 (defun sh-add-completer (string predicate code)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3164 "Do completion using `sh-shell-variables', but initialize it first.
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3165 This function is designed for use as the \"completion table\",
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3166 so it takes three arguments:
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3167 STRING, the current buffer contents;
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3168 PREDICATE, the predicate for filtering possible matches;
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3169 CODE, which says what kind of things to do.
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3170 CODE can be nil, t or `lambda'.
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3171 nil means to return the best completion of STRING, or nil if there is none.
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3172 t means to return a list of all possible completions of STRING.
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3173 `lambda' means to return t if STRING is a valid completion as it stands."
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3174 (let ((sh-shell-variables
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3175 (save-excursion
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3176 (set-buffer sh-add-buffer)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3177 (or sh-shell-variables-initialized
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3178 (sh-shell-initialize-variables))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3179 (nconc (mapcar (lambda (var)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3180 (let ((name
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3181 (substring var 0 (string-match "=" var))))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3182 (cons name name)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3183 process-environment)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3184 sh-shell-variables))))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3185 (cond ((null code)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3186 (try-completion string sh-shell-variables predicate))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3187 ((eq code t)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3188 (all-completions string sh-shell-variables predicate))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3189 ((eq code 'lambda)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3190 (assoc string sh-shell-variables)))))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3191
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3192 (defun sh-add (var delta)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3193 "Insert an addition of VAR and prefix DELTA for Bourne (type) shell."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3194 (interactive
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3195 (let ((sh-add-buffer (current-buffer)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3196 (list (completing-read "Variable: " 'sh-add-completer)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3197 (prefix-numeric-value current-prefix-arg))))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3198 (insert (sh-feature '((bash . "$[ ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3199 (ksh88 . "$(( ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3200 (posix . "$(( ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3201 (rc . "`{expr $")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3202 (sh . "`expr $")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3203 (zsh . "$[ ")))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3204 (sh-remember-variable var)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3205 (if (< delta 0) " - " " + ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3206 (number-to-string (abs delta))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3207 (sh-feature '((bash . " ]")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3208 (ksh88 . " ))")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3209 (posix . " ))")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3210 (rc . "}")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3211 (sh . "`")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3212 (zsh . " ]")))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3213
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3214
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3215
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3216 (define-skeleton sh-function
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3217 "Insert a function definition. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3218 (bash eval sh-modify ksh88
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3219 3 "() {")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3220 (ksh88 "name: "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3221 "function " str " {" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3222 > _ \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3223 < "}")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3224 (rc eval sh-modify ksh88
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3225 1 "fn ")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3226 (sh ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3227 "() {" \n
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3228 > _ \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3229 < "}"))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3230
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3231
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3232
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3233 (define-skeleton sh-if
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3234 "Insert an if statement. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3235 (csh "condition: "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3236 "if( " str " ) then" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3237 > _ \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3238 ( "other condition, %s: "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3239 < "else if( " str " ) then" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3240 > _ \n)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3241 < "else" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3242 > _ \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3243 resume:
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3244 < "endif")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3245 (es "condition: "
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3246 > "if { " str " } {" \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3247 > _ \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3248 ( "other condition, %s: "
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3249 "} { " str " } {" > \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3250 > _ \n)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3251 "} {" > \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3252 > _ \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3253 resume:
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3254 ?} > )
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3255 (rc "condition: "
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3256 > "if( " str " ) {" \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3257 > _ \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3258 ( "other condition, %s: "
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3259 "} else if( " str " ) {" > \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3260 > _ \n)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3261 "} else {" > \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3262 > _ \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3263 resume:
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3264 ?} >
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3265 )
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3266 (sh "condition: "
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3267 '(setq input (sh-feature sh-test))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3268 > "if " str "; then" \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3269 > _ \n
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3270 ( "other condition, %s: "
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3271 > "elif " str "; then" > \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3272 > \n)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3273 "else" > \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3274 > \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3275 resume:
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3276 "fi" > ))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3277
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3278
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3279
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3280 (define-skeleton sh-repeat
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3281 "Insert a repeat loop definition. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3282 (es nil
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3283 > "forever {" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3284 > _ \n
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3285 ?} > )
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3286 (zsh "factor: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3287 > "repeat " str "; do" > \n
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3288 > \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3289 "done" > ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3290
17501
478f9bb8575c Remove all menu-enable properties except for sh-case.
Richard M. Stallman <rms@gnu.org>
parents: 17480
diff changeset
3291 ;;;(put 'sh-repeat 'menu-enable '(sh-feature sh-repeat))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3292
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3293
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3294
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3295 (define-skeleton sh-select
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3296 "Insert a select statement. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3297 (ksh88 "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3298 > "select " str " in " _ "; do" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3299 > ?$ str \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3300 "done" > )
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
3301 (bash eval sh-append ksh88))
17501
478f9bb8575c Remove all menu-enable properties except for sh-case.
Richard M. Stallman <rms@gnu.org>
parents: 17480
diff changeset
3302 ;;;(put 'sh-select 'menu-enable '(sh-feature sh-select))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3303
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3304
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3305
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3306 (define-skeleton sh-tmp-file
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3307 "Insert code to setup temporary file handling. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3308 (bash eval identity ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3309 (csh (file-name-nondirectory (buffer-file-name))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3310 "set tmp = /tmp/" str ".$$" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3311 "onintr exit" \n _
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3312 (and (goto-char (point-max))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3313 (not (bolp))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3314 ?\n)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3315 "exit:\n"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3316 "rm $tmp* >&/dev/null" >)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3317 (es (file-name-nondirectory (buffer-file-name))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3318 > "local( signals = $signals sighup sigint; tmp = /tmp/" str
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3319 ".$pid ) {" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3320 > "catch @ e {" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3321 > "rm $tmp^* >[2]/dev/null" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3322 "throw $e" \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3323 "} {" > \n
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3324 _ \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3325 ?} > \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3326 ?} > )
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3327 (ksh88 eval sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3328 7 "EXIT")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3329 (rc (file-name-nondirectory (buffer-file-name))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3330 > "tmp = /tmp/" str ".$pid" \n
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3331 "fn sigexit { rm $tmp^* >[2]/dev/null }")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3332 (sh (file-name-nondirectory (buffer-file-name))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3333 > "TMP=${TMPDIR:-/tmp}/" str ".$$" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3334 "trap \"rm $TMP* 2>/dev/null\" " ?0))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3335
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3336
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3337
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3338 (define-skeleton sh-until
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3339 "Insert an until loop. See `sh-feature'."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3340 (sh "condition: "
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3341 '(setq input (sh-feature sh-test))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3342 > "until " str "; do" \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3343 > _ \n
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3344 "done" > ))
17501
478f9bb8575c Remove all menu-enable properties except for sh-case.
Richard M. Stallman <rms@gnu.org>
parents: 17480
diff changeset
3345 ;;;(put 'sh-until 'menu-enable '(sh-feature sh-until))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3346
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3347
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3348
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3349 (define-skeleton sh-while
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3350 "Insert a while loop. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3351 (csh eval sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3352 2 ""
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3353 3 "while( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3354 5 " )"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3355 10 '<
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3356 11 "end" )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3357 (es eval sh-modify sh
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3358 3 "while { "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3359 5 " } {"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3360 10 ?} )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3361 (rc eval sh-modify sh
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3362 3 "while( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3363 5 " ) {"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3364 10 ?} )
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3365 (sh "condition: "
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3366 '(setq input (sh-feature sh-test))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3367 > "while " str "; do" \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3368 > _ \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3369 "done" > ))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3370
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3371
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3372
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3373 (define-skeleton sh-while-getopts
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3374 "Insert a while getopts loop. See `sh-feature'.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3375 Prompts for an options string which consists of letters for each recognized
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3376 option followed by a colon `:' if the option accepts an argument."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3377 (bash eval sh-modify sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3378 18 "${0##*/}")
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3379 (csh nil
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3380 "while( 1 )" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3381 > "switch( \"$1\" )" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3382 '(setq input '("- x" . 2))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3383 > >
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3384 ( "option, %s: "
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3385 < "case " '(eval str)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3386 '(if (string-match " +" str)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3387 (setq v1 (substring str (match-end 0))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3388 str (substring str 0 (match-beginning 0)))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3389 (setq v1 nil))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3390 str ?: \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3391 > "set " v1 & " = $2" | -4 & _ \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3392 (if v1 "shift") & \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3393 "breaksw" \n)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3394 < "case --:" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3395 > "shift" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3396 < "default:" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3397 > "break" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3398 resume:
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3399 < < "endsw" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3400 "shift" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3401 < "end")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3402 (ksh88 eval sh-modify sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3403 16 "print"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3404 18 "${0##*/}"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3405 36 "OPTIND-1")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3406 (posix eval sh-modify sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3407 18 "$(basename $0)")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3408 (sh "optstring: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3409 > "while getopts :" str " OPT; do" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3410 > "case $OPT in" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3411 '(setq v1 (append (vconcat str) nil))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3412 ( (prog1 (if v1 (char-to-string (car v1)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3413 (if (eq (nth 1 v1) ?:)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3414 (setq v1 (nthcdr 2 v1)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3415 v2 "\"$OPTARG\"")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3416 (setq v1 (cdr v1)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3417 v2 nil)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3418 > str "|+" str (propertize ")" 'syntax-table sh-st-punc) \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3419 > _ v2 \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3420 > ";;" \n)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3421 > "*" (propertize ")" 'syntax-table sh-st-punc) \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3422 > "echo" " \"usage: " "`basename $0`"
15027
30c4f64f3579 (sh-while-getopts): Punctuate help message better.
Richard M. Stallman <rms@gnu.org>
parents: 14892
diff changeset
3423 " [+-" '(setq v1 (point)) str
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3424 '(save-excursion
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3425 (while (search-backward ":" v1 t)
15027
30c4f64f3579 (sh-while-getopts): Punctuate help message better.
Richard M. Stallman <rms@gnu.org>
parents: 14892
diff changeset
3426 (replace-match " ARG] [+-" t t)))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3427 (if (eq (preceding-char) ?-) -5)
29844
093c79809c9e (sh-while-getopts): Fix handling of
Gerd Moellmann <gerd@gnu.org>
parents: 29422
diff changeset
3428 (if (and (sequencep v1) (length v1)) "] " "} ")
28923
dcafe3c9cd6c (sh-while-getopts) <sh>: Handle case that
Gerd Moellmann <gerd@gnu.org>
parents: 26967
diff changeset
3429 "[--] ARGS...\"" \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3430 "exit 2" > \n
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3431 "esac" >
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3432 \n "done"
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3433 > \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3434 "shift " (sh-add "OPTIND" -1)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3435
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3436
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3437
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3438 (defun sh-assignment (arg)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3439 "Remember preceding identifier for future completion and do self-insert."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3440 (interactive "p")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3441 (self-insert-command arg)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3442 (if (<= arg 1)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3443 (sh-remember-variable
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3444 (save-excursion
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3445 (if (re-search-forward (sh-feature sh-assignment-regexp)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3446 (prog1 (point)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3447 (beginning-of-line 1))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3448 t)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
3449 (match-string 1))))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3450
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3451
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3452
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3453 (defun sh-maybe-here-document (arg)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3454 "Insert self. Without prefix, following unquoted `<' inserts here document.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3455 The document is bounded by `sh-here-document-word'."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3456 (interactive "*P")
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3457 (self-insert-command (prefix-numeric-value arg))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3458 (or arg
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3459 (not (eq (char-after (- (point) 2)) last-command-char))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3460 (save-excursion
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3461 (backward-char 2)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3462 (sh-quoted-p))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3463 (progn
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3464 (insert sh-here-document-word)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3465 (or (eolp) (looking-at "[ \t]") (insert ? ))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3466 (end-of-line 1)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3467 (while
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3468 (sh-quoted-p)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3469 (end-of-line 2))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3470 (newline)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3471 (save-excursion (insert ?\n sh-here-document-word)))))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3472
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3473
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3474 ;; various other commands
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3475
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3476 (autoload 'comint-dynamic-complete "comint"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3477 "Dynamically perform completion at point." t)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3478
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3479 (autoload 'shell-dynamic-complete-command "shell"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3480 "Dynamically complete the command at point." t)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3481
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3482 (autoload 'comint-dynamic-complete-filename "comint"
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3483 "Dynamically complete the filename at point." t)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3484
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3485 (autoload 'shell-dynamic-complete-environment-variable "shell"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3486 "Dynamically complete the environment variable at point." t)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3487
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3488
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3489
12887
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3490 (defun sh-newline-and-indent ()
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3491 "Strip unquoted whitespace, insert newline, and indent like current line."
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3492 (interactive "*")
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3493 (indent-to (prog1 (current-indentation)
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3494 (delete-region (point)
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3495 (progn
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3496 (or (zerop (skip-chars-backward " \t"))
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3497 (if (sh-quoted-p)
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3498 (forward-char)))
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3499 (point)))
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3500 (newline))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3501
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3502 (defun sh-beginning-of-command ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3503 "Move point to successive beginnings of commands."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3504 (interactive)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3505 (if (re-search-backward sh-beginning-of-command nil t)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3506 (goto-char (match-beginning 2))))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3507
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3508 (defun sh-end-of-command ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3509 "Move point to successive ends of commands."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3510 (interactive)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3511 (if (re-search-forward sh-end-of-command nil t)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3512 (goto-char (match-end 1))))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3513
13707
9356c7d7dcd6 Provide sh-script.
Karl Heuer <kwzh@gnu.org>
parents: 13705
diff changeset
3514 (provide 'sh-script)
18382
0e4943a370e2 Whitespace change.
Richard M. Stallman <rms@gnu.org>
parents: 18024
diff changeset
3515
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3516 ;;; sh-script.el ends here