Mercurial > emacs
annotate lisp/progmodes/sh-script.el @ 64051:d700ccca5bd4
(sh, sh-script): Finish `defgroup' description with period.
(sh-maybe-here-document): "?\ " -> "?\s".
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Mon, 04 Jul 2005 03:24:03 +0000 |
parents | 135b9f905ec6 |
children | 18a818a2ee7c |
rev | line source |
---|---|
6463 | 1 ;;; sh-script.el --- shell-script editing commands for Emacs |
14169 | 2 |
59622
5ec981fa30e5
(sh-here-doc-open-re): Don't allow `|' or other
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59566
diff
changeset
|
3 ;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2001, 2003, 2004, 2005 |
37296
f9dbfb08ed11
(sh-indent-line): Add optional PREFIX-ARG
Gerd Moellmann <gerd@gnu.org>
parents:
36631
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
6463 | 5 |
23869 | 6 ;; Author: Daniel Pfeiffer <occitan@esperanto.org> |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
7 ;; Version: 2.0f |
6463 | 8 ;; Maintainer: FSF |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
9 ;; Keywords: languages, unix |
6463 | 10 |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | |
15 ;; the Free Software Foundation; either version 2, or (at your option) | |
16 ;; any later version. | |
17 | |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
14169 | 24 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
26 ;; Boston, MA 02111-1307, USA. | |
6463 | 27 |
28 ;;; Commentary: | |
29 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
30 ;; 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
|
31 ;; 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
|
32 ;; 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
|
33 ;; 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
|
34 ;; the environment as well as commands. |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
35 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
36 ;;; Known Bugs: |
6463 | 37 |
13705
4111cc3136d1
(sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents:
13510
diff
changeset
|
38 ;; - 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
|
39 ;; - 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
|
40 ;; syntactically distinguishing those from `'' strings. |
8257
bbf6304598d9
"Comment out" autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents:
8121
diff
changeset
|
41 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
42 ;; Indentation |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
43 ;; =========== |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
44 ;; 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
|
45 ;; and its derivatives it is quite customizable. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
46 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
47 ;; 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
|
48 ;; zsh, ...). |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
49 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
50 ;; 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
|
51 ;; 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
|
52 ;; 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
|
53 ;; 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
|
54 ;; 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
|
55 ;; of the line containing the fi. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
56 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
57 ;; 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
|
58 ;; 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
|
59 ;; 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
|
60 ;; indentation there is. Valid symbols: |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
61 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
62 ;; + Indent right by sh-basic-offset |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
63 ;; - Indent left by sh-basic-offset |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
64 ;; ++ Indent right twice sh-basic-offset |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
65 ;; -- Indent left twice sh-basic-offset |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
66 ;; * Indent right half sh-basic-offset |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
67 ;; / Indent left half sh-basic-offset. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
68 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
69 ;; There are 4 commands to help set the indentation variables: |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
70 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
71 ;; `sh-show-indent' |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
72 ;; 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
|
73 ;; line and its value. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
74 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
75 ;; `sh-set-indent' |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
76 ;; 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
|
77 ;; 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
|
78 ;; 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
|
79 ;; 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
|
80 ;; 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
|
81 ;; valid simply press C-h at the prompt. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
82 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
83 ;; `sh-learn-line-indent' |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
84 ;; 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
|
85 ;; 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
|
86 ;; 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
|
87 ;; the value to one of the symbols if applicable. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
88 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
89 ;; `sh-learn-buffer-indent' |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
90 ;; 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
|
91 ;; 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
|
92 ;; 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
|
93 ;; 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
|
94 ;; 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
|
95 ;; 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
|
96 ;; non-nil. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
97 ;; `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
|
98 ;; 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
|
99 ;; 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
|
100 ;; `sh-learn-basic-offset'. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
101 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
102 ;; 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
|
103 ;; (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
|
104 ;; 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
|
105 ;; 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
|
106 ;; *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
|
107 ;; `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
|
108 ;; suffice. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
109 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
110 ;; Saving indentation values |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
111 ;; ------------------------- |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
112 ;; 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
|
113 ;; 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
|
114 ;; 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
|
115 ;; the buffer. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
116 ;; You can do this automatically like this: |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
117 ;; (add-hook 'sh-set-shell-hook 'sh-learn-buffer-indent) |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
118 ;; |
47264
05606bafb8f5
(sh-indent-for-fi, sh-indent-for-done): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents:
45900
diff
changeset
|
119 ;; However... `sh-learn-buffer-indent' is extremely slow, |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
120 ;; 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
|
121 ;; "last one wins" which may not produce the desired setting. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
122 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
123 ;; 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
|
124 ;; to reload them in another buffer or at another point in time. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
125 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
126 ;; 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
|
127 ;; the current buffer. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
128 ;; 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
|
129 ;; buffer from a specific style. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
130 ;; 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
|
131 ;; 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
|
132 ;; `load-file' to load it. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
133 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
134 ;; Indentation variables - buffer local or global? |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
135 ;; ---------------------------------------------- |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
136 ;; 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
|
137 ;; 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
|
138 ;; 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
|
139 ;; to work if the variables are already local! |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
140 ;; |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
141 ;; 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
|
142 ;; functions: `sh-make-vars-local' and `sh-reset-indent-vars-to-global-values'. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
143 ;; |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
144 ;; 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
|
145 ;; buffer local when the mode is established. |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
146 ;; 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
|
147 ;; 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
|
148 ;; 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
|
149 ;; command `sh-reset-indent-vars-to-global-values'. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
150 ;; |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
151 ;; This may be awkward, but the intent is to cover all cases. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
152 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
153 ;; Awkward things, pitfalls |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
154 ;; ------------------------ |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
155 ;; Indentation for a sh script is complicated for a number of reasons: |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
156 ;; |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
157 ;; 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
|
158 ;; 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
|
159 ;; 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
|
160 ;; 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
|
161 ;; things quite tricky! |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
162 ;; 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
|
163 ;; 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
|
164 ;; containing the "<<" symbol. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
165 ;; 4. A line may be continued using the "\". |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
166 ;; 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
|
167 ;; but it doesn't in the sequence "$#"! |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
168 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
169 ;; 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
|
170 ;; 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
|
171 ;; disadvantages: |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
172 ;; 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
|
173 ;; 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
|
174 ;; 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
|
175 ;; 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
|
176 ;; 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
|
177 ;; but the user issued `toggle-read-only'. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
178 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
179 ;; Bugs |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
180 ;; ---- |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
181 ;; - 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
|
182 ;; independently, rather than saving state information. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
183 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
184 ;; - `sh-learn-buffer-indent' is extremely slow. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
185 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
186 ;; Richard Sharman <rsharman@pobox.com> June 1999. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
187 |
6463 | 188 ;;; Code: |
189 | |
190 ;; page 1: variables and settings | |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
191 ;; page 2: indentation stuff |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
192 ;; page 3: mode-command and utility functions |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
193 ;; page 4: statement syntax-commands for various shells |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
194 ;; page 5: various other commands |
6463 | 195 |
32503 | 196 (eval-when-compile |
197 (require 'skeleton) | |
49306
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
198 (require 'cl) |
32503 | 199 (require 'comint)) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
200 (require 'executable) |
6463 | 201 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
202 |
17068
d1391b21626f
(sh-mode-hook, sh-set-shell-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
16839
diff
changeset
|
203 |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
204 (defgroup sh nil |
64051
d700ccca5bd4
(sh, sh-script): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63885
diff
changeset
|
205 "Shell programming utilities." |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
206 :group 'unix |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
207 :group 'languages) |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
208 |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
209 (defgroup sh-script nil |
64051
d700ccca5bd4
(sh, sh-script): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63885
diff
changeset
|
210 "Shell script mode." |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
211 :group 'sh |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
212 :prefix "sh-") |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
213 |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
214 |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
215 (defcustom sh-ancestor-alist |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
216 '((ash . sh) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
217 (bash . jsh) |
29109
0e45e6e90467
(sh-ancestor-alist): Add `bash2'.
Gerd Moellmann <gerd@gnu.org>
parents:
28923
diff
changeset
|
218 (bash2 . jsh) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
219 (dtksh . ksh) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
220 (es . rc) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
221 (itcsh . tcsh) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
222 (jcsh . csh) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
223 (jsh . sh) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
224 (ksh . ksh88) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
225 (ksh88 . jsh) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
226 (oash . sh) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
227 (pdksh . ksh88) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
228 (posix . sh) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
229 (tcsh . csh) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
230 (wksh . ksh88) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
231 (wsh . sh) |
23501
f12ae4499ae0
(sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents:
23341
diff
changeset
|
232 (zsh . ksh88) |
f12ae4499ae0
(sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents:
23341
diff
changeset
|
233 (rpm . sh)) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
234 "*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
|
235 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
|
236 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
|
237 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
238 csh C Shell |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
239 jcsh C Shell with Job Control |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
240 tcsh Turbo C Shell |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
241 itcsh ? Turbo C Shell |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
242 rc Plan 9 Shell |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
243 es Extensible Shell |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
244 sh Bourne Shell |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
245 ash ? Shell |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
246 jsh Bourne Shell with Job Control |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
247 bash GNU Bourne Again Shell |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
248 ksh88 Korn Shell '88 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
249 ksh Korn Shell '93 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
250 dtksh CDE Desktop Korn Shell |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
251 pdksh Public Domain Korn Shell |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
252 wksh Window Korn Shell |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
253 zsh Z Shell |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
254 oash SCO OA (curses) Shell |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
255 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
|
256 wsh ? Shell" |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
257 :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
|
258 :group 'sh-script) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
259 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
260 |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
261 (defcustom sh-alias-alist |
47732
3712c799f805
(sh-alias-alist): Use append instead of nconc.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47595
diff
changeset
|
262 (append (if (eq system-type 'gnu/linux) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
263 '((csh . tcsh) |
14119
2a05fc406f3a
(sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents:
14026
diff
changeset
|
264 (ksh . pdksh))) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
265 ;; for the time being |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
266 '((ksh . ksh88) |
29109
0e45e6e90467
(sh-ancestor-alist): Add `bash2'.
Gerd Moellmann <gerd@gnu.org>
parents:
28923
diff
changeset
|
267 (bash2 . bash) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
268 (sh5 . sh))) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
269 "*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
|
270 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
|
271 shell it really is." |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
272 :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
|
273 :group 'sh-script) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
274 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
275 |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
276 (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
|
277 (or |
16839
daaa2c5bb40a
(sh-shell-file): Downcase and remove extension on shells in NT.
Richard M. Stallman <rms@gnu.org>
parents:
16810
diff
changeset
|
278 ;; 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
|
279 ;; 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
|
280 ;; 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
|
281 (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
|
282 (let* ((shell (getenv "SHELL")) |
3e498c36ccce
(sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents:
21669
diff
changeset
|
283 (shell-base |
3e498c36ccce
(sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents:
21669
diff
changeset
|
284 (and shell (file-name-nondirectory shell)))) |
3e498c36ccce
(sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents:
21669
diff
changeset
|
285 ;; 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
|
286 ;; so use the default instead. |
3e498c36ccce
(sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents:
21669
diff
changeset
|
287 (if (or (null shell) |
3e498c36ccce
(sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents:
21669
diff
changeset
|
288 (member (downcase shell-base) |
21980
e73c0672d7b3
(sh-shell-file): Add cmdproxy to MS shells.
Richard M. Stallman <rms@gnu.org>
parents:
21925
diff
changeset
|
289 '("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
|
290 "cmdproxy.exe"))) |
21925
3e498c36ccce
(sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents:
21669
diff
changeset
|
291 "/bin/sh" |
3e498c36ccce
(sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents:
21669
diff
changeset
|
292 (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
|
293 (getenv "SHELL") |
20dc495230a0
(sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents:
16552
diff
changeset
|
294 "/bin/sh") |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
295 "*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
|
296 :type 'string |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
297 :group 'sh-script) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
298 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
299 |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
300 (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
|
301 ;; 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
|
302 '((bash) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
303 (csh . "-f") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
304 (pdksh) |
14886
96423e733197
(sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents:
14876
diff
changeset
|
305 ;; 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
|
306 (ksh88) |
14886
96423e733197
(sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents:
14876
diff
changeset
|
307 ;; -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
|
308 (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
|
309 ;; 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
|
310 ;; 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
|
311 (wksh) |
96423e733197
(sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents:
14876
diff
changeset
|
312 ;; -f means don't run .zshrc. |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
313 (zsh . "-f")) |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
314 "*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
|
315 :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
|
316 (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
|
317 (string :tag "Arguments") |
54158
43e09e943479
(sh-shell-arg, sh-require-final-newline, sh-assignment-regexp, sh-builtins)
Eli Zaretskii <eliz@gnu.org>
parents:
53419
diff
changeset
|
318 (sexp :format "Evaluate: %v")))) |
17407
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 |
56688
6eee795cb9eb
(sh-set-shell): Use sh-mode-abbrev-table.
Richard M. Stallman <rms@gnu.org>
parents:
55119
diff
changeset
|
356 (defvar sh-mode-abbrev-table nil) |
6eee795cb9eb
(sh-set-shell): Use sh-mode-abbrev-table.
Richard M. Stallman <rms@gnu.org>
parents:
55119
diff
changeset
|
357 |
6eee795cb9eb
(sh-set-shell): Use sh-mode-abbrev-table.
Richard M. Stallman <rms@gnu.org>
parents:
55119
diff
changeset
|
358 (define-abbrev-table 'sh-mode-abbrev-table ()) |
6eee795cb9eb
(sh-set-shell): Use sh-mode-abbrev-table.
Richard M. Stallman <rms@gnu.org>
parents:
55119
diff
changeset
|
359 |
6eee795cb9eb
(sh-set-shell): Use sh-mode-abbrev-table.
Richard M. Stallman <rms@gnu.org>
parents:
55119
diff
changeset
|
360 |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
361 ;; I turned off this feature because it doesn't permit typing commands |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
362 ;; in the usual way without help. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
363 ;;(defvar sh-abbrevs |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
364 ;; '((csh sh-abbrevs shell |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
365 ;; "switch" 'sh-case |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
366 ;; "getopts" 'sh-while-getopts) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
367 |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
368 ;; (es sh-abbrevs shell |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
369 ;; "function" 'sh-function) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
370 |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
371 ;; (ksh88 sh-abbrevs sh |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
372 ;; "select" 'sh-select) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
373 |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
374 ;; (rc sh-abbrevs shell |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
375 ;; "case" 'sh-case |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
376 ;; "function" 'sh-function) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
377 |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
378 ;; (sh sh-abbrevs shell |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
379 ;; "case" 'sh-case |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
380 ;; "function" 'sh-function |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
381 ;; "until" 'sh-until |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
382 ;; "getopts" 'sh-while-getopts) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
383 |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
384 ;; ;; The next entry is only used for defining the others |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
385 ;; (shell "for" sh-for |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
386 ;; "loop" sh-indexed-loop |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
387 ;; "if" sh-if |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
388 ;; "tmpfile" sh-tmp-file |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
389 ;; "while" sh-while) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
390 |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
391 ;; (zsh sh-abbrevs ksh88 |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
392 ;; "repeat" 'sh-repeat)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
393 ;; "Abbrev-table used in Shell-Script mode. See `sh-feature'. |
14119
2a05fc406f3a
(sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents:
14026
diff
changeset
|
394 ;;;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
|
395 ;;;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
|
396 |
6463 | 397 |
398 | |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
399 (defun sh-mode-syntax-table (table &rest list) |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
400 "Copy TABLE and set syntax for successive CHARs according to strings S." |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
401 (setq table (copy-syntax-table table)) |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
402 (while list |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
403 (modify-syntax-entry (pop list) (pop list) table)) |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
404 table) |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
405 |
52682
a7331078ec76
(sh-mode-syntax-table): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
52619
diff
changeset
|
406 (defvar sh-mode-syntax-table nil |
a7331078ec76
(sh-mode-syntax-table): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
52619
diff
changeset
|
407 "The syntax table to use for Shell-Script mode. |
a7331078ec76
(sh-mode-syntax-table): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
52619
diff
changeset
|
408 This is buffer-local in every such buffer.") |
a7331078ec76
(sh-mode-syntax-table): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
52619
diff
changeset
|
409 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
410 (defvar sh-mode-default-syntax-table |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
411 (sh-mode-syntax-table () |
41349
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
412 ?\# "<" |
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
413 ?\n ">#" |
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
414 ?\" "\"\"" |
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
415 ?\' "\"'" |
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
416 ?\` "\"`" |
62242
cce9501aab6e
(sh-mode-default-syntax-table): Set the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
62214
diff
changeset
|
417 ;; ?$ might also have a ". p" syntax. Both "'" and ". p" seem |
cce9501aab6e
(sh-mode-default-syntax-table): Set the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
62214
diff
changeset
|
418 ;; to work fine. This is needed so that dabbrev-expand |
cce9501aab6e
(sh-mode-default-syntax-table): Set the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
62214
diff
changeset
|
419 ;; $VARNAME works. |
cce9501aab6e
(sh-mode-default-syntax-table): Set the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
62214
diff
changeset
|
420 ?$ "'" |
41349
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
421 ?! "_" |
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
422 ?% "_" |
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
423 ?: "_" |
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
424 ?. "_" |
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
425 ?^ "_" |
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
426 ?~ "_" |
51970
be96dd81138a
(sh-mode-syntax-table): Change syntax of ?, to "_".
Andreas Schwab <schwab@suse.de>
parents:
51727
diff
changeset
|
427 ?, "_" |
57159
e00b0d40b4bc
(sh-mode-default-syntax-table): Set syntax of = to "." (punctuation).
Richard M. Stallman <rms@gnu.org>
parents:
56688
diff
changeset
|
428 ?= "." |
41349
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
429 ?< "." |
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
430 ?> ".") |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
431 "Default syntax table for shell mode.") |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
432 |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
433 (defvar sh-mode-syntax-table-input |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
434 '((sh . nil)) |
41349
8dd8d78194a1
(sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents:
41348
diff
changeset
|
435 "Syntax-table used in Shell-Script mode. See `sh-feature'.") |
6463 | 436 |
437 (defvar sh-mode-map | |
13705
4111cc3136d1
(sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents:
13510
diff
changeset
|
438 (let ((map (make-sparse-keymap)) |
4111cc3136d1
(sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents:
13510
diff
changeset
|
439 (menu-map (make-sparse-keymap "Insert"))) |
6463 | 440 (define-key map "\C-c(" 'sh-function) |
441 (define-key map "\C-c\C-w" 'sh-while) | |
442 (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
|
443 (define-key map "\C-c\C-t" 'sh-tmp-file) |
6463 | 444 (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
|
445 (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
|
446 (define-key map "\C-c\C-o" 'sh-while-getopts) |
6463 | 447 (define-key map "\C-c\C-l" 'sh-indexed-loop) |
448 (define-key map "\C-c\C-i" 'sh-if) | |
449 (define-key map "\C-c\C-f" 'sh-for) | |
450 (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
|
451 (define-key map "\C-c?" 'sh-show-indent) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
452 (define-key map "\C-c=" 'sh-set-indent) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
453 (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
|
454 (define-key map "\C-c>" 'sh-learn-buffer-indent) |
59566
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
455 (define-key map "\C-c\C-\\" 'sh-backslash-region) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
456 |
6463 | 457 (define-key map "=" 'sh-assignment) |
458 (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
|
459 (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
|
460 (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
|
461 (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
|
462 (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
|
463 (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
|
464 (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
|
465 (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
|
466 (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
|
467 (define-key map "\"" 'skeleton-pair-insert-maybe) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
468 |
49176
56966d83f3a5
(sh-mode-map): Use command remapping instead of
Andreas Schwab <schwab@suse.de>
parents:
49132
diff
changeset
|
469 (define-key map [remap complete-tag] 'comint-dynamic-complete) |
56966d83f3a5
(sh-mode-map): Use command remapping instead of
Andreas Schwab <schwab@suse.de>
parents:
49132
diff
changeset
|
470 (define-key map [remap newline-and-indent] 'sh-newline-and-indent) |
56966d83f3a5
(sh-mode-map): Use command remapping instead of
Andreas Schwab <schwab@suse.de>
parents:
49132
diff
changeset
|
471 (define-key map [remap delete-backward-char] |
56966d83f3a5
(sh-mode-map): Use command remapping instead of
Andreas Schwab <schwab@suse.de>
parents:
49132
diff
changeset
|
472 'backward-delete-char-untabify) |
6463 | 473 (define-key map "\C-c:" 'sh-set-shell) |
49176
56966d83f3a5
(sh-mode-map): Use command remapping instead of
Andreas Schwab <schwab@suse.de>
parents:
49132
diff
changeset
|
474 (define-key map [remap backward-sentence] 'sh-beginning-of-command) |
56966d83f3a5
(sh-mode-map): Use command remapping instead of
Andreas Schwab <schwab@suse.de>
parents:
49132
diff
changeset
|
475 (define-key map [remap forward-sentence] 'sh-end-of-command) |
13705
4111cc3136d1
(sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents:
13510
diff
changeset
|
476 (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
|
477 (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
|
478 (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
|
479 (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
|
480 (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
|
481 (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
|
482 (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
|
483 (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
|
484 (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
|
485 (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
|
486 (define-key menu-map [sh-case] '("Case Statement" . sh-case)) |
6463 | 487 map) |
488 "Keymap used in Shell-Script mode.") | |
489 | |
490 | |
491 | |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
492 (defcustom sh-dynamic-complete-functions |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
493 '(shell-dynamic-complete-environment-variable |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
494 shell-dynamic-complete-command |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
495 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
|
496 "*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
|
497 :type '(repeat function) |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
498 :group 'sh-script) |
6463 | 499 |
500 | |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
501 (defcustom sh-require-final-newline |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
502 '((csh . t) |
59251
84ede35ffeb4
(sh-require-final-newline):
Richard M. Stallman <rms@gnu.org>
parents:
58767
diff
changeset
|
503 (pdksh . t)) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
504 "*Value of `require-final-newline' in Shell-Script mode buffers. |
59251
84ede35ffeb4
(sh-require-final-newline):
Richard M. Stallman <rms@gnu.org>
parents:
58767
diff
changeset
|
505 \(SHELL . t) means use the value of `mode-require-final-newline' for SHELL. |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
506 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 (const :tag "require" t) |
54158
43e09e943479
(sh-shell-arg, sh-require-final-newline, sh-assignment-regexp, sh-builtins)
Eli Zaretskii <eliz@gnu.org>
parents:
53419
diff
changeset
|
509 (sexp :format "Evaluate: %v")))) |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
510 :group 'sh-script) |
6463 | 511 |
512 | |
17531
b891e41b4011
(sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents:
17501
diff
changeset
|
513 (defcustom sh-assignment-regexp |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
514 '((csh . "\\<\\([a-zA-Z0-9_]+\\)\\(\\[.+\\]\\)?[ \t]*[-+*/%^]?=") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
515 ;; actually spaces are only supported in let/(( ... )) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
516 (ksh88 . "\\<\\([a-zA-Z0-9_]+\\)\\(\\[.+\\]\\)?[ \t]*\\([-+*/%&|~^]\\|<<\\|>>\\)?=") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
517 (rc . "\\<\\([a-zA-Z0-9_*]+\\)[ \t]*=") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
518 (sh . "\\<\\([a-zA-Z0-9_]+\\)=")) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
519 "*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
|
520 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
|
521 sign. See `sh-feature'." |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
522 :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
|
523 (choice regexp |
54158
43e09e943479
(sh-shell-arg, sh-require-final-newline, sh-assignment-regexp, sh-builtins)
Eli Zaretskii <eliz@gnu.org>
parents:
53419
diff
changeset
|
524 (sexp :format "Evaluate: %v")))) |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
525 :group 'sh-script) |
6463 | 526 |
527 | |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
528 (defcustom sh-indentation 4 |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
529 "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
|
530 :type 'integer |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
531 :group 'sh-script) |
6463 | 532 |
533 | |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
534 (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
|
535 "*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
|
536 :type 'integer |
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 | 538 |
539 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
540 (defvar sh-header-marker nil |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
541 "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
|
542 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
|
543 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
544 |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
545 (defcustom sh-beginning-of-command |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
546 "\\([;({`|&]\\|\\`\\|[^\\]\n\\)[ \t]*\\([/~a-zA-Z0-9:]\\)" |
6463 | 547 "*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
|
548 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
|
549 :type 'regexp |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
550 :group 'sh-script) |
6463 | 551 |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
552 |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
553 (defcustom sh-end-of-command |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
554 "\\([/~a-zA-Z0-9:]\\)[ \t]*\\([;#)}`|&]\\|$\\)" |
6463 | 555 "*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
|
556 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
|
557 :type 'regexp |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
558 :group 'sh-script) |
6463 | 559 |
560 | |
561 | |
61534
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
562 (defcustom sh-here-document-word "EOF" |
51265
575ad90ca254
(sh-here-document-word): Document new treatment of leading "-".
Glenn Morris <rgm@gnu.org>
parents:
49743
diff
changeset
|
563 "Word to delimit here documents. |
61534
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
564 If the first character of this string is \"-\", this is taken as |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
565 part of the redirection operator, rather than part of the |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
566 word (that is, \"<<-\" instead of \"<<\"). This is a feature |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
567 used by some shells (for example Bash) to indicate that leading |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
568 tabs inside the here document should be ignored. In this case, |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
569 Emacs indents the initial body and end of the here document with |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
570 tabs, to the same level as the start (note that apart from this |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
571 there is no support for indentation of here documents). This |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
572 will only work correctly if `sh-basic-offset' is a multiple of |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
573 `tab-width'. |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
574 |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
575 Any quote characters or leading whitespace in the word are |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
576 removed when closing the here document." |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
577 :type 'string |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
578 :group 'sh-script) |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
579 |
6463 | 580 |
12863 | 581 (defvar sh-test |
582 '((sh "[ ]" . 3) | |
583 (ksh88 "[[ ]]" . 4)) | |
584 "Initial input in Bourne if, while and until skeletons. See `sh-feature'.") | |
585 | |
6463 | 586 |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
587 ;; 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
|
588 ;; 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
|
589 (defcustom sh-builtins |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
590 '((bash sh-append posix |
61316
283f977b41fb
(sh-builtins) <bash>: Add `caller'.
Glenn Morris <rgm@gnu.org>
parents:
60917
diff
changeset
|
591 "." "alias" "bg" "bind" "builtin" "caller" "compgen" "complete" |
52322
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
592 "declare" "dirs" "disown" "enable" "fc" "fg" "help" "history" |
52619
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
593 "jobs" "kill" "let" "local" "popd" "printf" "pushd" "shopt" |
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
594 "source" "suspend" "typeset" "unalias") |
12505
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 ;; The next entry is only used for defining the others |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
597 (bourne sh-append shell |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
598 "eval" "export" "getopts" "newgrp" "pwd" "read" "readonly" |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
599 "times" "ulimit") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
600 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
601 (csh sh-append shell |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
602 "alias" "chdir" "glob" "history" "limit" "nice" "nohup" "rehash" |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
603 "setenv" "source" "time" "unalias" "unhash") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
604 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
605 (dtksh sh-append wksh) |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
606 |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
607 (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
|
608 "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
|
609 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
610 (jsh sh-append sh |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
611 "bg" "fg" "jobs" "kill" "stop" "suspend") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
612 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
613 (jcsh sh-append csh |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
614 "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
|
615 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
616 (ksh88 sh-append bourne |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
617 "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
|
618 "typeset" "unalias" "whence") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
619 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
620 (oash sh-append sh |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
621 "checkwin" "dateline" "error" "form" "menu" "newwin" "oadeinit" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
622 "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
|
623 "wclear" "werase" "win" "wmclose" "wmmessage" "wmopen" "wmove" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
624 "wmtitle" "wrefresh") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
625 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
626 (pdksh sh-append ksh88 |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
627 "bind") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
628 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
629 (posix sh-append sh |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
630 "command") |
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 (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
|
633 "whatis") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
634 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
635 (sh sh-append bourne |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
636 "hash" "test" "type") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
637 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
638 ;; 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
|
639 (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
|
640 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
641 (wksh sh-append ksh88 |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
642 "Xt[A-Z][A-Za-z]*") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
643 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
644 (zsh sh-append ksh88 |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
645 "autoload" "bindkey" "builtin" "chdir" "compctl" "declare" "dirs" |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
646 "disable" "disown" "echotc" "enable" "functions" "getln" "hash" |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
647 "history" "integer" "limit" "local" "log" "popd" "pushd" "r" |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
648 "readonly" "rehash" "sched" "setopt" "source" "suspend" "true" |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
649 "ttyctl" "type" "unfunction" "unhash" "unlimit" "unsetopt" "vared" |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
650 "which")) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
651 "*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
|
652 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
|
653 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
|
654 :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
|
655 (choice (repeat string) |
54158
43e09e943479
(sh-shell-arg, sh-require-final-newline, sh-assignment-regexp, sh-builtins)
Eli Zaretskii <eliz@gnu.org>
parents:
53419
diff
changeset
|
656 (sexp :format "Evaluate: %v")))) |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
657 :group 'sh-script) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
658 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
659 |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
660 |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
661 (defcustom sh-leading-keywords |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
662 '((bash sh-append sh |
52322
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
663 "time") |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
664 |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
665 (csh "else") |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
666 |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
667 (es "true" "unwind-protect" "whatis") |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
668 |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
669 (rc "else") |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
670 |
55119
3a424bb24301
(sh-leading-keywords) <sh>: Add "!".
Andreas Schwab <schwab@suse.de>
parents:
54282
diff
changeset
|
671 (sh "!" "do" "elif" "else" "if" "then" "trap" "type" "until" "while")) |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
672 "*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
|
673 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
|
674 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
|
675 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
|
676 :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
|
677 (choice (repeat string) |
54158
43e09e943479
(sh-shell-arg, sh-require-final-newline, sh-assignment-regexp, sh-builtins)
Eli Zaretskii <eliz@gnu.org>
parents:
53419
diff
changeset
|
678 (sexp :format "Evaluate: %v")))) |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
679 :group 'sh-script) |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
680 |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
681 |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
682 (defcustom sh-other-keywords |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
683 '((bash sh-append bourne |
51515
6d06c54cda5d
Fix bug in "Options Loop" skeleton for ksh. Add newlines to a few skeletons,
Juanma Barranquero <lekktu@gmail.com>
parents:
51379
diff
changeset
|
684 "bye" "logout" "select") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
685 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
686 ;; The next entry is only used for defining the others |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
687 (bourne sh-append sh |
16810
20dc495230a0
(sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents:
16552
diff
changeset
|
688 "function") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
689 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
690 (csh sh-append shell |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
691 "breaksw" "default" "end" "endif" "endsw" "foreach" "goto" |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
692 "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
|
693 |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
694 (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
|
695 "return" "throw" "while") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
696 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
697 (ksh88 sh-append bourne |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
698 "select") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
699 |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
700 (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
|
701 "while") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
702 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
703 (sh sh-append shell |
16810
20dc495230a0
(sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents:
16552
diff
changeset
|
704 "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
|
705 |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
706 ;; 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
|
707 (shell "break" "case" "continue" "exec" "exit") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
708 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
709 (zsh sh-append bash |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
710 "select")) |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
711 "*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
|
712 See `sh-feature'." |
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
713 :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
|
714 (choice (repeat string) |
54158
43e09e943479
(sh-shell-arg, sh-require-final-newline, sh-assignment-regexp, sh-builtins)
Eli Zaretskii <eliz@gnu.org>
parents:
53419
diff
changeset
|
715 (sexp :format "Evaluate: %v")))) |
17407
ae0ba78d6c07
Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17356
diff
changeset
|
716 :group 'sh-script) |
6463 | 717 |
718 | |
719 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
720 (defvar sh-variables |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
721 '((bash sh-append sh |
52322
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
722 "allow_null_glob_expansion" "auto_resume" "BASH" "BASH_ENV" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
723 "BASH_VERSINFO" "BASH_VERSION" "cdable_vars" "COMP_CWORD" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
724 "COMP_LINE" "COMP_POINT" "COMP_WORDS" "COMPREPLY" "DIRSTACK" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
725 "ENV" "EUID" "FCEDIT" "FIGNORE" "FUNCNAME" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
726 "glob_dot_filenames" "GLOBIGNORE" "GROUPS" "histchars" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
727 "HISTCMD" "HISTCONTROL" "HISTFILE" "HISTFILESIZE" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
728 "HISTIGNORE" "history_control" "HISTSIZE" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
729 "hostname_completion_file" "HOSTFILE" "HOSTTYPE" "IGNOREEOF" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
730 "ignoreeof" "INPUTRC" "LINENO" "MACHTYPE" "MAIL_WARNING" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
731 "noclobber" "nolinks" "notify" "no_exit_on_failed_exec" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
732 "NO_PROMPT_VARS" "OLDPWD" "OPTERR" "OSTYPE" "PIPESTATUS" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
733 "PPID" "POSIXLY_CORRECT" "PROMPT_COMMAND" "PS3" "PS4" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
734 "pushd_silent" "PWD" "RANDOM" "REPLY" "SECONDS" "SHELLOPTS" |
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
735 "SHLVL" "TIMEFORMAT" "TMOUT" "UID") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
736 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
737 (csh sh-append shell |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
738 "argv" "cdpath" "child" "echo" "histchars" "history" "home" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
739 "ignoreeof" "mail" "noclobber" "noglob" "nonomatch" "path" "prompt" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
740 "shell" "status" "time" "verbose") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
741 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
742 (es sh-append shell |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
743 "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
|
744 "pid" "prompt" "signals") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
745 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
746 (jcsh sh-append csh |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
747 "notify") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
748 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
749 (ksh88 sh-append sh |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
750 "ENV" "ERRNO" "FCEDIT" "FPATH" "HISTFILE" "HISTSIZE" "LINENO" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
751 "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
|
752 "TMOUT") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
753 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
754 (oash sh-append sh |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
755 "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
|
756 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
757 (rc sh-append shell |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
758 "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
|
759 "prompt" "status") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
760 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
761 (sh sh-append shell |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
762 "CDPATH" "IFS" "OPTARG" "OPTIND" "PS1" "PS2") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
763 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
764 ;; 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
|
765 (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
|
766 "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
|
767 "LINES" "LOGNAME" "MAIL" "MAILCHECK" "MAILPATH" "PAGER" "PATH" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
768 "SHELL" "TERM" "TERMCAP" "TERMINFO" "VISUAL") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
769 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
770 (tcsh sh-append csh |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
771 "addsuffix" "ampm" "autocorrect" "autoexpand" "autolist" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
772 "autologout" "chase_symlinks" "correct" "dextract" "edit" "el" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
773 "fignore" "gid" "histlit" "HOST" "HOSTTYPE" "HPATH" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
774 "ignore_symlinks" "listjobs" "listlinks" "listmax" "matchbeep" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
775 "nobeep" "NOREBIND" "oid" "printexitvalue" "prompt2" "prompt3" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
776 "pushdsilent" "pushdtohome" "recexact" "recognize_only_executables" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
777 "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
|
778 "tperiod" "tty" "uid" "version" "visiblebell" "watch" "who" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
779 "wordchars") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
780 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
781 (zsh sh-append ksh88 |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
782 "BAUD" "bindcmds" "cdpath" "DIRSTACKSIZE" "fignore" "FIGNORE" "fpath" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
783 "HISTCHARS" "hostcmds" "hosts" "HOSTS" "LISTMAX" "LITHISTSIZE" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
784 "LOGCHECK" "mailpath" "manpath" "NULLCMD" "optcmds" "path" "POSTEDIT" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
785 "prompt" "PROMPT" "PROMPT2" "PROMPT3" "PROMPT4" "psvar" "PSVAR" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
786 "READNULLCMD" "REPORTTIME" "RPROMPT" "RPS1" "SAVEHIST" "SPROMPT" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
787 "STTY" "TIMEFMT" "TMOUT" "TMPPREFIX" "varcmds" "watch" "WATCH" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
788 "WATCHFMT" "WORDCHARS" "ZDOTDIR")) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
789 "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
|
790 See `sh-feature'.") |
6463 | 791 |
33430
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
792 |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
793 ;; Font-Lock support |
33430
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
794 |
63455
1589bde025e5
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-414
Miles Bader <miles@gnu.org>
parents:
62772
diff
changeset
|
795 (defface sh-heredoc |
61394
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61316
diff
changeset
|
796 '((((min-colors 88) (class color) |
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61316
diff
changeset
|
797 (background dark)) |
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61316
diff
changeset
|
798 (:foreground "yellow1" :weight bold)) |
31aa9a390538
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents:
61316
diff
changeset
|
799 (((class color) |
33430
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
800 (background dark)) |
42456
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
42075
diff
changeset
|
801 (:foreground "yellow" :weight bold)) |
33430
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
802 (((class color) |
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
803 (background light)) |
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
804 (:foreground "tan" )) |
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
805 (t |
42456
8a4077ab418c
(various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents:
42075
diff
changeset
|
806 (:weight bold))) |
33430
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
807 "Face to show a here-document" |
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
808 :group 'sh-indentation) |
63455
1589bde025e5
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-414
Miles Bader <miles@gnu.org>
parents:
62772
diff
changeset
|
809 ;; backward-compatibility alias |
1589bde025e5
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-414
Miles Bader <miles@gnu.org>
parents:
62772
diff
changeset
|
810 (put 'sh-heredoc-face 'face-alias 'sh-heredoc) |
1589bde025e5
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-414
Miles Bader <miles@gnu.org>
parents:
62772
diff
changeset
|
811 (defvar sh-heredoc-face 'sh-heredoc) |
6463 | 812 |
61316
283f977b41fb
(sh-builtins) <bash>: Add `caller'.
Glenn Morris <rgm@gnu.org>
parents:
60917
diff
changeset
|
813 (defface sh-escaped-newline '((t :inherit font-lock-string-face)) |
283f977b41fb
(sh-builtins) <bash>: Add `caller'.
Glenn Morris <rgm@gnu.org>
parents:
60917
diff
changeset
|
814 "Face used for (non-escaped) backslash at end of a line in Shell-script mode." |
283f977b41fb
(sh-builtins) <bash>: Add `caller'.
Glenn Morris <rgm@gnu.org>
parents:
60917
diff
changeset
|
815 :group 'sh-script |
283f977b41fb
(sh-builtins) <bash>: Add `caller'.
Glenn Morris <rgm@gnu.org>
parents:
60917
diff
changeset
|
816 :version "22.1") |
6463 | 817 |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
818 (defvar sh-font-lock-keywords |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
819 '((csh sh-append shell |
52619
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
820 ("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1 |
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
821 font-lock-variable-name-face)) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
822 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
823 (es sh-append executable-font-lock-keywords |
52619
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
824 ("\\$#?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\)" 1 |
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
825 font-lock-variable-name-face)) |
6463 | 826 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
827 (rc sh-append es) |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
828 |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
829 (sh 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
|
830 ;; Variable names. |
52619
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
831 ("\\$\\({#?\\)?\\([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
|
832 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
|
833 ;; Function names. |
52619
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
834 ("^\\(\\sw+\\)[ \t]*(" 1 font-lock-function-name-face) |
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
835 ("\\<\\(function\\)\\>[ \t]*\\(\\sw+\\)?" |
62080
2922c607db05
(sh-font-lock-keywords): Use font-lock-negation-char-face.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
61534
diff
changeset
|
836 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)) |
2922c607db05
(sh-font-lock-keywords): Use font-lock-negation-char-face.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
61534
diff
changeset
|
837 ("\\(?:^\\s *\\|[[();&|]\\s *\\|\\(?:\\s +-[ao]\\|if\\|else\\|then\\|while\\|do\\)\\s +\\)\\(!\\)" |
2922c607db05
(sh-font-lock-keywords): Use font-lock-negation-char-face.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
61534
diff
changeset
|
838 1 font-lock-negation-char-face)) |
6463 | 839 |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
840 ;; The next entry is only used for defining the others |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
841 (shell sh-append executable-font-lock-keywords |
52411
9db479d16349
(sh-font-lock-keywords): Use something other than
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
842 ;; Using font-lock-string-face here confuses sh-get-indent-info. |
61316
283f977b41fb
(sh-builtins) <bash>: Add `caller'.
Glenn Morris <rgm@gnu.org>
parents:
60917
diff
changeset
|
843 ("\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\)$" 3 'sh-escaped-newline) |
52619
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
844 ("\\\\[^A-Za-z0-9]" 0 font-lock-string-face) |
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
845 ("\\${?\\([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
|
846 font-lock-variable-name-face)) |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
847 (rpm sh-append rpm2 |
52619
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
848 ("%{?\\(\\sw+\\)" 1 font-lock-keyword-face)) |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
849 (rpm2 sh-append shell |
52619
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
850 ("^\\(\\sw+\\):" 1 font-lock-variable-name-face))) |
18024
58afe194f1bd
Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents:
17531
diff
changeset
|
851 "Default expressions to highlight in Shell Script modes. See `sh-feature'.") |
6463 | 852 |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
853 (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
|
854 '((sh "[ \t]in\\>")) |
18024
58afe194f1bd
Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents:
17531
diff
changeset
|
855 "Subdued level highlighting for Shell Script modes.") |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
856 |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
857 (defvar sh-font-lock-keywords-2 () |
18024
58afe194f1bd
Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents:
17531
diff
changeset
|
858 "Gaudy level highlighting for Shell Script modes.") |
6463 | 859 |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
860 ;; 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
|
861 ;; 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
|
862 (defconst sh-st-punc (string-to-syntax ".")) |
36631
d5345decc9a4
(sh-st-symbol): New symbol.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35180
diff
changeset
|
863 (defconst sh-st-symbol (string-to-syntax "_")) |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
864 (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
|
865 |
59622
5ec981fa30e5
(sh-here-doc-open-re): Don't allow `|' or other
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59566
diff
changeset
|
866 (defconst sh-here-doc-open-re "<<-?\\s-*\\\\?\\(\\(?:['\"][^'\"]+['\"]\\|\\sw\\)+\\).*\\(\n\\)") |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
867 |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
868 (defvar sh-here-doc-markers nil) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
869 (make-variable-buffer-local 'sh-here-doc-markers) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
870 (defvar sh-here-doc-re sh-here-doc-open-re) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
871 (make-variable-buffer-local 'sh-here-doc-re) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
872 |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
873 (defun sh-font-lock-close-heredoc (bol eof indented) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
874 "Determine the syntax of the \\n after an EOF. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
875 If non-nil INDENTED indicates that the EOF was indented." |
40336
8f116e4bd2cd
(sh-font-lock-close-heredoc): check the args for being non-nil
Sam Steingold <sds@gnu.org>
parents:
40335
diff
changeset
|
876 (let* ((eof-re (if eof (regexp-quote eof) "")) |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
877 ;; A rough regexp that should find the opening <<EOF back. |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
878 (sre (concat "<<\\(-?\\)\\s-*['\"\\]?" |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
879 ;; Use \s| to cheaply check it's an open-heredoc. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
880 eof-re "['\"]?\\([ \t|;&)<>].*\\)?\\s|")) |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
881 ;; A regexp that will find other EOFs. |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
882 (ere (concat "^" (if indented "[ \t]*") eof-re "\n")) |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
883 (start (save-excursion |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
884 (goto-char bol) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
885 (re-search-backward (concat sre "\\|" ere) nil t)))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
886 ;; If subgroup 1 matched, we found an open-heredoc, otherwise we first |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
887 ;; found a close-heredoc which makes the current close-heredoc inoperant. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
888 (cond |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
889 ((when (and start (match-end 1) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
890 (not (and indented (= (match-beginning 1) (match-end 1)))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
891 (not (sh-in-comment-or-string (match-beginning 0)))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
892 ;; Make sure our `<<' is not the EOF1 of a `cat <<EOF1 <<EOF2'. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
893 (save-excursion |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
894 (goto-char start) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
895 (setq start (line-beginning-position 2)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
896 (while |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
897 (progn |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
898 (re-search-forward "<<") ; Skip ourselves. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
899 (and (re-search-forward sh-here-doc-open-re start 'move) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
900 (goto-char (match-beginning 0)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
901 (sh-in-comment-or-string (point))))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
902 ;; No <<EOF2 found after our <<. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
903 (= (point) start))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
904 sh-here-doc-syntax) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
905 ((not (or start (save-excursion (re-search-forward sre nil t)))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
906 ;; There's no <<EOF either before or after us, |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
907 ;; so we should remove ourselves from font-lock's keywords. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
908 (setq sh-here-doc-markers (delete eof sh-here-doc-markers)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
909 (setq sh-here-doc-re |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
910 (concat sh-here-doc-open-re "\\|^\\([ \t]*\\)" |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
911 (regexp-opt sh-here-doc-markers t) "\\(\n\\)")) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
912 nil)))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
913 |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
914 (defun sh-font-lock-open-heredoc (start string) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
915 "Determine the syntax of the \\n after a <<EOF. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
916 START is the position of <<. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
917 STRING is the actual word used as delimiter (f.ex. \"EOF\"). |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
918 INDENTED is non-nil if the here document's content (and the EOF mark) can |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
919 be indented (i.e. a <<- was used rather than just <<)." |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
920 (unless (or (memq (char-before start) '(?< ?>)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
921 (sh-in-comment-or-string start)) |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
922 ;; 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
|
923 ;; font-lock keywords to detect the end of this here document. |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
924 (let ((str (replace-regexp-in-string "['\"]" "" string))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
925 (unless (member str sh-here-doc-markers) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
926 (push str sh-here-doc-markers) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
927 (setq sh-here-doc-re |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
928 (concat sh-here-doc-open-re "\\|^\\([ \t]*\\)" |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
929 (regexp-opt sh-here-doc-markers t) "\\(\n\\)")))) |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
930 sh-here-doc-syntax)) |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
931 |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
932 (defun sh-font-lock-here-doc (limit) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
933 "Search for a heredoc marker." |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
934 ;; This looks silly, but it's because `sh-here-doc-re' keeps changing. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
935 (re-search-forward sh-here-doc-re limit t)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
936 |
51379
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
937 (defun sh-is-quoted-p (pos) |
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
938 (and (eq (char-before pos) ?\\) |
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
939 (not (sh-is-quoted-p (1- pos))))) |
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
940 |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
941 (defun sh-font-lock-paren (start) |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
942 (save-excursion |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
943 (goto-char start) |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
944 ;; Skip through all patterns |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
945 (while |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
946 (progn |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
947 (forward-comment (- (point-max))) |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
948 ;; Skip through one pattern |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
949 (while |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
950 (or (/= 0 (skip-syntax-backward "w_")) |
54282
d11df80991d8
(sh-font-lock-paren): Add @ in case patterns.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54158
diff
changeset
|
951 (/= 0 (skip-chars-backward "?[]*@/\\")) |
51379
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
952 (and (sh-is-quoted-p (1- (point))) |
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
953 (goto-char (- (point) 2))) |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
954 (when (memq (char-before) '(?\" ?\')) |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
955 (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
|
956 (error nil))))) |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
957 (forward-comment (- (point-max))) |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
958 (when (eq (char-before) ?|) |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
959 (backward-char 1) t))) |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
960 (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
|
961 sh-st-punc))) |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
962 |
18024
58afe194f1bd
Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents:
17531
diff
changeset
|
963 (defconst sh-font-lock-syntactic-keywords |
36631
d5345decc9a4
(sh-st-symbol): New symbol.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35180
diff
changeset
|
964 ;; A `#' begins a comment when it is unquoted and at the beginning of a |
d5345decc9a4
(sh-st-symbol): New symbol.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35180
diff
changeset
|
965 ;; word. In the shell, words are separated by metacharacters. |
d5345decc9a4
(sh-st-symbol): New symbol.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35180
diff
changeset
|
966 ;; The list of special chars is taken from the single-unix spec |
d5345decc9a4
(sh-st-symbol): New symbol.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35180
diff
changeset
|
967 ;; of the shell command language (under `quoting') but with `$' removed. |
d5345decc9a4
(sh-st-symbol): New symbol.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35180
diff
changeset
|
968 `(("[^|&;<>()`\\\"' \t\n]\\(#+\\)" 1 ,sh-st-symbol) |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
969 ;; Find HEREDOC starters and add a corresponding rule for the ender. |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
970 (sh-font-lock-here-doc |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
971 (2 (sh-font-lock-open-heredoc |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
972 (match-beginning 0) (match-string 1)) nil t) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
973 (5 (sh-font-lock-close-heredoc |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
974 (match-beginning 0) (match-string 4) |
40336
8f116e4bd2cd
(sh-font-lock-close-heredoc): check the args for being non-nil
Sam Steingold <sds@gnu.org>
parents:
40335
diff
changeset
|
975 (and (match-beginning 3) (/= (match-beginning 3) (match-end 3)))) |
8f116e4bd2cd
(sh-font-lock-close-heredoc): check the args for being non-nil
Sam Steingold <sds@gnu.org>
parents:
40335
diff
changeset
|
976 nil t)) |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
977 ;; Distinguish the special close-paren in `case'. |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
978 (")" 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
|
979 |
33430
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
980 (defun sh-font-lock-syntactic-face-function (state) |
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
981 (if (nth 3 state) |
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
982 (if (char-valid-p (nth 3 state)) |
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
983 font-lock-string-face |
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
984 sh-heredoc-face) |
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
985 font-lock-comment-face)) |
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
986 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
987 (defgroup sh-indentation nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
988 "Variables controlling indentation in shell scripts. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
989 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
990 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
|
991 `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
|
992 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
|
993 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
|
994 :group 'sh-script) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
995 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
996 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
997 (defcustom sh-set-shell-hook nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
998 "*Hook run by `sh-set-shell'." |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
999 :type 'hook |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1000 :group 'sh-script) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1001 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1002 (defcustom sh-mode-hook nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1003 "*Hook run by `sh-mode'." |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1004 :type 'hook |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1005 :group 'sh-script) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1006 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1007 (defcustom sh-learn-basic-offset nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1008 "*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
|
1009 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1010 nil mean: never. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1011 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
|
1012 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
|
1013 :type '(choice |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1014 (const :tag "Never" nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1015 (const :tag "Only if sure" t) |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1016 (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
|
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-popup-occur-buffer nil |
62309 | 1020 "*Controls when `sh-learn-buffer-indent' pops the `*indent*' buffer. |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1021 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
|
1022 are conflicts." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1023 :type '(choice |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1024 (const :tag "Only when there are conflicts." nil) |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1025 (const :tag "Always" t)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1026 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1027 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1028 (defcustom sh-blink t |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1029 "*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
|
1030 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
|
1031 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
|
1032 always the case." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1033 :type 'boolean |
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-first-lines-indent 0 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1037 "*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
|
1038 Usually 0 meaning first column. |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1039 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
|
1040 :type '(choice |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1041 (const :tag "Leave as is" nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1042 (integer :tag "Column number" |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1043 :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
|
1044 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1045 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1046 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1047 (defcustom sh-basic-offset 4 |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1048 "*The default indentation increment. |
62309 | 1049 This value is used for the `+' and `-' symbols in an indentation variable." |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1050 :type 'integer |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1051 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1052 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1053 (defcustom sh-indent-comment nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1054 "*How a comment line is to be indented. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1055 nil means leave it as it is; |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1056 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
|
1057 non-comment line; |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1058 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
|
1059 :type '(choice |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1060 (const :tag "Leave as is." nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1061 (const :tag "Indent as a normal line." t) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1062 (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
|
1063 :tag "Indent to column number.") ) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1064 :group 'sh-indentation) |
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 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1067 (defvar sh-debug nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1068 "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
|
1069 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1070 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1071 ;; 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
|
1072 ;; (defun sh-debug (&rest args) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1073 ;; "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
|
1074 ;; (if sh-debug |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1075 ;; (apply 'message args))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1076 (defmacro sh-debug (&rest args)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1077 |
29422
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1078 (defconst sh-symbol-list |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1079 '((const :tag "+ " :value + |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1080 :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
|
1081 (const :tag "- " :value - |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1082 :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
|
1083 (const :tag "++" :value ++ |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1084 :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
|
1085 (const :tag "--" :value -- |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1086 :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
|
1087 (const :tag "* " :value * |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1088 :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
|
1089 (const :tag "/ " :value / |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1090 :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
|
1091 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1092 (defcustom sh-indent-for-else 0 |
62309 | 1093 "*How much to indent an `else' relative to its `if'. Usually 0." |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1094 :type `(choice |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1095 (integer :menu-tag "A number (positive=>indent right)" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1096 :tag "A number") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1097 (const :tag "--") ;; separator! |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1098 ,@ sh-symbol-list |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1099 ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1100 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1101 |
29422
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1102 (defconst sh-number-or-symbol-list |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1103 (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
|
1104 :tag "A number") |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1105 (const :tag "--")) ; separator |
29422
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1106 sh-symbol-list)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1107 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1108 (defcustom sh-indent-for-fi 0 |
62309 | 1109 "*How much to indent a `fi' relative to its `if'. Usually 0." |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1110 :type `(choice ,@ sh-number-or-symbol-list ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1111 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1112 |
62309 | 1113 (defcustom sh-indent-for-done 0 |
1114 "*How much to indent a `done' relative to its matching stmt. Usually 0." | |
25986
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 (defcustom sh-indent-after-else '+ |
62309 | 1119 "*How much to indent a statement after an `else' statement." |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1120 :type `(choice ,@ sh-number-or-symbol-list ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1121 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1122 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1123 (defcustom sh-indent-after-if '+ |
62309 | 1124 "*How much to indent a statement after an `if' statement. |
1125 This includes lines after `else' and `elif' statements, too, but | |
1126 does not affect the `else', `elif' or `fi' statements themselves." | |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1127 :type `(choice ,@ sh-number-or-symbol-list ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1128 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1129 |
58767
d2c6a8b592f2
(sh-indent-for-then): Change default.
Richard M. Stallman <rms@gnu.org>
parents:
57159
diff
changeset
|
1130 (defcustom sh-indent-for-then 0 |
62309 | 1131 "*How much to indent a `then' relative to its `if'." |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1132 :type `(choice ,@ sh-number-or-symbol-list ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1133 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1134 |
62214
e451c7eb2d24
(sh-indent-for-do): Default to 0.
Richard M. Stallman <rms@gnu.org>
parents:
62080
diff
changeset
|
1135 (defcustom sh-indent-for-do 0 |
62309 | 1136 "*How much to indent a `do' statement. |
62310 | 1137 This is relative to the statement before the `do', typically a |
1138 `while', `until', `for', `repeat' or `select' statement." | |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1139 :type `(choice ,@ sh-number-or-symbol-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1140 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1141 |
62309 | 1142 (defcustom sh-indent-after-do '+ |
1143 "*How much to indent a line after a `do' statement. | |
1144 This is used when the `do' is the first word of the line. | |
62310 | 1145 This is relative to the statement before the `do', typically a |
1146 `while', `until', `for', `repeat' or `select' statement." | |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1147 :type `(choice ,@ sh-number-or-symbol-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1148 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1149 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1150 (defcustom sh-indent-after-loop-construct '+ |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1151 "*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
|
1152 |
62309 | 1153 This variable is used when the keyword `do' is on the same line as the |
1154 loop statement (e.g., `until', `while' or `for'). | |
1155 If the `do' is on a line by itself, then `sh-indent-after-do' is used instead." | |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1156 :type `(choice ,@ sh-number-or-symbol-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1157 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1158 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1159 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1160 (defcustom sh-indent-after-done 0 |
62309 | 1161 "*How much to indent a statement after a `done' keyword. |
1162 Normally this is 0, which aligns the `done' to the matching | |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1163 looping construct line. |
62309 | 1164 Setting it non-zero allows you to have the `do' statement on a line |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1165 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
|
1166 :type `(choice ,@ sh-number-or-symbol-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1167 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1168 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1169 (defcustom sh-indent-for-case-label '+ |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1170 "*How much to indent a case label statement. |
62309 | 1171 This is relative to the line containing the `case' statement." |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1172 :type `(choice ,@ sh-number-or-symbol-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1173 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1174 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1175 (defcustom sh-indent-for-case-alt '++ |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1176 "*How much to indent statements after the case label. |
62309 | 1177 This is relative to the line containing the `case' statement." |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1178 :type `(choice ,@ sh-number-or-symbol-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1179 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1180 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1181 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1182 (defcustom sh-indent-for-continuation '+ |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1183 "*How much to indent for a continuation statement." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1184 :type `(choice ,@ sh-number-or-symbol-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1185 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1186 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1187 (defcustom sh-indent-after-open '+ |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1188 "*How much to indent after a line with an opening parenthesis or brace. |
62309 | 1189 For an open paren after a function, `sh-indent-after-function' is used." |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1190 :type `(choice ,@ sh-number-or-symbol-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1191 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1192 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1193 (defcustom sh-indent-after-function '+ |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1194 "*How much to indent after a function line." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1195 :type `(choice ,@ sh-number-or-symbol-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1196 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1197 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1198 ;; These 2 are for the rc shell: |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1199 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1200 (defcustom sh-indent-after-switch '+ |
62309 | 1201 "*How much to indent a `case' statement relative to the `switch' statement. |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1202 This is for the rc shell." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1203 :type `(choice ,@ sh-number-or-symbol-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1204 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1205 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1206 (defcustom sh-indent-after-case '+ |
62309 | 1207 "*How much to indent a statement relative to the `case' statement. |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1208 This is for the rc shell." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1209 :type `(choice ,@ sh-number-or-symbol-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1210 :group 'sh-indentation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1211 |
59566
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
1212 (defcustom sh-backslash-column 48 |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
1213 "*Column in which `sh-backslash-region' inserts backslashes." |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
1214 :type 'integer |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
1215 :group 'sh) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
1216 |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
1217 (defcustom sh-backslash-align t |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
1218 "*If non-nil, `sh-backslash-region' will align backslashes." |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
1219 :type 'boolean |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
1220 :group 'sh) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
1221 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1222 ;; 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
|
1223 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1224 (defun sh-mkword-regexpr (word) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1225 "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
|
1226 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
|
1227 punctuation characters like '-'." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1228 (concat word "\\([^-a-z0-9_]\\|$\\)")) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1229 |
29422
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1230 (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
|
1231 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1232 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1233 (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
|
1234 '((sh . ( "while" "until" "for" ) ) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1235 (bash . ( "while" "until" "for" "select" ) ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1236 (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
|
1237 (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
|
1238 "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
|
1239 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1240 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1241 (defconst sh-indent-supported |
29422
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1242 '((sh . t) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1243 (csh . nil) |
29422
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1244 (rc . t)) |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1245 "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
|
1246 |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1247 (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
|
1248 "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
|
1249 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1250 (defconst sh-var-list |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1251 '( |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1252 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
|
1253 sh-indent-after-do sh-indent-after-done |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1254 sh-indent-after-else |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1255 sh-indent-after-if |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1256 sh-indent-after-loop-construct |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1257 sh-indent-after-open |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1258 sh-indent-comment |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1259 sh-indent-for-case-alt |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1260 sh-indent-for-case-label |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1261 sh-indent-for-continuation |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1262 sh-indent-for-do |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1263 sh-indent-for-done |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1264 sh-indent-for-else |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1265 sh-indent-for-fi |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1266 sh-indent-for-then |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1267 ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1268 "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
|
1269 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
|
1270 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
|
1271 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1272 (defvar sh-make-vars-local t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1273 "*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
|
1274 If non-nil, indentation variables are made local initially. |
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1275 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
|
1276 command `sh-make-vars-local'. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1277 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
|
1278 frequently editing existing scripts with different styles.") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1279 |
6463 | 1280 |
1281 ;; mode-command and utility functions | |
1282 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1283 ;;;###autoload |
41348
b46a4ee1a05d
(sh-mode): Don't use define-derived-mode.
Richard M. Stallman <rms@gnu.org>
parents:
41233
diff
changeset
|
1284 (defun sh-mode () |
6463 | 1285 "Major mode for editing shell scripts. |
1286 This mode works for many shells, since they all have roughly the same syntax, | |
1287 as far as commands, arguments, variables, pipes, comments etc. are concerned. | |
1288 Unless the file's magic number indicates the shell, your usual shell is | |
1289 assumed. Since filenames rarely give a clue, they are not further analyzed. | |
1290 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1291 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
|
1292 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
|
1293 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
|
1294 shell-specific features. |
6463 | 1295 |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1296 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
|
1297 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
|
1298 following commands are available, based on the current shell's syntax: |
6463 | 1299 |
1300 \\[sh-case] case statement | |
1301 \\[sh-for] for loop | |
1302 \\[sh-function] function definition | |
1303 \\[sh-if] if statement | |
1304 \\[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
|
1305 \\[sh-while-getopts] while getopts loop |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1306 \\[sh-repeat] repeat loop |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1307 \\[sh-select] select loop |
6463 | 1308 \\[sh-until] until loop |
1309 \\[sh-while] while loop | |
1310 | |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1311 For sh and rc shells indentation commands are: |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1312 \\[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
|
1313 \\[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
|
1314 \\[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
|
1315 would indent to the way it currently is. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1316 \\[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
|
1317 buffer indents as it currently is indented. |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1318 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1319 |
6463 | 1320 \\[backward-delete-char-untabify] Delete backward one position, even if it was a tab. |
1321 \\[sh-newline-and-indent] Delete unquoted space and indent new line same as this one. | |
1322 \\[sh-end-of-command] Go to end of successive commands. | |
1323 \\[sh-beginning-of-command] Go to beginning of successive commands. | |
1324 \\[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
|
1325 \\[sh-execute-region] Have optional header and region be executed in a subshell. |
6463 | 1326 |
1327 \\[sh-maybe-here-document] Without prefix, following an unquoted < inserts here document. | |
40340
5800d6cc4718
sugar: escape a "{" in the first column to pacify font-lock
Sam Steingold <sds@gnu.org>
parents:
40336
diff
changeset
|
1328 \{, (, [, ', \", ` |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1329 Unless quoted with \\, insert the pairs {}, (), [], or '', \"\", ``. |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1330 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1331 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
|
1332 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
|
1333 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
|
1334 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1335 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
|
1336 with your script for an edit-interpret-debug cycle." |
41348
b46a4ee1a05d
(sh-mode): Don't use define-derived-mode.
Richard M. Stallman <rms@gnu.org>
parents:
41233
diff
changeset
|
1337 (interactive) |
b46a4ee1a05d
(sh-mode): Don't use define-derived-mode.
Richard M. Stallman <rms@gnu.org>
parents:
41233
diff
changeset
|
1338 (kill-all-local-variables) |
b46a4ee1a05d
(sh-mode): Don't use define-derived-mode.
Richard M. Stallman <rms@gnu.org>
parents:
41233
diff
changeset
|
1339 (setq major-mode 'sh-mode |
b46a4ee1a05d
(sh-mode): Don't use define-derived-mode.
Richard M. Stallman <rms@gnu.org>
parents:
41233
diff
changeset
|
1340 mode-name "Shell-script") |
b46a4ee1a05d
(sh-mode): Don't use define-derived-mode.
Richard M. Stallman <rms@gnu.org>
parents:
41233
diff
changeset
|
1341 (use-local-map sh-mode-map) |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1342 (make-local-variable 'skeleton-end-hook) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1343 (make-local-variable 'paragraph-start) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1344 (make-local-variable 'paragraph-separate) |
6463 | 1345 (make-local-variable 'comment-start) |
1346 (make-local-variable 'comment-start-skip) | |
1347 (make-local-variable 'require-final-newline) | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1348 (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
|
1349 (make-local-variable 'sh-shell-file) |
6463 | 1350 (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
|
1351 (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
|
1352 (make-local-variable 'skeleton-pair-filter) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1353 (make-local-variable 'comint-dynamic-complete-functions) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1354 (make-local-variable 'comint-prompt-regexp) |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1355 (make-local-variable 'font-lock-defaults) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1356 (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
|
1357 (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
|
1358 (make-local-variable 'sh-shell-variables) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
1359 (make-local-variable 'sh-shell-variables-initialized) |
20395
2bd6621697d5
(sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
20385
diff
changeset
|
1360 (make-local-variable 'imenu-generic-expression) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1361 (make-local-variable 'sh-indent-supported-here) |
33430
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
1362 (setq skeleton-end-hook (lambda () |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1363 (or (eolp) (newline) (indent-relative))) |
13705
4111cc3136d1
(sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents:
13510
diff
changeset
|
1364 paragraph-start (concat page-delimiter "\\|$") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1365 paragraph-separate paragraph-start |
6463 | 1366 comment-start "# " |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1367 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
|
1368 ;; 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
|
1369 comint-prompt-regexp "^[ \t]*" |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1370 font-lock-defaults |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
1371 `((sh-font-lock-keywords |
18024
58afe194f1bd
Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents:
17531
diff
changeset
|
1372 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
|
1373 nil nil |
58afe194f1bd
Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents:
17531
diff
changeset
|
1374 ((?/ . "w") (?~ . "w") (?. . "w") (?- . "w") (?_ . "w")) nil |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1375 (font-lock-syntactic-keywords . sh-font-lock-syntactic-keywords) |
33430
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
1376 (font-lock-syntactic-face-function |
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
1377 . 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
|
1378 skeleton-pair-alist '((?` _ ?`)) |
3b9dcd964c66
(sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents:
12863
diff
changeset
|
1379 skeleton-pair-filter 'sh-quoted-p |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1380 skeleton-further-elements '((< '(- (min sh-indentation |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1381 (current-column))))) |
12887
cbed067bf52d
(sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents:
12864
diff
changeset
|
1382 skeleton-filter 'sh-feature |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1383 skeleton-newline-indent-rigidly t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1384 sh-indent-supported-here nil) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1385 (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
|
1386 ;; 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
|
1387 ;; on the shell thus determined. |
fe3d32bca2c5
(sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents:
16535
diff
changeset
|
1388 (let ((interpreter |
fe3d32bca2c5
(sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents:
16535
diff
changeset
|
1389 (save-excursion |
fe3d32bca2c5
(sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents:
16535
diff
changeset
|
1390 (goto-char (point-min)) |
23501
f12ae4499ae0
(sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents:
23341
diff
changeset
|
1391 (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
|
1392 (match-string 2)) |
e1cb8de8ffb2
(sh-mode): Do not fail if buffer has no
Karl Heuer <kwzh@gnu.org>
parents:
23869
diff
changeset
|
1393 ((and buffer-file-name |
62550
4f78132b042b
(sh-mode, sh-get-word): Minor regexp fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
62310
diff
changeset
|
1394 (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
|
1395 "rpm"))))) |
42075
a39583392219
(sh-mode): Run sh-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
41349
diff
changeset
|
1396 (sh-set-shell (or interpreter sh-shell-file) nil nil)) |
62772
f2892faa87d4
* progmodes/ada-mode.el (ada-mode):
Lute Kamstra <lute@gnu.org>
parents:
62550
diff
changeset
|
1397 (run-mode-hooks 'sh-mode-hook)) |
33430
d2648645aa9b
(sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32728
diff
changeset
|
1398 |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1399 ;;;###autoload |
6463 | 1400 (defalias 'shell-script-mode 'sh-mode) |
1401 | |
1402 | |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1403 (defun sh-font-lock-keywords (&optional keywords) |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1404 "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
|
1405 This adds rules for comments and assignments." |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1406 (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
|
1407 (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
|
1408 (lambda (list) |
8b4cdcbaf071
(sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents:
23501
diff
changeset
|
1409 `((,(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
|
1410 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
|
1411 ,@keywords |
8b4cdcbaf071
(sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents:
23501
diff
changeset
|
1412 ,@list))))) |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1413 |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1414 (defun sh-font-lock-keywords-1 (&optional builtins) |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1415 "Function to get better fontification including keywords." |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1416 (let ((keywords (concat "\\([;(){}`|&]\\|^\\)[ \t]*\\(\\(" |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1417 (regexp-opt (sh-feature sh-leading-keywords) t) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1418 "[ \t]+\\)?" |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1419 (regexp-opt (append (sh-feature sh-leading-keywords) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1420 (sh-feature sh-other-keywords)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1421 t)))) |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1422 (sh-font-lock-keywords |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1423 `(,@(if builtins |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1424 `((,(concat keywords "[ \t]+\\)?" |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1425 (regexp-opt (sh-feature sh-builtins) t) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1426 "\\>") |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1427 (2 font-lock-keyword-face nil t) |
16478 | 1428 (6 font-lock-builtin-face)) |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1429 ,@(sh-feature sh-font-lock-keywords-2))) |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1430 (,(concat keywords "\\)\\>") |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1431 2 font-lock-keyword-face) |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1432 ,@(sh-feature sh-font-lock-keywords-1))))) |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1433 |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1434 (defun sh-font-lock-keywords-2 () |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1435 "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
|
1436 (sh-font-lock-keywords-1 t)) |
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
1437 |
6463 | 1438 |
29422
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1439 (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
|
1440 "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
|
1441 |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1442 (defvar sh-kw-alist nil |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1443 "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
|
1444 |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1445 ;; ( 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
|
1446 ;; 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
|
1447 ;; having 3 elements: |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1448 ;; a keyword |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1449 ;; 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
|
1450 ;; 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
|
1451 ;; 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
|
1452 ;; 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
|
1453 ;; 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
|
1454 ;; 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
|
1455 ;; 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
|
1456 ;; 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
|
1457 ;; 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
|
1458 ;; 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
|
1459 ;; `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
|
1460 ;; 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
|
1461 ;; 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
|
1462 ;; 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
|
1463 ;; for both. |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1464 ;; |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1465 (defconst sh-kw |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1466 '((sh |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1467 ("if" nil sh-handle-prev-if) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1468 ("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
|
1469 ("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
|
1470 ("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
|
1471 ("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
|
1472 ("(" nil sh-handle-prev-open) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1473 ("{" nil sh-handle-prev-open) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1474 ("[" nil sh-handle-prev-open) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1475 ("}" sh-handle-this-close nil) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1476 (")" sh-handle-this-close nil) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1477 ("]" sh-handle-this-close nil) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1478 ("case" nil sh-handle-prev-case) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1479 ("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
|
1480 (case-label nil sh-handle-after-case-label) ;; ??? |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1481 (";;" nil sh-handle-prev-case-alt-end) ;; ??? |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1482 ("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
|
1483 ("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
|
1484 |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1485 ;; 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
|
1486 ;; 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
|
1487 ;; these shells use. |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1488 (rc |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1489 ("{" nil sh-handle-prev-open) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1490 ("}" sh-handle-this-close nil) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1491 ("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
|
1492 |
be5a54fc840d
(sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29109
diff
changeset
|
1493 |
14148
fa30f7528502
(sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents:
14119
diff
changeset
|
1494 (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
|
1495 "Set this buffer's shell to SHELL (a string). |
42909
af3eb1ed8032
(sh-set-shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42456
diff
changeset
|
1496 When used interactively, insert the proper starting #!-line, |
af3eb1ed8032
(sh-set-shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42456
diff
changeset
|
1497 and make the visited file executable via `executable-set-magic', |
af3eb1ed8032
(sh-set-shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42456
diff
changeset
|
1498 perhaps querying depending on the value of `executable-query'. |
af3eb1ed8032
(sh-set-shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42456
diff
changeset
|
1499 |
af3eb1ed8032
(sh-set-shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42456
diff
changeset
|
1500 When this function is called noninteractively, INSERT-FLAG (the third |
af3eb1ed8032
(sh-set-shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42456
diff
changeset
|
1501 argument) controls whether to insert a #!-line and think about making |
af3eb1ed8032
(sh-set-shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42456
diff
changeset
|
1502 the visited file executable, and NO-QUERY-FLAG (the second argument) |
af3eb1ed8032
(sh-set-shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42456
diff
changeset
|
1503 controls whether to query about making the visited file executable. |
af3eb1ed8032
(sh-set-shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42456
diff
changeset
|
1504 |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1505 Calls the value of `sh-set-shell-hook' if set." |
49132
99f9777a831b
(sh-set-shell): Make sh-shell-file the default shell.
Juanma Barranquero <lekktu@gmail.com>
parents:
48032
diff
changeset
|
1506 (interactive (list (completing-read (format "Shell \(default %s\): " |
99f9777a831b
(sh-set-shell): Make sh-shell-file the default shell.
Juanma Barranquero <lekktu@gmail.com>
parents:
48032
diff
changeset
|
1507 sh-shell-file) |
99f9777a831b
(sh-set-shell): Make sh-shell-file the default shell.
Juanma Barranquero <lekktu@gmail.com>
parents:
48032
diff
changeset
|
1508 interpreter-mode-alist |
99f9777a831b
(sh-set-shell): Make sh-shell-file the default shell.
Juanma Barranquero <lekktu@gmail.com>
parents:
48032
diff
changeset
|
1509 (lambda (x) (eq (cdr x) 'sh-mode)) |
99f9777a831b
(sh-set-shell): Make sh-shell-file the default shell.
Juanma Barranquero <lekktu@gmail.com>
parents:
48032
diff
changeset
|
1510 nil nil nil sh-shell-file) |
14148
fa30f7528502
(sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents:
14119
diff
changeset
|
1511 (eq executable-query 'function) |
fa30f7528502
(sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents:
14119
diff
changeset
|
1512 t)) |
23589
660727693bf6
(sh-canonicalize-shell): Fix regexp.
Andreas Schwab <schwab@suse.de>
parents:
23511
diff
changeset
|
1513 (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
|
1514 (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
|
1515 (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
|
1516 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
|
1517 sh-shell)) |
16552
fe3d32bca2c5
(sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents:
16535
diff
changeset
|
1518 (if insert-flag |
fe3d32bca2c5
(sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents:
16535
diff
changeset
|
1519 (setq sh-shell-file |
fe3d32bca2c5
(sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents:
16535
diff
changeset
|
1520 (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
|
1521 no-query-flag insert-flag))) |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1522 (let ((tem (sh-feature sh-require-final-newline))) |
59251
84ede35ffeb4
(sh-require-final-newline):
Richard M. Stallman <rms@gnu.org>
parents:
58767
diff
changeset
|
1523 (if (eq tem t) |
84ede35ffeb4
(sh-require-final-newline):
Richard M. Stallman <rms@gnu.org>
parents:
58767
diff
changeset
|
1524 (setq require-final-newline mode-require-final-newline))) |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1525 (setq |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1526 comment-start-skip "#+[\t ]*" |
56688
6eee795cb9eb
(sh-set-shell): Use sh-mode-abbrev-table.
Richard M. Stallman <rms@gnu.org>
parents:
55119
diff
changeset
|
1527 local-abbrev-table sh-mode-abbrev-table |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1528 mode-line-process (format "[%s]" sh-shell) |
14195
df3c52ae5b14
(sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
1529 sh-shell-variables nil |
14418
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
1530 sh-shell-variables-initialized nil |
20395
2bd6621697d5
(sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
20385
diff
changeset
|
1531 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
|
1532 imenu-case-fold-search nil) |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1533 (make-local-variable 'sh-mode-syntax-table) |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1534 (let ((tem (sh-feature sh-mode-syntax-table-input))) |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1535 (setq sh-mode-syntax-table |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1536 (if tem (apply 'sh-mode-syntax-table tem) |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1537 sh-mode-default-syntax-table))) |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1538 (set-syntax-table sh-mode-syntax-table) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1539 (dolist (var (sh-feature sh-variables)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1540 (sh-remember-variable var)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1541 (make-local-variable 'indent-line-function) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1542 (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
|
1543 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1544 (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
|
1545 (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
|
1546 (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
|
1547 (let ((regexp (sh-feature sh-kws-for-done))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1548 (if regexp |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1549 (set (make-local-variable 'sh-regexp-for-done) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1550 (sh-mkword-regexpr (regexp-opt regexp t))))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1551 (message "setting up indent stuff") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1552 ;; 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
|
1553 ;; 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
|
1554 (setq indent-line-function 'sh-indent-line) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1555 (if sh-make-vars-local |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1556 (sh-make-vars-local)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1557 (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
|
1558 (message "No indentation for this shell type.") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1559 (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
|
1560 (run-hooks 'sh-set-shell-hook)) |
6463 | 1561 |
1562 | |
1563 | |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1564 (defun sh-feature (alist &optional function) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1565 "Index ALIST by the current shell. |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1566 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
|
1567 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
|
1568 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1569 - 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
|
1570 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
|
1571 The ultimate default is always `sh'. |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1572 |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1573 - If the value thus looked up is a list starting with `sh-append', |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1574 we call the function `sh-append' with the rest of the list as |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1575 arguments, and use the value. However, the next element of the |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1576 list is not used as-is; instead, we look it up recursively |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1577 in ALIST to allow the function called to define the value for |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1578 one shell to be derived from another shell. |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1579 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
|
1580 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1581 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
|
1582 in ALIST." |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1583 (or (if (consp alist) |
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1584 (let ((l alist)) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1585 (while (and l (consp (car l))) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1586 (setq l (cdr l))) |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1587 (if l alist))) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1588 (if function |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1589 (cdr (assoc (setq function (cons sh-shell function)) alist))) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1590 (let ((sh-shell sh-shell) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1591 elt val) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1592 (while (and sh-shell |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1593 (not (setq elt (assq sh-shell alist)))) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1594 (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
|
1595 ;; 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
|
1596 (unless elt |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1597 (setq elt (assq 'sh alist))) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1598 (if (and (consp (setq val (cdr elt))) |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
1599 (memq (car val) '(sh-append sh-modify))) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1600 (setcdr elt |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1601 (setq val |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
1602 (apply (car val) |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1603 (let ((sh-shell (car (cdr val)))) |
52619
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
1604 (if (assq sh-shell alist) |
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
1605 (sh-feature alist) |
50338995d37f
(sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents:
52571
diff
changeset
|
1606 (eval sh-shell))) |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1607 (cddr val))))) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1608 (if function |
52571
6de55a10c444
(sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
52549
diff
changeset
|
1609 (nconc alist |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1610 (list (cons function |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1611 (setq sh-shell (car function) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1612 val (funcall (cdr function) val)))))) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1613 val))) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1614 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1615 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1616 |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1617 ;; I commented this out because nobody calls it -- rms. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1618 ;;(defun sh-abbrevs (ancestor &rest list) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1619 ;; "Iff it isn't, define the current shell as abbrev table and fill that. |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1620 ;;Abbrev table will inherit all abbrevs from ANCESTOR, which is either an abbrev |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1621 ;;table or a list of (NAME1 EXPANSION1 ...). In addition it will define abbrevs |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1622 ;;according to the remaining arguments NAMEi EXPANSIONi ... |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1623 ;;EXPANSION may be either a string or a skeleton command." |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1624 ;; (or (if (boundp sh-shell) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1625 ;; (symbol-value sh-shell)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1626 ;; (progn |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1627 ;; (if (listp ancestor) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1628 ;; (nconc list ancestor)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1629 ;; (define-abbrev-table sh-shell ()) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1630 ;; (if (vectorp ancestor) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1631 ;; (mapatoms (lambda (atom) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1632 ;; (or (eq atom 0) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1633 ;; (define-abbrev (symbol-value sh-shell) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1634 ;; (symbol-name atom) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1635 ;; (symbol-value atom) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1636 ;; (symbol-function atom)))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1637 ;; ancestor)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1638 ;; (while list |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1639 ;; (define-abbrev (symbol-value sh-shell) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1640 ;; (car list) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1641 ;; (if (stringp (car (cdr list))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1642 ;; (car (cdr list)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1643 ;; "") |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1644 ;; (if (symbolp (car (cdr list))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1645 ;; (car (cdr list)))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1646 ;; (setq list (cdr (cdr list))))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1647 ;; (symbol-value sh-shell))) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1648 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1649 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1650 (defun sh-append (ancestor &rest list) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1651 "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
|
1652 (nconc list ancestor)) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1653 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1654 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1655 (defun sh-modify (skeleton &rest list) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1656 "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
|
1657 (setq skeleton (copy-sequence skeleton)) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1658 (while list |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1659 (setcar (or (nthcdr (car list) skeleton) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1660 (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
|
1661 (car (cdr list))) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1662 (setq list (nthcdr 2 list))) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1663 skeleton) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1664 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1665 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1666 (defun sh-basic-indent-line () |
19480
7f11f103a0ca
(sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents:
18382
diff
changeset
|
1667 "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
|
1668 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
|
1669 Lines containing only comments are considered empty." |
6463 | 1670 (interactive) |
1671 (let ((previous (save-excursion | |
19480
7f11f103a0ca
(sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents:
18382
diff
changeset
|
1672 (while (and (progn (beginning-of-line) |
7f11f103a0ca
(sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents:
18382
diff
changeset
|
1673 (not (bobp))) |
14211
949aa01aca87
(sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents:
14195
diff
changeset
|
1674 (progn |
949aa01aca87
(sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents:
14195
diff
changeset
|
1675 (forward-line -1) |
949aa01aca87
(sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents:
14195
diff
changeset
|
1676 (back-to-indentation) |
949aa01aca87
(sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents:
14195
diff
changeset
|
1677 (or (eolp) |
949aa01aca87
(sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents:
14195
diff
changeset
|
1678 (eq (following-char) ?#))))) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1679 (current-column))) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1680 current) |
6463 | 1681 (save-excursion |
1682 (indent-to (if (eq this-command 'newline-and-indent) | |
1683 previous | |
1684 (if (< (current-column) | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1685 (setq current (progn (back-to-indentation) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1686 (current-column)))) |
6463 | 1687 (if (eolp) previous 0) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1688 (delete-region (point) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1689 (progn (beginning-of-line) (point))) |
6463 | 1690 (if (eolp) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1691 (max previous (* (1+ (/ current sh-indentation)) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1692 sh-indentation)) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1693 (* (1+ (/ current sh-indentation)) sh-indentation)))))) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1694 (if (< (current-column) (current-indentation)) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1695 (skip-chars-forward " \t")))) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1696 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1697 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1698 (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
|
1699 "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
|
1700 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
|
1701 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
|
1702 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1703 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
|
1704 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
|
1705 region, clear header." |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1706 (interactive "r\nP") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1707 (if flag |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1708 (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
|
1709 (point-marker))) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1710 (if sh-header-marker |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1711 (save-excursion |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1712 (let (buffer-undo-list) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1713 (goto-char sh-header-marker) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1714 (append-to-buffer (current-buffer) start end) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1715 (shell-command-on-region (point-min) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1716 (setq end (+ sh-header-marker |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1717 (- end start))) |
14119
2a05fc406f3a
(sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents:
14026
diff
changeset
|
1718 sh-shell-file) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
1719 (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
|
1720 (shell-command-on-region start end (concat sh-shell-file " -"))))) |
6463 | 1721 |
1722 | |
1723 (defun sh-remember-variable (var) | |
1724 "Make VARIABLE available for future completing reads in this buffer." | |
1725 (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
|
1726 (getenv var) |
14195
df3c52ae5b14
(sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
1727 (assoc var sh-shell-variables) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1728 (push (cons var var) sh-shell-variables)) |
6463 | 1729 var) |
1730 | |
1731 | |
1732 | |
1733 (defun sh-quoted-p () | |
1734 "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
|
1735 (eq -1 (% (save-excursion (skip-chars-backward "\\\\")) 2))) |
6463 | 1736 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1737 ;; Indentation stuff. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1738 (defun sh-must-support-indent () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1739 "*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
|
1740 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
|
1741 (unless sh-indent-supported-here |
40927
d8cd2ee4b10c
(sh-must-be-shell-mode): Allow modes derived from sh-mode.
Richard M. Stallman <rms@gnu.org>
parents:
40340
diff
changeset
|
1742 (error "This buffer's shell does not support indentation through Emacs"))) |
25986
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 (defun sh-make-vars-local () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1745 "Make the indentation variables local to this buffer. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1746 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
|
1747 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
|
1748 |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1749 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
|
1750 command `sh-reset-indent-vars-to-global-values'." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1751 (interactive) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1752 (mapcar 'make-local-variable sh-var-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1753 (message "Indentation variable are now local.")) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1754 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1755 (defun sh-reset-indent-vars-to-global-values () |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1756 "Reset local indentation variables to the global values. |
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1757 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
|
1758 (interactive) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1759 (mapcar 'kill-local-variable sh-var-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1760 (if sh-make-vars-local |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1761 (mapcar 'make-local-variable sh-var-list))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1762 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1763 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1764 ;; 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
|
1765 ;; 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
|
1766 (defconst sh-special-keywords "then\\|do") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1767 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1768 (defun sh-help-string-for-variable (var) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1769 "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
|
1770 (let ((msg (documentation-property var 'variable-documentation)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1771 (msg2 "")) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1772 (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
|
1773 (setq msg2 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1774 (format "\n |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1775 You can enter a number (positive to increase indentation, |
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1776 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
|
1777 |
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1778 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
|
1779 the value of variable `sh-basic-offset' |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1780 which in this buffer is currently %s. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1781 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1782 \t%s." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1783 sh-basic-offset |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1784 (mapconcat (lambda (x) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1785 (nth (1- (length x)) x)) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1786 sh-symbol-list "\n\t")))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1787 (concat |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1788 ;; 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
|
1789 ;; (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
|
1790 msg msg2))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1791 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1792 (defun sh-read-variable (var) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1793 "Read a new value for indentation variable VAR." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1794 (interactive "*variable? ") ;; to test |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1795 (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
|
1796 (quote ,var))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1797 val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1798 (setq val (read-from-minibuffer |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1799 (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
|
1800 var (single-key-description help-char)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1801 (format "%s" (symbol-value var)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1802 nil t)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1803 val)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1804 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1805 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1806 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1807 (defun sh-in-comment-or-string (start) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1808 "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
|
1809 (save-excursion |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1810 (let ((state (syntax-ppss start))) |
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
1811 (or (nth 3 state) (nth 4 state))))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1812 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1813 (defun sh-goto-matching-if () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1814 "Go to the matching if for a fi. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1815 This handles nested if..fi pairs." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1816 (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
|
1817 (if found |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1818 (goto-char found)))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1819 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1820 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1821 ;; 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
|
1822 ;; line whose indentation is being handled contain XXX; |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
1823 ;; 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
|
1824 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1825 (defun sh-handle-prev-if () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1826 (list '(+ sh-indent-after-if))) |
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-else () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1829 (if (sh-goto-matching-if) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1830 ;; (list "aligned to if") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1831 (list "aligned to if" '(+ sh-indent-for-else)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1832 nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1833 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1834 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1835 (defun sh-handle-prev-else () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1836 (if (sh-goto-matching-if) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1837 (list '(+ sh-indent-after-if)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1838 )) |
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-this-fi () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1841 (if (sh-goto-matching-if) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1842 (list "aligned to if" '(+ sh-indent-for-fi)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1843 nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1844 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1845 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1846 (defun sh-handle-prev-fi () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1847 ;; 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
|
1848 ;; 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
|
1849 ;; 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
|
1850 ;; 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
|
1851 ;; 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
|
1852 (sh-goto-matching-if) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1853 nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1854 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1855 (defun sh-handle-this-then () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1856 (let ((p (sh-goto-matching-if))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1857 (if p |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1858 (list '(+ sh-indent-for-then)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1859 ))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1860 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1861 (defun sh-handle-prev-then () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1862 (let ((p (sh-goto-matching-if))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1863 (if p |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1864 (list '(+ sh-indent-after-if)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1865 ))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1866 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1867 (defun sh-handle-prev-open () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1868 (save-excursion |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1869 (let ((x (sh-prev-stmt))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1870 (if (and x |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1871 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1872 (goto-char x) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1873 (or |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1874 (looking-at "function\\b") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1875 (looking-at "\\s-*\\S-+\\s-*()") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1876 ))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1877 (list '(+ sh-indent-after-function)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1878 (list '(+ sh-indent-after-open))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1879 ))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1880 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1881 (defun sh-handle-this-close () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1882 (forward-char 1) ;; move over ")" |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1883 (if (sh-safe-forward-sexp -1) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1884 (list "aligned to opening paren"))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1885 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1886 (defun sh-goto-matching-case () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1887 (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
|
1888 (if found (goto-char found)))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1889 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1890 (defun sh-handle-prev-case () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1891 ;; 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
|
1892 ;; 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
|
1893 (if (looking-at ".*\\<case\\>") |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1894 (list '(+ sh-indent-for-case-label)) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1895 (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
|
1896 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1897 (defun sh-handle-this-esac () |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1898 (if (sh-goto-matching-case) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1899 (list "aligned to matching case"))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1900 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1901 (defun sh-handle-prev-esac () |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1902 (if (sh-goto-matching-case) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1903 (list "matching case"))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1904 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1905 (defun sh-handle-after-case-label () |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1906 (if (sh-goto-matching-case) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1907 (list '(+ sh-indent-for-case-alt)))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1908 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1909 (defun sh-handle-prev-case-alt-end () |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1910 (if (sh-goto-matching-case) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1911 (list '(+ sh-indent-for-case-label)))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1912 |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1913 (defun sh-safe-forward-sexp (&optional arg) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1914 "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
|
1915 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
|
1916 (condition-case nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1917 (progn |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1918 (forward-sexp (or arg 1)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1919 (point)) ;; return point if successful |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1920 (error |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1921 (sh-debug "oops!(1) %d" (point)) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1922 nil))) ;; return nil if fail |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1923 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1924 (defun sh-goto-match-for-done () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1925 (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
|
1926 (if found |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1927 (goto-char found)))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1928 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1929 (defun sh-handle-this-done () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1930 (if (sh-goto-match-for-done) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1931 (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
|
1932 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1933 (defun sh-handle-prev-done () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1934 (if (sh-goto-match-for-done) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1935 (list "previous done"))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1936 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1937 (defun sh-handle-this-do () |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1938 (if (sh-goto-match-for-done) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1939 (list '(+ sh-indent-for-do)))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1940 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1941 (defun sh-handle-prev-do () |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1942 (cond |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1943 ((save-restriction |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1944 (narrow-to-region |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1945 (point) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1946 (save-excursion |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1947 (beginning-of-line) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1948 (point))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1949 (sh-goto-match-for-done)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1950 (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
|
1951 (list '(+ sh-indent-after-loop-construct))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1952 ((sh-goto-match-for-done) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1953 (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
|
1954 (list '(+ sh-indent-after-do))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1955 (t |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1956 (message "match for done NOT found") |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1957 nil))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1958 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1959 ;; for rc: |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1960 (defun sh-find-prev-switch () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1961 "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
|
1962 (re-search-backward "\\<switch\\>" nil t)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1963 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1964 (defun sh-handle-this-rc-case () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1965 (if (sh-find-prev-switch) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1966 (list '(+ sh-indent-after-switch)) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
1967 ;; (list '(+ sh-indent-for-case-label)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1968 nil)) |
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 (defun sh-handle-prev-rc-case () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1971 (list '(+ sh-indent-after-case))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1972 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1973 (defun sh-check-rule (n thing) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1974 (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
|
1975 (val nil)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1976 (if rule |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1977 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1978 (setq val (funcall rule)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1979 (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
|
1980 n thing (point) rule val))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1981 val)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1982 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1983 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1984 (defun sh-get-indent-info () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1985 "Return indent-info for this line. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1986 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
|
1987 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
|
1988 \(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
|
1989 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
|
1990 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
|
1991 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
|
1992 modified by subsequent sublists. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1993 \(+ VAR\) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1994 \(- 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
|
1995 the indentation calculated so far. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1996 \(= 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
|
1997 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
|
1998 special variables such as `sh-indent-comment'. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
1999 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
|
2000 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
|
2001 what the indentation is based on." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2002 ;; See comments before `sh-kw'. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2003 (save-excursion |
51379
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
2004 (let ((have-result nil) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2005 this-kw |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2006 start |
51379
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
2007 val |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2008 (result nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2009 (align-point nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2010 prev-line-end x) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2011 (beginning-of-line) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2012 ;; 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
|
2013 ;;(This function never returns just t.) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2014 (cond |
51379
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
2015 ((or (and (boundp 'font-lock-string-face) (not (bobp)) |
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
2016 (eq (get-text-property (1- (point)) 'face) |
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
2017 font-lock-string-face)) |
37542
51f2e2a0c455
(sh-prev-line): Look for sh-heredoc-face
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37528
diff
changeset
|
2018 (eq (get-text-property (point) 'face) sh-heredoc-face)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2019 (setq result t) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2020 (setq have-result t)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2021 ((looking-at "\\s-*#") ; was (equal this-kw "#") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2022 (if (bobp) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2023 (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
|
2024 (setq result (list '(= sh-indent-comment))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2025 ;; 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
|
2026 ;; 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
|
2027 (setq align-point (sh-prev-line nil)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2028 (setq have-result nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2029 )) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2030 ) ;; cond |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
2031 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2032 (unless have-result |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2033 ;; Continuation lines are handled specially |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2034 (if (sh-this-is-a-continuation) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2035 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2036 ;; We assume the line being continued is already |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2037 ;; properly indented... |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2038 ;; (setq prev-line-end (sh-prev-line)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2039 (setq align-point (sh-prev-line nil)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2040 (setq result (list '(+ sh-indent-for-continuation))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2041 (setq have-result t)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2042 (beginning-of-line) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2043 (skip-chars-forward " \t") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2044 (setq this-kw (sh-get-kw))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2045 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2046 ;; 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
|
2047 ;; calculating indentation info for. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2048 (if this-kw |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2049 (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
|
2050 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2051 (setq align-point (point)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2052 (sh-debug |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2053 "this - setting align-point to %d" align-point) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2054 (setq result (append result val)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2055 (setq have-result t) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2056 ;; set prev-line to continue processing remainder |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2057 ;; of this line as a previous line |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2058 (setq prev-line-end (point)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2059 )))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2060 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2061 (unless have-result |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2062 (setq prev-line-end (sh-prev-line 'end))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2063 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2064 (if prev-line-end |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2065 (save-excursion |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2066 ;; We start off at beginning of this line. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2067 ;; Scan previous statements while this is <= |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2068 ;; start of previous line. |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2069 (setq start (point)) ;; for debug only |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2070 (goto-char prev-line-end) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2071 (setq x t) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2072 (while (and x (setq x (sh-prev-thing))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2073 (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
|
2074 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2075 ((and (equal x ")") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2076 (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
|
2077 sh-st-punc)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2078 (sh-debug "Case label) here") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2079 (setq x 'case-label) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2080 (if (setq val (sh-check-rule 2 x)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2081 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2082 (setq result (append result val)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2083 (setq align-point (point)))) |
53419 | 2084 (or (bobp) |
2085 (forward-char -1)) | |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2086 (skip-chars-forward "[a-z0-9]*?") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2087 ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2088 ((string-match "[])}]" x) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2089 (setq x (sh-safe-forward-sexp -1)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2090 (if x |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2091 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2092 (setq align-point (point)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2093 (setq result (append result |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2094 (list "aligned to opening paren"))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2095 ))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2096 ((string-match "[[({]" x) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2097 (sh-debug "Checking special thing: %s" x) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2098 (if (setq val (sh-check-rule 2 x)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2099 (setq result (append result val))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2100 (forward-char -1) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2101 (setq align-point (point))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2102 ((string-match "[\"'`]" x) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2103 (sh-debug "Skipping back for %s" x) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2104 ;; this was oops-2 |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2105 (setq x (sh-safe-forward-sexp -1))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2106 ((stringp x) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2107 (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
|
2108 (if (setq val (sh-check-rule 2 x)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2109 ;; (or (eq t (car val)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2110 ;; (eq t (car (car val)))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2111 (setq result (append result val))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2112 ;; 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
|
2113 (setq align-point (point)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2114 (unless (bolp) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2115 (forward-char -1))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2116 (t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2117 (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
|
2118 ) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2119 ) ;; while |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2120 (sh-debug "result is %s" result) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2121 ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2122 (sh-debug "No prev line!") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2123 (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
|
2124 ) |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
2125 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2126 (if align-point |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2127 ;; 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
|
2128 (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
|
2129 ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2130 (sh-debug "result is now: %s" result) |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
2131 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2132 (or result |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2133 (if prev-line-end |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2134 (setq result (list (list t prev-line-end))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2135 (setq result (list (list '= 'sh-first-lines-indent))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2136 )) |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
2137 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2138 (if (eq result t) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2139 (setq result nil)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2140 (sh-debug "result is: %s" result) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2141 result |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2142 ) ;; let |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2143 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2144 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2145 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2146 (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
|
2147 "Return the variable controlling indentation for this line. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2148 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
|
2149 indicating the problem. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2150 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
|
2151 (let ((var nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2152 (result nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2153 (reason nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2154 sym elt) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2155 (or info |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2156 (setq info (sh-get-indent-info))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2157 (if (null info) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2158 (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
|
2159 (while (and info (null result)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2160 (setq elt (car info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2161 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2162 ((stringp elt) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2163 (setq reason elt) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2164 ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2165 ((not (listp elt)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2166 (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
|
2167 ;; so it is a list |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2168 ((eq t (car elt)) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2169 ) ;; nothing |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2170 ((symbolp (setq sym (nth 1 elt))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2171 ;; 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
|
2172 ;; ignore other variables. Otherwise it is tricky to |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2173 ;; "learn" the comment indentation. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2174 (if (eq var 'sh-indent-comment) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2175 (setq result var) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2176 (if var |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2177 (setq result |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2178 "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
|
2179 (setq var sym)))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2180 (t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2181 (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
|
2182 (setq info (cdr info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2183 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2184 (or result |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2185 (setq result var)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2186 (or result |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2187 (setq result reason)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2188 (if (null result) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2189 ;; e.g. just had (t POS) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2190 (setq result "line has default indentation")) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2191 result)) |
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 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2194 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2195 ;; Finding the previous line isn't trivial. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2196 ;; 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
|
2197 ;; 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
|
2198 ;; we are going to! |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2199 ;; 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
|
2200 ;; 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
|
2201 ;; |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2202 ;; What we do: |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2203 ;; - go back to previous non-empty line |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2204 ;; - 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
|
2205 ;; - 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
|
2206 (defun sh-prev-line (&optional end) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2207 "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
|
2208 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
|
2209 we go to the end of the previous line and do not check for continuations." |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2210 (save-excursion |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2211 (beginning-of-line) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2212 (forward-comment (- (point-max))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2213 (unless end (beginning-of-line)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2214 (when (and (not (bobp)) |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
2215 (equal (get-text-property (1- (point)) 'face) |
37542
51f2e2a0c455
(sh-prev-line): Look for sh-heredoc-face
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37528
diff
changeset
|
2216 sh-heredoc-face)) |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
2217 (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
|
2218 (when p1 |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2219 (goto-char p1) |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
2220 (if end |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
2221 (end-of-line) |
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
2222 (beginning-of-line))))) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2223 (unless end |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2224 ;; 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
|
2225 ;; 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
|
2226 (while (and (sh-this-is-a-continuation) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2227 (>= 0 (forward-line -1)))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2228 (beginning-of-line) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2229 (skip-chars-forward " \t")) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2230 (point))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2231 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2232 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2233 (defun sh-prev-stmt () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2234 "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
|
2235 ;; 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
|
2236 ;; 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
|
2237 ;; 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
|
2238 ;; 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
|
2239 (interactive) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2240 (save-excursion |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2241 (let ((going t) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2242 (start (point)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2243 (found nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2244 (prev nil)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2245 (skip-chars-backward " \t;|&({[") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2246 (while (and (not found) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2247 (not (bobp)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2248 going) |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2249 ;; 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
|
2250 (if (sh-safe-forward-sexp -1) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2251 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2252 (if (looking-at sh-special-keywords) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2253 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2254 (setq found prev)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2255 (setq prev (point)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2256 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2257 ;; backward-sexp failed |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2258 (if (zerop (skip-chars-backward " \t()[\]{};`'")) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2259 (forward-char -1)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2260 (if (bolp) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2261 (let ((back (sh-prev-line nil))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2262 (if back |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2263 (goto-char back) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2264 (setq going nil))))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2265 (unless found |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2266 (skip-chars-backward " \t") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2267 (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
|
2268 (eq (char-before) ?\;) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2269 (looking-at "\\s-*[|&]")) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2270 (setq found (point))))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2271 (if found |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2272 (goto-char found)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2273 (if found |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2274 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2275 (skip-chars-forward " \t|&({[") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2276 (setq found (point)))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2277 (if (>= (point) start) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2278 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2279 (debug "We didn't move!") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2280 (setq found nil)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2281 (or found |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2282 (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
|
2283 found))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2284 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2285 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2286 (defun sh-get-word () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2287 "Get a shell word skipping whitespace from point." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2288 (interactive) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2289 (skip-chars-forward "\t ") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2290 (let ((start (point))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2291 (while |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2292 (if (looking-at "[\"'`]") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2293 (sh-safe-forward-sexp) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2294 ;; (> (skip-chars-forward "^ \t\n\"'`") 0) |
62550
4f78132b042b
(sh-mode, sh-get-word): Minor regexp fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
62310
diff
changeset
|
2295 (> (skip-chars-forward "-_a-zA-Z$0-9") 0) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2296 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2297 (buffer-substring start (point)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2298 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2299 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2300 (defun sh-prev-thing () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2301 "Return the previous thing this logical line." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2302 ;; 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
|
2303 ;; 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
|
2304 ;; 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
|
2305 ;; 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
|
2306 ;; line. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2307 ;; |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2308 ;; Added a kludge for ";;" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2309 ;; Possible return values: |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2310 ;; nil - nothing |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2311 ;; a string - possibly a keyword |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
2312 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2313 (if (bolp) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2314 nil |
51379
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
2315 (let (c min-point |
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
2316 (start (point))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2317 (save-restriction |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2318 (narrow-to-region |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2319 (if (sh-this-is-a-continuation) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2320 (setq min-point (sh-prev-line nil)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2321 (save-excursion |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2322 (beginning-of-line) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2323 (setq min-point (point)))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2324 (point)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2325 (skip-chars-backward " \t;") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2326 (unless (looking-at "\\s-*;;") |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2327 (skip-chars-backward "^)}];\"'`({[") |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2328 (setq c (char-before)))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2329 (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
|
2330 (point) c start min-point) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2331 (if (< (point) min-point) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2332 (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
|
2333 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2334 ((looking-at "\\s-*;;") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2335 ;; (message "Found ;; !") |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2336 ";;") |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2337 ((or (eq c ?\n) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2338 (eq c nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2339 (eq c ?\;)) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2340 (save-excursion |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2341 ;; 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
|
2342 (skip-chars-forward " \t\n\\\\") |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2343 (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
|
2344 (if (>= (point) start) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2345 (progn |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2346 (sh-debug "point: %d >= start: %d" (point) start) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2347 nil) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2348 (sh-get-word)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2349 )) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2350 (t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2351 ;; c -- return a string |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2352 (char-to-string c) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2353 )) |
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 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2357 (defun sh-this-is-a-continuation () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2358 "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
|
2359 (save-excursion |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2360 (and (zerop (forward-line -1)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2361 (looking-at ".*\\\\$") |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2362 (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
|
2363 nil nil nil t)))))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2364 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2365 (defun sh-get-kw (&optional where and-move) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2366 "Return first word of line from WHERE. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2367 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
|
2368 (let ((start (point))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2369 (if where |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2370 (goto-char where)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2371 (prog1 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2372 (buffer-substring (point) |
63885
135b9f905ec6
(sh-get-kw): `&' also separates words.
Glenn Morris <rgm@gnu.org>
parents:
63455
diff
changeset
|
2373 (progn (skip-chars-forward "^ \t\n;&")(point))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2374 (unless and-move |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
2375 (goto-char start))))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2376 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2377 (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
|
2378 "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
|
2379 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
|
2380 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
|
2381 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
|
2382 (let ((parse-sexp-ignore-comments t) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2383 prev) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2384 (setq depth (or depth 1)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2385 (save-excursion |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2386 (condition-case nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2387 (while (and |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2388 (/= 0 depth) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2389 (not (bobp)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2390 (setq prev (sh-prev-stmt))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2391 (goto-char prev) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2392 (save-excursion |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2393 (if (looking-at "\\\\\n") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2394 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2395 (forward-char 2) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2396 (skip-chars-forward " \t"))) |
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 ((looking-at open) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2399 (setq depth (1- depth)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2400 (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
|
2401 ((looking-at close) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2402 (setq depth (1+ depth)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2403 (sh-debug "found close - depth = %d" depth)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2404 (t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2405 )))) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2406 (error nil)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2407 (if (eq depth 0) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2408 prev ;; (point) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2409 nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2410 ))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2411 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2412 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2413 (defun sh-var-value (var &optional ignore-error) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2414 "Return the value of variable VAR, interpreting symbols. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2415 It can also return t or nil. |
60917
87f9bb9d3718
* progmodes/ebnf-abn.el, progmodes/ebnf-bnf.el,
Werner LEMBERG <wl@gnu.org>
parents:
59622
diff
changeset
|
2416 If an invalid 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
|
2417 IGNORE-ERROR is non-nil." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2418 (let ((val (symbol-value var))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2419 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2420 ((numberp val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2421 val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2422 ((eq val t) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2423 val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2424 ((null val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2425 val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2426 ((eq val '+) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2427 sh-basic-offset) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2428 ((eq val '-) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2429 (- sh-basic-offset)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2430 ((eq val '++) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2431 (* 2 sh-basic-offset)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2432 ((eq val '--) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2433 (* 2 (- sh-basic-offset))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2434 ((eq val '*) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2435 (/ sh-basic-offset 2)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2436 ((eq val '/) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2437 (/ (- sh-basic-offset) 2)) |
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 (if ignore-error |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2440 (progn |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2441 (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
|
2442 0) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2443 (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
|
2444 )))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2445 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2446 (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
|
2447 "Set variable VAR to VALUE. |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2448 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
|
2449 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
|
2450 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2451 (no-symbol |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2452 (set var value)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2453 ((= value sh-basic-offset) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2454 (set var '+)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2455 ((= value (- sh-basic-offset)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2456 (set var '-)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2457 ((eq value (* 2 sh-basic-offset)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2458 (set var '++)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2459 ((eq value (* 2 (- sh-basic-offset))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2460 (set var '--)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2461 ((eq value (/ sh-basic-offset 2)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2462 (set var '*)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2463 ((eq value (/ (- sh-basic-offset) 2)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2464 (set var '/)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2465 (t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2466 (set var value))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2467 ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2468 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2469 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2470 (defun sh-calculate-indent (&optional info) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2471 "Return the indentation for the current line. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2472 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
|
2473 (let ((ofs 0) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2474 (base-value 0) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2475 elt a b var val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2476 (or info |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2477 (setq info (sh-get-indent-info))) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2478 (when info |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2479 (while info |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2480 (sh-debug "info: %s ofs=%s" info ofs) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2481 (setq elt (car info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2482 (cond |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2483 ((stringp elt)) ;; do nothing? |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2484 ((listp elt) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2485 (setq a (car (car info))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2486 (setq b (nth 1 (car info))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2487 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2488 ((eq a t) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2489 (save-excursion |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2490 (goto-char b) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2491 (setq val (current-indentation))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2492 (setq base-value val)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2493 ((symbolp b) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2494 (setq val (sh-var-value b)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2495 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2496 ((eq a '=) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2497 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2498 ((null val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2499 ;; no indentation |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2500 ;; set info to nil so we stop immediately |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2501 (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
|
2502 ((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
|
2503 (t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2504 ;; The following assume the (t POS) come first! |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2505 (setq ofs val base-value 0) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2506 (setq info nil)))) ;; ? stop now |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2507 ((eq a '+) (setq ofs (+ ofs val))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2508 ((eq a '-) (setq ofs (- ofs val))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2509 (t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2510 (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
|
2511 (t |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2512 (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
|
2513 (t |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2514 (error "sh-calculate-indent invalid elt %s" elt))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2515 (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
|
2516 a b val base-value ofs) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2517 (setq info (cdr info))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2518 ;; return value: |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2519 (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
|
2520 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2521 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2522 ((or (null base-value)(null ofs)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2523 nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2524 ((and (numberp base-value)(numberp ofs)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2525 (sh-debug "base (%d) + ofs (%d) = %d" |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2526 base-value ofs (+ base-value ofs)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2527 (+ base-value ofs)) ;; return value |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2528 (t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2529 (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
|
2530 base-value ofs) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2531 nil))))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2532 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2533 |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
2534 (defun sh-indent-line () |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2535 "Indent the current line." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2536 (interactive) |
49306
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
2537 (let ((indent (sh-calculate-indent)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2538 (pos (- (point-max) (point)))) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2539 (when indent |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2540 (beginning-of-line) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2541 (skip-chars-forward " \t") |
49306
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
2542 (indent-line-to indent) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2543 ;; If initial point was within line's indentation, |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2544 ;; 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
|
2545 (if (> (- (point-max) pos) (point)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2546 (goto-char (- (point-max) pos)))))) |
25986
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 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2549 (defun sh-blink (blinkpos &optional msg) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2550 "Move cursor momentarily to BLINKPOS and display MSG." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2551 ;; 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
|
2552 (if (numberp blinkpos) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2553 (save-excursion |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2554 (goto-char blinkpos) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2555 (message msg) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2556 (sit-for blink-matching-delay)) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2557 (message msg))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2558 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2559 (defun sh-show-indent (arg) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2560 "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
|
2561 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
|
2562 this line. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2563 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
|
2564 a pop up window describes this variable. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2565 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
|
2566 we are indenting relative to, if applicable." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2567 (interactive "P") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2568 (sh-must-support-indent) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2569 (let* ((info (sh-get-indent-info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2570 (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
|
2571 (curr-indent (current-indentation)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2572 val msg) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2573 (if (stringp var) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2574 (message (setq msg var)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2575 (setq val (sh-calculate-indent info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2576 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2577 (if (eq curr-indent val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2578 (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
|
2579 (setq msg |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2580 (if val |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2581 (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
|
2582 var (symbol-value var) curr-indent val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2583 (format "%s (%s) would leave line as is" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2584 var (symbol-value var))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2585 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2586 (if (and arg var) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2587 (describe-variable var))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2588 (if sh-blink |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2589 (let ((info (sh-get-indent-info))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2590 (if (and info (listp (car info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2591 (eq (car (car info)) t)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2592 (sh-blink (nth 1 (car info)) msg) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2593 (message msg))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2594 (message msg)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2595 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2596 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2597 (defun sh-set-indent () |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2598 "Set the indentation for the current line. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2599 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
|
2600 for a new value for it." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2601 (interactive) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2602 (sh-must-support-indent) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2603 (let* ((info (sh-get-indent-info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2604 (var (sh-get-indent-var-for-line info)) |
51379
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
2605 val old-val indent-val) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2606 (if (stringp var) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2607 (message (format "Cannot set indent - %s" var)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2608 (setq old-val (symbol-value var)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2609 (setq val (sh-read-variable var)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2610 (condition-case nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2611 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2612 (set var val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2613 (setq indent-val (sh-calculate-indent info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2614 (if indent-val |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2615 (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
|
2616 var (symbol-value var) indent-val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2617 (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
|
2618 var (symbol-value var))) |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2619 ;; 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
|
2620 ;; 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
|
2621 ;; 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
|
2622 ;; (sh-indent-line) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2623 ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2624 (error |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2625 (set var old-val) |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2626 (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
|
2627 var old-val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2628 (sit-for 1) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2629 nil)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2630 ))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2631 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2632 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2633 (defun sh-learn-line-indent (arg) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2634 "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
|
2635 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2636 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
|
2637 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
|
2638 presently is. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2639 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2640 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
|
2641 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
|
2642 (interactive "*P") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2643 (sh-must-support-indent) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2644 ;; 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
|
2645 ;; 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
|
2646 ;; would just be confusing. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2647 (if (save-excursion |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2648 (beginning-of-line) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2649 (looking-at "\\s-*$")) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2650 (message "sh-learn-line-indent ignores empty lines.") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2651 (let* ((info (sh-get-indent-info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2652 (var (sh-get-indent-var-for-line info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2653 ival sval diff new-val |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2654 (no-symbol arg) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2655 (curr-indent (current-indentation))) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2656 (cond |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2657 ((stringp var) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2658 (message (format "Cannot learn line - %s" var))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2659 ((eq var 'sh-indent-comment) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2660 ;; This is arbitrary... |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2661 ;; - 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
|
2662 ;; - 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
|
2663 ;; then set to t |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2664 ;; - else set to curr-indent. |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2665 (setq sh-indent-comment |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2666 (if (= curr-indent 0) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2667 0 |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2668 (let* ((sh-indent-comment t) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2669 (val2 (sh-calculate-indent info))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2670 (if (= val2 curr-indent) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2671 t |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2672 curr-indent)))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2673 (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
|
2674 ) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2675 ((numberp (setq sval (sh-var-value var))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2676 (setq ival (sh-calculate-indent info)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2677 (setq diff (- curr-indent ival)) |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
2678 |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2679 (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
|
2680 curr-indent ival diff var sval) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2681 (setq new-val (+ sval diff)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2682 ;;; 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
|
2683 ;;; 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
|
2684 ;;; or vice-versa. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2685 ;;; (if (= 0 diff) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2686 ;;; (message "No change needed!") |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2687 (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
|
2688 (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
|
2689 ) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2690 (t |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2691 (debug) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2692 (message "Cannot change %s" var)))))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2693 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2694 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2695 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2696 (defun sh-mark-init (buffer) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2697 "Initialize a BUFFER to be used by `sh-mark-line'." |
47595
64e6b86fa461
(sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents:
47264
diff
changeset
|
2698 (save-excursion |
64e6b86fa461
(sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents:
47264
diff
changeset
|
2699 (set-buffer (get-buffer-create buffer)) |
64e6b86fa461
(sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents:
47264
diff
changeset
|
2700 (erase-buffer) |
64e6b86fa461
(sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents:
47264
diff
changeset
|
2701 (occur-mode) |
64e6b86fa461
(sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents:
47264
diff
changeset
|
2702 )) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2703 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2704 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2705 (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
|
2706 "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
|
2707 Buffer BUFFER is in `occur-mode'. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2708 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
|
2709 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
|
2710 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
|
2711 (let ((m1 (make-marker)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2712 start |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2713 (line "")) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2714 (when point |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2715 (set-marker m1 point (current-buffer)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2716 (if add-linenum |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2717 (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
|
2718 (save-excursion |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2719 (if (get-buffer buffer) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2720 (set-buffer (get-buffer buffer)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2721 (set-buffer (get-buffer-create buffer)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2722 (occur-mode) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2723 ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2724 (goto-char (point-max)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2725 (setq start (point)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2726 (insert line) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2727 (if occur-point |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2728 (setq occur-point (point))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2729 (insert message) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2730 (if point |
38079
7563c3b44130
(sh-mark-line): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents:
37542
diff
changeset
|
2731 (add-text-properties |
7563c3b44130
(sh-mark-line): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents:
37542
diff
changeset
|
2732 start (point) |
7563c3b44130
(sh-mark-line): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents:
37542
diff
changeset
|
2733 '(mouse-face highlight |
7563c3b44130
(sh-mark-line): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents:
37542
diff
changeset
|
2734 help-echo "mouse-2: go to the line where I learned this"))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2735 (insert "\n") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2736 (if point |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2737 (progn |
47595
64e6b86fa461
(sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents:
47264
diff
changeset
|
2738 (put-text-property start (point) 'occur-target m1) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2739 (if occur-point |
47595
64e6b86fa461
(sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents:
47264
diff
changeset
|
2740 (put-text-property start occur-point |
64e6b86fa461
(sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents:
47264
diff
changeset
|
2741 'occur-match t)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2742 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2743 ))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2744 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2745 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2746 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2747 ;; Is this really worth having? |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2748 (defvar sh-learned-buffer-hook nil |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2749 "*An abnormal hook, called with an alist of learned variables.") |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
2750 ;; Example of how to use sh-learned-buffer-hook |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
2751 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2752 ;; (defun what-i-learned (list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2753 ;; (let ((p list)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2754 ;; (save-excursion |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2755 ;; (set-buffer "*scratch*") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2756 ;; (goto-char (point-max)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2757 ;; (insert "(setq\n") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2758 ;; (while p |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2759 ;; (insert (format " %s %s \n" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2760 ;; (nth 0 (car p)) (nth 1 (car p)))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2761 ;; (setq p (cdr p))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2762 ;; (insert ")\n") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2763 ;; ))) |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
2764 ;; |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2765 ;; (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
|
2766 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2767 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2768 ;; 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
|
2769 ;; 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
|
2770 ;; use the whole buffer. Use narrowing if needbe. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2771 (defun sh-learn-buffer-indent (&optional arg) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2772 "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
|
2773 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2774 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
|
2775 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
|
2776 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
|
2777 |
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2778 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
|
2779 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
|
2780 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
|
2781 basic indent. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2782 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
|
2783 is set to the prefix's numerical value. |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2784 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
|
2785 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
|
2786 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2787 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
|
2788 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
|
2789 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
|
2790 removed in the future. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2791 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2792 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
|
2793 (interactive "P") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2794 (sh-must-support-indent) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2795 (save-excursion |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2796 (goto-char (point-min)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2797 (let ((learned-var-list nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2798 (out-buffer "*indent*") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2799 (num-diffs 0) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2800 previous-set-info |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2801 (max 17) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2802 vec |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2803 msg |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2804 (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
|
2805 (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
|
2806 initial-msg |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2807 (specified-basic-offset (and arg (numberp arg) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2808 (> arg 0))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2809 (linenum 0) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2810 suggested) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2811 (setq vec (make-vector max 0)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2812 (sh-mark-init out-buffer) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2813 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2814 (if specified-basic-offset |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2815 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2816 (setq sh-basic-offset arg) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2817 (setq initial-msg |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2818 (format "Using specified sh-basic-offset of %d" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2819 sh-basic-offset))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2820 (setq initial-msg |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2821 (format "Initial value of sh-basic-offset: %s" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2822 sh-basic-offset))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2823 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2824 (while (< (point) (point-max)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2825 (setq linenum (1+ linenum)) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2826 ;; (if (zerop (% linenum 10)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2827 (message "line %d" linenum) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2828 ;; ) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2829 (unless (looking-at "\\s-*$") ;; ignore empty lines! |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2830 (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
|
2831 (info (sh-get-indent-info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2832 (var (sh-get-indent-var-for-line info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2833 sval ival diff new-val |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2834 (curr-indent (current-indentation))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2835 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2836 ((null var) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2837 nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2838 ((stringp var) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2839 nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2840 ((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
|
2841 ;; 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
|
2842 (setq ival (sh-calculate-indent)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2843 (setq diff (- curr-indent ival)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2844 (setq new-val (+ sval diff)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2845 (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
|
2846 (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
|
2847 (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
|
2848 (progn |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2849 ;; 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
|
2850 (unless (eq (symbol-value var) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2851 (nth 1 previous-set-info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2852 (sh-mark-line |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2853 (format "Variable %s was set to %s" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2854 var (symbol-value var)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2855 (point) out-buffer t t) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2856 (sh-mark-line |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2857 (format " but was previously set to %s" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2858 (nth 1 previous-set-info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2859 (nth 2 previous-set-info) out-buffer t) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2860 (setq num-diffs (1+ num-diffs)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2861 ;; (delete previous-set-info learned-var-list) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2862 (setcdr previous-set-info |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2863 (list (symbol-value var) (point))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2864 ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2865 ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2866 (setq learned-var-list |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2867 (append (list (list var (symbol-value var) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2868 (point))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2869 learned-var-list))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2870 (if (numberp new-val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2871 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2872 (sh-debug |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2873 "This line's indent value: %d" new-val) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2874 (if (< new-val 0) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2875 (setq new-val (- new-val))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2876 (if (< new-val max) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2877 (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
|
2878 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2879 ((eq var 'sh-indent-comment) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2880 (unless (= curr-indent (sh-calculate-indent info)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2881 ;; this is not the default indentation |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2882 (setq comments-always-default nil) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2883 (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
|
2884 (or (eq comment-col curr-indent) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2885 (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
|
2886 (setq comment-col curr-indent)) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2887 )) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2888 (t |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2889 (sh-debug "Cannot learn this line!!!") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2890 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2891 (sh-debug |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2892 "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
|
2893 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2894 (forward-line 1) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2895 ) ;; while |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2896 (if sh-debug |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2897 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2898 (setq msg (format |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2899 "comment-col = %s comments-always-default = %s" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2900 comment-col comments-always-default)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2901 ;; (message msg) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2902 (sh-mark-line msg nil out-buffer))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2903 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2904 ((eq comment-col 0) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2905 (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
|
2906 (comments-always-default |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2907 (setq msg "\nComments follow default indentation.\n") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2908 (setq comment-col t)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2909 ((numberp comment-col) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2910 (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
|
2911 (t |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2912 (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
|
2913 (setq comment-col nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2914 )) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2915 (sh-debug msg) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2916 (sh-mark-line msg nil out-buffer) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2917 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2918 (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
|
2919 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2920 (setq suggested (sh-guess-basic-offset vec)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2921 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2922 (if (and suggested (not specified-basic-offset)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2923 (let ((new-value |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2924 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2925 ;; 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
|
2926 ((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
|
2927 suggested) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2928 ;; 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
|
2929 (sh-learn-basic-offset |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2930 (if (numberp suggested) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2931 suggested |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2932 (if (= (length suggested) 1) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2933 (car suggested)))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2934 (t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2935 nil)))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2936 (if new-value |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2937 (progn |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2938 (setq learned-var-list |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2939 (append (list (list 'sh-basic-offset |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2940 (setq sh-basic-offset new-value) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2941 (point-max))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2942 learned-var-list)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2943 ;; 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
|
2944 ;; it will appear in the "Learned variable settings". |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2945 (sh-mark-line |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2946 (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
|
2947 nil out-buffer)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2948 (sh-mark-line |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2949 (if (listp suggested) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2950 (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
|
2951 (mapconcat 'int-to-string suggested " ")) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2952 (format "Suggested sh-basic-offset: %d" suggested)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2953 nil out-buffer)))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2954 |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
2955 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2956 (setq learned-var-list |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2957 (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
|
2958 learned-var-list)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2959 (setq sh-indent-comment comment-col) |
51379
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
2960 (let ((name (buffer-name))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2961 (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
|
2962 (if arg |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2963 ;; Set learned variables to symbolic rather than numeric |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2964 ;; values where possible. |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2965 (dolist (learned-var (reverse learned-var-list)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2966 (let ((var (car learned-var)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2967 (val (nth 1 learned-var))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2968 (when (and (not (eq var 'sh-basic-offset)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2969 (numberp val)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2970 (sh-set-var-value var val))))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2971 (dolist (learned-var (reverse learned-var-list)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2972 (let ((var (car learned-var))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2973 (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
|
2974 (nth 2 learned-var) out-buffer))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2975 (save-excursion |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2976 (set-buffer out-buffer) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2977 (goto-char (point-min)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2978 (insert |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2979 (format "Indentation values for buffer %s.\n" name) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2980 (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
|
2981 num-diffs |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2982 (if (= num-diffs 1) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2983 " has" "s have") |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2984 (if (zerop num-diffs) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2985 "." ":")) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
2986 ))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2987 ;; Are abnormal hooks considered bad form? |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2988 (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
|
2989 (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
|
2990 (pop-to-buffer out-buffer)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2991 ))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2992 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2993 (defun sh-guess-basic-offset (vec) |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
2994 "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
|
2995 This is experimental, heuristic and arbitrary! |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2996 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
|
2997 `sh-learn-buffer-indent'. |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2998 Return values: |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
2999 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
|
3000 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
|
3001 reasonable choices |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3002 nil - we couldn't find a reasonable one." |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3003 (let* ((max (1- (length vec))) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3004 (i 1) |
51379
f61b3dac769b
(sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51265
diff
changeset
|
3005 (totals (make-vector max 0))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3006 (while (< i max) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3007 (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
|
3008 (if (zerop (% i 2)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3009 (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
|
3010 (if (< (* i 2) max) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3011 (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
|
3012 (setq i (1+ i))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3013 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3014 (let ((x nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3015 (result nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3016 tot sum p) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3017 (setq i 1) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3018 (while (< i max) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3019 (if (/= (aref totals i) 0) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3020 (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
|
3021 (setq i (1+ i))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3022 |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3023 (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
|
3024 (setq tot (apply '+ (append totals nil))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3025 (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
|
3026 vec totals tot)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3027 (cond |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3028 ((zerop (length x)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3029 (message "no values!")) ;; we return nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3030 ((= (length x) 1) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3031 (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
|
3032 (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
|
3033 ((> (cdr (car x)) (/ tot 2)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3034 ;; 1st is > 50% |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3035 (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
|
3036 (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
|
3037 ((>= (cdr (car x)) (* 2 (cdr (car (cdr x))))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3038 ;; 1st is >= 2 * 2nd |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3039 (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
|
3040 (setq result (car (car x)))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3041 ((>= (+ (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
|
3042 ;; 1st & 2nd together >= 50% - return a list |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3043 (setq p x sum 0 result nil) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3044 (while (and p |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3045 (<= (setq sum (+ sum (cdr (car p)))) (/ tot 2))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3046 (setq result (append result (list (car (car p))))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3047 (setq p (cdr p))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3048 (message "Possible choices for sh-basic-offset: %s" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3049 (mapconcat 'int-to-string result " "))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3050 (t |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3051 (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
|
3052 (car (car x))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3053 ;; result is nil here |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3054 )) |
32728
6fe525e8880c
(sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32503
diff
changeset
|
3055 result))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3056 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3057 ;; ======================================================================== |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3058 |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
3059 ;; 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
|
3060 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3061 (defvar sh-styles-alist nil |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3062 "A list of all known shell indentation styles.") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3063 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3064 (defun sh-name-style (name &optional confirm-overwrite) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3065 "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
|
3066 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
|
3067 overwritten if |
30956
4c05432300f8
Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29844
diff
changeset
|
3068 - - 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
|
3069 - - 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
|
3070 ;; (interactive "sName for this style: ") |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3071 (interactive |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3072 (list |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3073 (read-from-minibuffer "Name for this style? " ) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3074 (not current-prefix-arg))) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3075 (let ((slist (cons name |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3076 (mapcar (lambda (var) (cons var (symbol-value var))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3077 sh-var-list))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3078 (style (assoc name sh-styles-alist))) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3079 (if style |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3080 (if (and confirm-overwrite |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3081 (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
|
3082 (message "Not changing style %s" name) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3083 (message "Updating style %s" name) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3084 (setcdr style (cdr slist))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3085 (message "Creating new style %s" name) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3086 (push slist sh-styles-alist)))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3087 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3088 (defun sh-load-style (name) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3089 "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
|
3090 (interactive (list (completing-read |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3091 "Which style to use for this buffer? " |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3092 sh-styles-alist nil t))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3093 (let ((sl (assoc name sh-styles-alist))) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3094 (if (null sl) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3095 (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
|
3096 (dolist (var (cdr sl)) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3097 (set (car var) (cdr var)))))) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3098 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3099 (defun sh-save-styles-to-buffer (buff) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3100 "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
|
3101 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
|
3102 (interactive (list |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3103 (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
|
3104 (with-current-buffer (get-buffer-create buff) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3105 (goto-char (point-max)) |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3106 (insert "\n") |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3107 (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
|
3108 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3109 |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3110 |
6463 | 3111 ;; statement syntax-commands for various shells |
3112 | |
3113 ;; You are welcome to add the syntax or even completely new statements as | |
3114 ;; appropriate for your favorite shell. | |
3115 | |
49306
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3116 (defconst sh-non-closing-paren |
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3117 ;; If we leave it rear-sticky, calling `newline' ends up inserting a \n |
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3118 ;; that inherits this property, which then confuses the indentation. |
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3119 (propertize ")" 'syntax-table sh-st-punc 'rear-nonsticky t)) |
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3120 |
17531
b891e41b4011
(sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents:
17501
diff
changeset
|
3121 (define-skeleton sh-case |
b891e41b4011
(sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents:
17501
diff
changeset
|
3122 "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
|
3123 (csh "expression: " |
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3124 "switch( " str " )" \n |
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3125 > "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
|
3126 > _ \n |
20771
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3127 "breaksw" \n |
17531
b891e41b4011
(sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents:
17501
diff
changeset
|
3128 ( "other pattern, %s: " |
20771
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3129 < "case " str ?: \n |
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3130 > _ \n |
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3131 "breaksw" \n) |
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3132 < "default:" \n |
17531
b891e41b4011
(sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents:
17501
diff
changeset
|
3133 > _ \n |
b891e41b4011
(sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents:
17501
diff
changeset
|
3134 resume: |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3135 < < "endsw" \n) |
20771
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3136 (es) |
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3137 (rc "expression: " |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3138 > "switch( " str " ) {" \n |
20771
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3139 > "case " (read-string "pattern: ") \n |
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3140 > _ \n |
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3141 ( "other pattern, %s: " |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3142 "case " str > \n |
20771
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3143 > _ \n) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3144 "case *" > \n |
20771
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3145 > _ \n |
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3146 resume: |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
3147 ?\} > \n) |
20771
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3148 (sh "expression: " |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3149 > "case " str " in" \n |
49306
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3150 ( "pattern, %s: " |
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3151 > str sh-non-closing-paren \n |
20771
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3152 > _ \n |
51594
ad56e8962943
(sh-while-getopts, sh-if, sh-case): Revert part of previous change.
Juanma Barranquero <lekktu@gmail.com>
parents:
51515
diff
changeset
|
3153 ";;" \n) |
49306
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3154 > "*" sh-non-closing-paren \n |
20771
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3155 > _ \n |
c6d9f48bd2f8
(sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
3156 resume: |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3157 "esac" > \n)) |
6463 | 3158 |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3159 (define-skeleton sh-for |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3160 "Insert a for loop. See `sh-feature'." |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3161 (csh sh-modify sh |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3162 1 "" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3163 2 "foreach " |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3164 4 " ( " |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3165 6 " )" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3166 15 '< |
37542
51f2e2a0c455
(sh-prev-line): Look for sh-heredoc-face
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37528
diff
changeset
|
3167 16 "end") |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3168 (es sh-modify rc |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3169 4 " = ") |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3170 (rc sh-modify sh |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3171 2 "for( " |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3172 6 " ) {" |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
3173 15 ?\} ) |
6463 | 3174 (sh "Index variable: " |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3175 > "for " str " in " _ "; do" \n |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3176 > _ | ?$ & (sh-remember-variable str) \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3177 "done" > \n)) |
6463 | 3178 |
3179 | |
3180 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3181 (define-skeleton sh-indexed-loop |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3182 "Insert an indexed loop from 1 to n. See `sh-feature'." |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3183 (bash sh-modify posix) |
6463 | 3184 (csh "Index variable: " |
3185 "@ " str " = 1" \n | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3186 "while( $" str " <= " (read-string "upper limit: ") " )" \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3187 > _ ?$ str \n |
6463 | 3188 "@ " str "++" \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3189 < "end" \n) |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3190 (es sh-modify rc |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3191 4 " =") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3192 (ksh88 "Index variable: " |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3193 > "integer " str "=0" \n |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3194 > "while (( ( " str " += 1 ) <= " |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3195 (read-string "upper limit: ") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3196 " )); do" \n |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3197 > _ ?$ (sh-remember-variable str) > \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3198 "done" > \n) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3199 (posix "Index variable: " |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3200 > str "=1" \n |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3201 "while [ $" str " -le " |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3202 (read-string "upper limit: ") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3203 " ]; do" \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3204 > _ ?$ str \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3205 str ?= (sh-add (sh-remember-variable str) 1) \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3206 "done" > \n) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3207 (rc "Index variable: " |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3208 > "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
|
3209 (read-string "upper limit: ") |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3210 "; i++ ) print i }'`}) {" \n |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3211 > _ ?$ (sh-remember-variable str) \n |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
3212 ?\} > \n) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3213 (sh "Index variable: " |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3214 > "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
|
3215 (read-string "upper limit: ") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3216 "; i++ ) print i }'`; do" \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3217 > _ ?$ (sh-remember-variable str) \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3218 "done" > \n)) |
6463 | 3219 |
3220 | |
14418
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3221 (defun sh-shell-initialize-variables () |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3222 "Scan the buffer for variable assignments. |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3223 Add these variables to `sh-shell-variables'." |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3224 (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
|
3225 (save-excursion |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3226 (goto-char (point-min)) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3227 (setq sh-shell-variables-initialized t) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3228 (while (search-forward "=" nil t) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3229 (sh-assignment 0))) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3230 (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
|
3231 (buffer-name))) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3232 |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3233 (defvar sh-add-buffer) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3234 |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3235 (defun sh-add-completer (string predicate code) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3236 "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
|
3237 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
|
3238 so it takes three arguments: |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3239 STRING, the current buffer contents; |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3240 PREDICATE, the predicate for filtering possible matches; |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3241 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
|
3242 CODE can be nil, t or `lambda'. |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3243 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
|
3244 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
|
3245 `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
|
3246 (let ((sh-shell-variables |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3247 (save-excursion |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3248 (set-buffer sh-add-buffer) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3249 (or sh-shell-variables-initialized |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3250 (sh-shell-initialize-variables)) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3251 (nconc (mapcar (lambda (var) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3252 (let ((name |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3253 (substring var 0 (string-match "=" var)))) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3254 (cons name name))) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3255 process-environment) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3256 sh-shell-variables)))) |
49306
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3257 (case code |
52322
e9922af67382
(sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents:
52099
diff
changeset
|
3258 ((nil) (try-completion string sh-shell-variables predicate)) |
49306
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3259 (lambda (test-completion string sh-shell-variables predicate)) |
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3260 (t (all-completions string sh-shell-variables predicate))))) |
14418
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3261 |
6463 | 3262 (defun sh-add (var delta) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3263 "Insert an addition of VAR and prefix DELTA for Bourne (type) shell." |
6463 | 3264 (interactive |
14418
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3265 (let ((sh-add-buffer (current-buffer))) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3266 (list (completing-read "Variable: " 'sh-add-completer) |
7f58ca0014ef
(sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14221
diff
changeset
|
3267 (prefix-numeric-value current-prefix-arg)))) |
61534
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3268 (insert (sh-feature '((bash . "$(( ") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3269 (ksh88 . "$(( ") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3270 (posix . "$(( ") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3271 (rc . "`{expr $") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3272 (sh . "`expr $") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3273 (zsh . "$[ "))) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3274 (sh-remember-variable var) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3275 (if (< delta 0) " - " " + ") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3276 (number-to-string (abs delta)) |
61534
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3277 (sh-feature '((bash . " ))") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3278 (ksh88 . " ))") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3279 (posix . " ))") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3280 (rc . "}") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3281 (sh . "`") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3282 (zsh . " ]"))))) |
6463 | 3283 |
3284 | |
3285 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3286 (define-skeleton sh-function |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3287 "Insert a function definition. See `sh-feature'." |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3288 (bash sh-modify ksh88 |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3289 3 "() {") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3290 (ksh88 "name: " |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3291 "function " str " {" \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3292 > _ \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3293 < "}" \n) |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3294 (rc sh-modify ksh88 |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3295 1 "fn ") |
6463 | 3296 (sh () |
3297 "() {" \n | |
3298 > _ \n | |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3299 < "}" \n)) |
6463 | 3300 |
3301 | |
3302 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3303 (define-skeleton sh-if |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3304 "Insert an if statement. See `sh-feature'." |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3305 (csh "condition: " |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3306 "if( " str " ) then" \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3307 > _ \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3308 ( "other condition, %s: " |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3309 < "else if( " str " ) then" \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3310 > _ \n) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3311 < "else" \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3312 > _ \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3313 resume: |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3314 < "endif" \n) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3315 (es "condition: " |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3316 > "if { " str " } {" \n |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3317 > _ \n |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3318 ( "other condition, %s: " |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3319 "} { " str " } {" > \n |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3320 > _ \n) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3321 "} {" > \n |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3322 > _ \n |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3323 resume: |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
3324 ?\} > \n) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3325 (rc "condition: " |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3326 > "if( " str " ) {" \n |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3327 > _ \n |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3328 ( "other condition, %s: " |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3329 "} else if( " str " ) {" > \n |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3330 > _ \n) |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3331 "} else {" > \n |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3332 > _ \n |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3333 resume: |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
3334 ?\} > \n) |
6463 | 3335 (sh "condition: " |
12863 | 3336 '(setq input (sh-feature sh-test)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3337 > "if " str "; then" \n |
6463 | 3338 > _ \n |
3339 ( "other condition, %s: " | |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3340 > "elif " str "; then" > \n |
51594
ad56e8962943
(sh-while-getopts, sh-if, sh-case): Revert part of previous change.
Juanma Barranquero <lekktu@gmail.com>
parents:
51515
diff
changeset
|
3341 > \n) |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3342 "else" > \n |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3343 > \n |
6463 | 3344 resume: |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3345 "fi" > \n)) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3346 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3347 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3348 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3349 (define-skeleton sh-repeat |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3350 "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
|
3351 (es nil |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3352 > "forever {" \n |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3353 > _ \n |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
3354 ?\} > \n) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3355 (zsh "factor: " |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3356 > "repeat " str "; do" > \n |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3357 > \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3358 "done" > \n)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3359 |
17501
478f9bb8575c
Remove all menu-enable properties except for sh-case.
Richard M. Stallman <rms@gnu.org>
parents:
17480
diff
changeset
|
3360 ;;;(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
|
3361 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3362 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3363 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3364 (define-skeleton sh-select |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3365 "Insert a select statement. See `sh-feature'." |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3366 (ksh88 "Index variable: " |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3367 > "select " str " in " _ "; do" \n |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3368 > ?$ str \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3369 "done" > \n) |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3370 (bash sh-append ksh88)) |
17501
478f9bb8575c
Remove all menu-enable properties except for sh-case.
Richard M. Stallman <rms@gnu.org>
parents:
17480
diff
changeset
|
3371 ;;;(put 'sh-select 'menu-enable '(sh-feature sh-select)) |
6463 | 3372 |
3373 | |
3374 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3375 (define-skeleton sh-tmp-file |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3376 "Insert code to setup temporary file handling. See `sh-feature'." |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3377 (bash sh-append ksh88) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3378 (csh (file-name-nondirectory (buffer-file-name)) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3379 "set tmp = /tmp/" str ".$$" \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3380 "onintr exit" \n _ |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3381 (and (goto-char (point-max)) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3382 (not (bolp)) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3383 ?\n) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3384 "exit:\n" |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3385 "rm $tmp* >&/dev/null" > \n) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3386 (es (file-name-nondirectory (buffer-file-name)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3387 > "local( signals = $signals sighup sigint; tmp = /tmp/" str |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3388 ".$pid ) {" \n |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3389 > "catch @ e {" \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3390 > "rm $tmp^* >[2]/dev/null" \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3391 "throw $e" \n |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3392 "} {" > \n |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3393 _ \n |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
3394 ?\} > \n |
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
3395 ?\} > \n) |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3396 (ksh88 sh-modify sh |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3397 7 "EXIT") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3398 (rc (file-name-nondirectory (buffer-file-name)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3399 > "tmp = /tmp/" str ".$pid" \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3400 "fn sigexit { rm $tmp^* >[2]/dev/null }" \n) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3401 (sh (file-name-nondirectory (buffer-file-name)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3402 > "TMP=${TMPDIR:-/tmp}/" str ".$$" \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3403 "trap \"rm $TMP* 2>/dev/null\" " ?0 \n)) |
6463 | 3404 |
3405 | |
3406 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3407 (define-skeleton sh-until |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3408 "Insert an until loop. See `sh-feature'." |
6463 | 3409 (sh "condition: " |
12863 | 3410 '(setq input (sh-feature sh-test)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3411 > "until " str "; do" \n |
6463 | 3412 > _ \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3413 "done" > \n)) |
17501
478f9bb8575c
Remove all menu-enable properties except for sh-case.
Richard M. Stallman <rms@gnu.org>
parents:
17480
diff
changeset
|
3414 ;;;(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
|
3415 |
6463 | 3416 |
3417 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3418 (define-skeleton sh-while |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3419 "Insert a while loop. See `sh-feature'." |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3420 (csh sh-modify sh |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3421 2 "" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3422 3 "while( " |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3423 5 " )" |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3424 10 '< |
37542
51f2e2a0c455
(sh-prev-line): Look for sh-heredoc-face
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37528
diff
changeset
|
3425 11 "end") |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3426 (es sh-modify sh |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3427 3 "while { " |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3428 5 " } {" |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
3429 10 ?\} ) |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3430 (rc sh-modify sh |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3431 3 "while( " |
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3432 5 " ) {" |
40335
96186171af6d
no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents:
39890
diff
changeset
|
3433 10 ?\} ) |
6463 | 3434 (sh "condition: " |
12863 | 3435 '(setq input (sh-feature sh-test)) |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3436 > "while " str "; do" \n |
6463 | 3437 > _ \n |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3438 "done" > \n)) |
6463 | 3439 |
3440 | |
3441 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3442 (define-skeleton sh-while-getopts |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3443 "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
|
3444 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
|
3445 option followed by a colon `:' if the option accepts an argument." |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3446 (bash sh-modify sh |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3447 18 "${0##*/}") |
12863 | 3448 (csh nil |
3449 "while( 1 )" \n | |
3450 > "switch( \"$1\" )" \n | |
3451 '(setq input '("- x" . 2)) | |
3452 > > | |
3453 ( "option, %s: " | |
3454 < "case " '(eval str) | |
3455 '(if (string-match " +" str) | |
3456 (setq v1 (substring str (match-end 0)) | |
3457 str (substring str 0 (match-beginning 0))) | |
3458 (setq v1 nil)) | |
3459 str ?: \n | |
3460 > "set " v1 & " = $2" | -4 & _ \n | |
3461 (if v1 "shift") & \n | |
3462 "breaksw" \n) | |
3463 < "case --:" \n | |
3464 > "shift" \n | |
3465 < "default:" \n | |
3466 > "break" \n | |
3467 resume: | |
3468 < < "endsw" \n | |
3469 "shift" \n | |
39890
bc9296467c86
(sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38079
diff
changeset
|
3470 < "end" \n) |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3471 (ksh88 sh-modify sh |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3472 16 "print" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3473 18 "${0##*/}" |
51515
6d06c54cda5d
Fix bug in "Options Loop" skeleton for ksh. Add newlines to a few skeletons,
Juanma Barranquero <lekktu@gmail.com>
parents:
51379
diff
changeset
|
3474 37 "OPTIND-1") |
52758
aaeb60b0150f
(sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents:
52682
diff
changeset
|
3475 (posix sh-modify sh |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3476 18 "$(basename $0)") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3477 (sh "optstring: " |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3478 > "while getopts :" str " OPT; do" \n |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3479 > "case $OPT in" \n |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3480 '(setq v1 (append (vconcat str) nil)) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3481 ( (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
|
3482 (if (eq (nth 1 v1) ?:) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3483 (setq v1 (nthcdr 2 v1) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3484 v2 "\"$OPTARG\"") |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3485 (setq v1 (cdr v1) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3486 v2 nil))) |
49306
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3487 > str "|+" str sh-non-closing-paren \n |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3488 > _ v2 \n |
51594
ad56e8962943
(sh-while-getopts, sh-if, sh-case): Revert part of previous change.
Juanma Barranquero <lekktu@gmail.com>
parents:
51515
diff
changeset
|
3489 > ";;" \n) |
49306
ed0ec7e165de
(sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49176
diff
changeset
|
3490 > "*" sh-non-closing-paren \n |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3491 > "echo" " \"usage: " "`basename $0`" |
15027
30c4f64f3579
(sh-while-getopts): Punctuate help message better.
Richard M. Stallman <rms@gnu.org>
parents:
14892
diff
changeset
|
3492 " [+-" '(setq v1 (point)) str |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3493 '(save-excursion |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3494 (while (search-backward ":" v1 t) |
15027
30c4f64f3579
(sh-while-getopts): Punctuate help message better.
Richard M. Stallman <rms@gnu.org>
parents:
14892
diff
changeset
|
3495 (replace-match " ARG] [+-" t t))) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3496 (if (eq (preceding-char) ?-) -5) |
29844
093c79809c9e
(sh-while-getopts): Fix handling of
Gerd Moellmann <gerd@gnu.org>
parents:
29422
diff
changeset
|
3497 (if (and (sequencep v1) (length v1)) "] " "} ") |
28923
dcafe3c9cd6c
(sh-while-getopts) <sh>: Handle case that
Gerd Moellmann <gerd@gnu.org>
parents:
26967
diff
changeset
|
3498 "[--] ARGS...\"" \n |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3499 "exit 2" > \n |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3500 "esac" > |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3501 \n "done" |
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3502 > \n |
61534
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3503 "shift " (sh-add "OPTIND" -1) \n |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3504 "OPTIND=1" \n)) |
6463 | 3505 |
3506 | |
3507 | |
3508 (defun sh-assignment (arg) | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3509 "Remember preceding identifier for future completion and do self-insert." |
6463 | 3510 (interactive "p") |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3511 (self-insert-command arg) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3512 (if (<= arg 1) |
6463 | 3513 (sh-remember-variable |
3514 (save-excursion | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3515 (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
|
3516 (prog1 (point) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3517 (beginning-of-line 1)) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3518 t) |
13391
550ecb2269b0
(sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents:
13389
diff
changeset
|
3519 (match-string 1)))))) |
6463 | 3520 |
3521 | |
3522 (defun sh-maybe-here-document (arg) | |
32480
261dcd5e9f0a
(sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31731
diff
changeset
|
3523 "Insert self. Without prefix, following unquoted `<' inserts here document. |
6463 | 3524 The document is bounded by `sh-here-document-word'." |
3525 (interactive "*P") | |
3526 (self-insert-command (prefix-numeric-value arg)) | |
3527 (or arg | |
3528 (not (eq (char-after (- (point) 2)) last-command-char)) | |
3529 (save-excursion | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3530 (backward-char 2) |
6463 | 3531 (sh-quoted-p)) |
61534
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3532 (let ((tabs (if (string-match "\\`-" sh-here-document-word) |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3533 (make-string (/ (current-indentation) tab-width) ?\t) |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3534 "")) |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3535 (delim (replace-regexp-in-string "['\"]" "" |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3536 sh-here-document-word))) |
6463 | 3537 (insert sh-here-document-word) |
64051
d700ccca5bd4
(sh, sh-script): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63885
diff
changeset
|
3538 (or (eolp) (looking-at "[ \t]") (insert ?\s)) |
6463 | 3539 (end-of-line 1) |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3540 (while |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3541 (sh-quoted-p) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3542 (end-of-line 2)) |
61534
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3543 (insert ?\n tabs) |
51265
575ad90ca254
(sh-here-document-word): Document new treatment of leading "-".
Glenn Morris <rgm@gnu.org>
parents:
49743
diff
changeset
|
3544 (save-excursion |
61534
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3545 (insert ?\n tabs (replace-regexp-in-string |
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3546 "\\`-?[ \t]*" "" delim)))))) |
6463 | 3547 |
3548 | |
3549 ;; various other commands | |
3550 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3551 (autoload 'comint-dynamic-complete "comint" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3552 "Dynamically perform completion at point." t) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3553 |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3554 (autoload 'shell-dynamic-complete-command "shell" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3555 "Dynamically complete the command at point." t) |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3556 |
6463 | 3557 (autoload 'comint-dynamic-complete-filename "comint" |
3558 "Dynamically complete the filename at point." t) | |
3559 | |
12505
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3560 (autoload 'shell-dynamic-complete-environment-variable "shell" |
0f970ed476cb
restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents:
12034
diff
changeset
|
3561 "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
|
3562 |
6463 | 3563 |
3564 | |
12887
cbed067bf52d
(sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents:
12864
diff
changeset
|
3565 (defun sh-newline-and-indent () |
cbed067bf52d
(sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents:
12864
diff
changeset
|
3566 "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
|
3567 (interactive "*") |
cbed067bf52d
(sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents:
12864
diff
changeset
|
3568 (indent-to (prog1 (current-indentation) |
cbed067bf52d
(sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents:
12864
diff
changeset
|
3569 (delete-region (point) |
cbed067bf52d
(sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents:
12864
diff
changeset
|
3570 (progn |
cbed067bf52d
(sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents:
12864
diff
changeset
|
3571 (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
|
3572 (if (sh-quoted-p) |
cbed067bf52d
(sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents:
12864
diff
changeset
|
3573 (forward-char))) |
cbed067bf52d
(sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents:
12864
diff
changeset
|
3574 (point))) |
cbed067bf52d
(sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents:
12864
diff
changeset
|
3575 (newline)))) |
6463 | 3576 |
3577 (defun sh-beginning-of-command () | |
3578 "Move point to successive beginnings of commands." | |
3579 (interactive) | |
3580 (if (re-search-backward sh-beginning-of-command nil t) | |
3581 (goto-char (match-beginning 2)))) | |
3582 | |
3583 (defun sh-end-of-command () | |
3584 "Move point to successive ends of commands." | |
3585 (interactive) | |
3586 (if (re-search-forward sh-end-of-command nil t) | |
3587 (goto-char (match-end 1)))) | |
3588 | |
59566
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3589 ;; Backslashification. Stolen from make-mode.el. |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3590 |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3591 (defun sh-backslash-region (from to delete-flag) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3592 "Insert, align, or delete end-of-line backslashes on the lines in the region. |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3593 With no argument, inserts backslashes and aligns existing backslashes. |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3594 With an argument, deletes the backslashes. |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3595 |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3596 This function does not modify the last line of the region if the region ends |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3597 right at the start of the following line; it does not modify blank lines |
61534
3d7c70a6a91e
(sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
61394
diff
changeset
|
3598 at the start of the region. So you can put the region around an entire |
59566
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3599 shell command and conveniently use this command." |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3600 (interactive "r\nP") |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3601 (save-excursion |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3602 (goto-char from) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3603 (let ((column sh-backslash-column) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3604 (endmark (make-marker))) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3605 (move-marker endmark to) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3606 ;; Compute the smallest column number past the ends of all the lines. |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3607 (if sh-backslash-align |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3608 (progn |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3609 (if (not delete-flag) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3610 (while (< (point) to) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3611 (end-of-line) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3612 (if (= (preceding-char) ?\\) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3613 (progn (forward-char -1) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3614 (skip-chars-backward " \t"))) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3615 (setq column (max column (1+ (current-column)))) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3616 (forward-line 1))) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3617 ;; Adjust upward to a tab column, if that doesn't push |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3618 ;; past the margin. |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3619 (if (> (% column tab-width) 0) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3620 (let ((adjusted (* (/ (+ column tab-width -1) tab-width) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3621 tab-width))) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3622 (if (< adjusted (window-width)) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3623 (setq column adjusted)))))) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3624 ;; Don't modify blank lines at start of region. |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3625 (goto-char from) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3626 (while (and (< (point) endmark) (eolp)) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3627 (forward-line 1)) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3628 ;; Add or remove backslashes on all the lines. |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3629 (while (and (< (point) endmark) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3630 ;; Don't backslashify the last line |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3631 ;; if the region ends right at the start of the next line. |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3632 (save-excursion |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3633 (forward-line 1) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3634 (< (point) endmark))) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3635 (if (not delete-flag) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3636 (sh-append-backslash column) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3637 (sh-delete-backslash)) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3638 (forward-line 1)) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3639 (move-marker endmark nil)))) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3640 |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3641 (defun sh-append-backslash (column) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3642 (end-of-line) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3643 ;; Note that "\\\\" is needed to get one backslash. |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3644 (if (= (preceding-char) ?\\) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3645 (progn (forward-char -1) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3646 (delete-horizontal-space) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3647 (indent-to column (if sh-backslash-align nil 1))) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3648 (indent-to column (if sh-backslash-align nil 1)) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3649 (insert "\\"))) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3650 |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3651 (defun sh-delete-backslash () |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3652 (end-of-line) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3653 (or (bolp) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3654 (progn |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3655 (forward-char -1) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3656 (if (looking-at "\\\\") |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3657 (delete-region (1+ (point)) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3658 (progn (skip-chars-backward " \t") (point))))))) |
7b97d6104891
(sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents:
59251
diff
changeset
|
3659 |
13707 | 3660 (provide 'sh-script) |
18382 | 3661 |
59622
5ec981fa30e5
(sh-here-doc-open-re): Don't allow `|' or other
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59566
diff
changeset
|
3662 ;; arch-tag: eccd8b72-f337-4fc2-ae86-18155a69d937 |
25986
29aeb35781cd
Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents:
25554
diff
changeset
|
3663 ;;; sh-script.el ends here |