annotate lisp/progmodes/sh-script.el @ 106840:5df8e547a422

Fix typos in docstrings.
author Juanma Barranquero <lekktu@gmail.com>
date Thu, 14 Jan 2010 19:59:31 +0100
parents 1d1d5d9bd884
children 349c5e0bbe82
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; sh-script.el --- shell-script editing commands for Emacs
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14148
diff changeset
2
104778
afa0e028ba97 Mark face aliases with "-face" suffix as obsolete.
Glenn Morris <rgm@gnu.org>
parents: 104298
diff changeset
3 ;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2001, 2002, 2003,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 105823
diff changeset
4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
23869
8d2bb5d1416a Update comment.
Karl Heuer <kwzh@gnu.org>
parents: 23589
diff changeset
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
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94046
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94046
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94046
diff changeset
16 ;; (at your option) any later version.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94046
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
28 ;; 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
29 ;; 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
30 ;; 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
31 ;; 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
32 ;; the environment as well as commands.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
33
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
34 ;;; Known Bugs:
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
36 ;; - 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
37 ;; - 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
38 ;; syntactically distinguishing those from `'' strings.
8257
bbf6304598d9 "Comment out" autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents: 8121
diff changeset
39
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
40 ;; Indentation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
41 ;; ===========
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
42 ;; 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
43 ;; 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
44 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
45 ;; 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
46 ;; zsh, ...).
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
47 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
48 ;; 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
49 ;; 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
50 ;; 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
51 ;; 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
52 ;; 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
53 ;; 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
54 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
55 ;; 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
56 ;; 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
57 ;; 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
58 ;; 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
59 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
60 ;; + Indent right by sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
61 ;; - Indent left by sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
62 ;; ++ Indent right twice sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
63 ;; -- Indent left twice sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
64 ;; * Indent right half sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
65 ;; / 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
66 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
67 ;; 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
68 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
69 ;; `sh-show-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
70 ;; 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
71 ;; line and its value.
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
72 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
73 ;; `sh-set-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
74 ;; 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
75 ;; 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
76 ;; 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
77 ;; 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
78 ;; 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
79 ;; 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
80 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
81 ;; `sh-learn-line-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
82 ;; 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
83 ;; 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
84 ;; 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
85 ;; 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
86 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
87 ;; `sh-learn-buffer-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
88 ;; 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
89 ;; 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
90 ;; 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
91 ;; 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
92 ;; 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
93 ;; 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
94 ;; non-nil.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
95 ;; `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
96 ;; 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
97 ;; 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
98 ;; `sh-learn-basic-offset'.
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
99 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
100 ;; 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
101 ;; (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
102 ;; 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
103 ;; 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
104 ;; *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
105 ;; `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
106 ;; suffice.
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
107 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
108 ;; Saving indentation values
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
109 ;; -------------------------
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
110 ;; 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
111 ;; 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
112 ;; 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
113 ;; the buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
114 ;; You can do this automatically like this:
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
115 ;; (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
116 ;;
47264
05606bafb8f5 (sh-indent-for-fi, sh-indent-for-done): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents: 45900
diff changeset
117 ;; However... `sh-learn-buffer-indent' is extremely slow,
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
118 ;; 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
119 ;; "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
120 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
121 ;; 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
122 ;; 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
123 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
124 ;; 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
125 ;; the current buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
126 ;; 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
127 ;; buffer from a specific style.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
128 ;; 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
129 ;; 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
130 ;; `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
131 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
132 ;; Indentation variables - buffer local or global?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
133 ;; ----------------------------------------------
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
134 ;; 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
135 ;; 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
136 ;; 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
137 ;; 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
138 ;;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
139 ;; 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
140 ;; 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
141 ;;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
142 ;; 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
143 ;; buffer local when the mode is established.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
144 ;; 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
145 ;; 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
146 ;; 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
147 ;; 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
148 ;;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
149 ;; 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
150 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
151 ;; Awkward things, pitfalls
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
152 ;; ------------------------
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
153 ;; 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
154 ;;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
155 ;; 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
156 ;; 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
157 ;; 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
158 ;; 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
159 ;; things quite tricky!
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
160 ;; 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
161 ;; 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
162 ;; containing the "<<" symbol.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
163 ;; 4. A line may be continued using the "\".
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
164 ;; 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
165 ;; 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
166 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
167 ;; 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
168 ;; 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
169 ;; disadvantages:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
170 ;; 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
171 ;; case alternative, to find any here documents, and handle "$#".
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
172 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
173 ;; Bugs
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
174 ;; ----
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
175 ;; - 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
176 ;; 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
177 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
178 ;; - `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
179 ;;
78197
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
180 ;; - "case $x in y) echo ;; esac)" the last ) is mis-identified as being
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
181 ;; part of a case-pattern. You need to add a semi-colon after "esac" to
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
182 ;; coerce sh-script into doing the right thing.
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
183 ;;
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
184 ;; - "echo $z in ps | head)" the last ) is mis-identified as being part of
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
185 ;; a case-pattern. You need to put the "in" between quotes to coerce
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
186 ;; sh-script into doing the right thing.
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
187 ;;
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
188 ;; - A line starting with "}>foo" is not indented like "} >foo".
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
189 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
190 ;; Richard Sharman <rsharman@pobox.com> June 1999.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
191
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ;;; Code:
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ;; page 1: variables and settings
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
195 ;; page 2: indentation stuff
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
196 ;; page 3: mode-command and utility functions
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
197 ;; page 4: statement syntax-commands for various shells
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
198 ;; page 5: various other commands
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199
32503
3470d692f2e0 Require skeleton and comint when
Dave Love <fx@gnu.org>
parents: 32480
diff changeset
200 (eval-when-compile
3470d692f2e0 Require skeleton and comint when
Dave Love <fx@gnu.org>
parents: 32480
diff changeset
201 (require 'skeleton)
49306
ed0ec7e165de (sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49176
diff changeset
202 (require 'cl)
32503
3470d692f2e0 Require skeleton and comint when
Dave Love <fx@gnu.org>
parents: 32480
diff changeset
203 (require 'comint))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
204 (require 'executable)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205
65239
a1c74fb41c2b (font-lock-comment-face, font-lock-set-defaults, font-lock-string-face):
Juanma Barranquero <lekktu@gmail.com>
parents: 64971
diff changeset
206 (defvar font-lock-comment-face)
a1c74fb41c2b (font-lock-comment-face, font-lock-set-defaults, font-lock-string-face):
Juanma Barranquero <lekktu@gmail.com>
parents: 64971
diff changeset
207 (defvar font-lock-set-defaults)
a1c74fb41c2b (font-lock-comment-face, font-lock-set-defaults, font-lock-string-face):
Juanma Barranquero <lekktu@gmail.com>
parents: 64971
diff changeset
208 (defvar font-lock-string-face)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
209
17068
d1391b21626f (sh-mode-hook, sh-set-shell-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents: 16839
diff changeset
210
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
211 (defgroup sh nil
64051
d700ccca5bd4 (sh, sh-script): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents: 63885
diff changeset
212 "Shell programming utilities."
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
213 :group 'languages)
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 (defgroup sh-script nil
64051
d700ccca5bd4 (sh, sh-script): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents: 63885
diff changeset
216 "Shell script mode."
66963
a11fdee52c05 Add :link (custom-group-link font-lock-faces) to defgroup.
Juri Linkov <juri@jurta.org>
parents: 66269
diff changeset
217 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
218 :group 'sh
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
219 :prefix "sh-")
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
220
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
221
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
222 (defcustom sh-ancestor-alist
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
223 '((ash . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
224 (bash . jsh)
29109
0e45e6e90467 (sh-ancestor-alist): Add `bash2'.
Gerd Moellmann <gerd@gnu.org>
parents: 28923
diff changeset
225 (bash2 . jsh)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
226 (dtksh . ksh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
227 (es . rc)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
228 (itcsh . tcsh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
229 (jcsh . csh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
230 (jsh . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
231 (ksh . ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
232 (ksh88 . jsh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
233 (oash . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
234 (pdksh . ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
235 (posix . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
236 (tcsh . csh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
237 (wksh . ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
238 (wsh . sh)
23501
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
239 (zsh . ksh88)
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
240 (rpm . sh))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
241 "Alist showing the direct ancestor of various shells.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
242 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
243 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
244
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
245 csh C Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
246 jcsh C Shell with Job Control
100877
4d4c11933279 (sh-ancestor-alist): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 98331
diff changeset
247 tcsh TENEX C Shell
4d4c11933279 (sh-ancestor-alist): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 98331
diff changeset
248 itcsh Ian's TENEX C Shell
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
249 rc Plan 9 Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
250 es Extensible Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
251 sh Bourne Shell
101311
f920ab2e8179 Very minor doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 101002
diff changeset
252 ash Almquist Shell
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
253 jsh Bourne Shell with Job Control
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
254 bash GNU Bourne Again Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
255 ksh88 Korn Shell '88
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
256 ksh Korn Shell '93
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
257 dtksh CDE Desktop Korn Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
258 pdksh Public Domain Korn Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
259 wksh Window Korn Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
260 zsh Z Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
261 oash SCO OA (curses) Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
262 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
263 wsh ? Shell"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
264 :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
265 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
266
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
267
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
268 (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
269 (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
270 '((csh . tcsh)
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
271 (ksh . pdksh)))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
272 ;; for the time being
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
273 '((ksh . ksh88)
29109
0e45e6e90467 (sh-ancestor-alist): Add `bash2'.
Gerd Moellmann <gerd@gnu.org>
parents: 28923
diff changeset
274 (bash2 . bash)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
275 (sh5 . sh)))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
276 "Alist for transforming shell names to what they really are.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
277 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
278 shell it really is."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
279 :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
280 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
281
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
282
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
283 (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
284 (or
16839
daaa2c5bb40a (sh-shell-file): Downcase and remove extension on shells in NT.
Richard M. Stallman <rms@gnu.org>
parents: 16810
diff changeset
285 ;; 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
286 ;; 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
287 ;; 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
288 (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
289 (let* ((shell (getenv "SHELL"))
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
290 (shell-base
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
291 (and shell (file-name-nondirectory shell))))
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
292 ;; 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
293 ;; so use the default instead.
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
294 (if (or (null shell)
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
295 (member (downcase shell-base)
21980
e73c0672d7b3 (sh-shell-file): Add cmdproxy to MS shells.
Richard M. Stallman <rms@gnu.org>
parents: 21925
diff changeset
296 '("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
297 "cmdproxy.exe")))
21925
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
298 "/bin/sh"
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
299 (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
300 (getenv "SHELL")
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
301 "/bin/sh")
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
302 "The executable file name for the shell being programmed."
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
303 :type 'string
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
304 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
305
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
306
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
307 (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
308 ;; 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
309 '((bash)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
310 (csh . "-f")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
311 (pdksh)
14886
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
312 ;; 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
313 (ksh88)
14886
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
314 ;; -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
315 (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
316 ;; 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
317 ;; 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
318 (wksh)
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
319 ;; -f means don't run .zshrc.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
320 (zsh . "-f"))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
321 "Single argument string for the magic number. See `sh-feature'."
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
322 :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
323 (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
324 (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
325 (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
326 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
327
20395
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
328 (defcustom sh-imenu-generic-expression
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
329 `((sh
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
330 . ((nil "^\\s-*\\(function\\s-+\\)?\\([[:alpha:]_][[:alnum:]_]+\\)\\s-*()" 2))))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
331 "Alist of regular expressions for recognizing shell function definitions.
35180
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
332 See `sh-feature' and `imenu-generic-expression'."
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
333 :type '(alist :key-type (symbol :tag "Shell")
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
334 :value-type (alist :key-type (choice :tag "Title"
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
335 string
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
336 (const :tag "None" nil))
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
337 :value-type
f4733aab37df (sh-imenu-generic-expression): Fix doc,
Dave Love <fx@gnu.org>
parents: 33430
diff changeset
338 (repeat :tag "Regexp, index..." sexp)))
21669
9861518505cb *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20900
diff changeset
339 :group 'sh-script
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
340 :version "20.4")
20395
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
341
14195
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
342 (defvar sh-shell-variables nil
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
343 "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
344 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
345 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
346 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
347
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
348 (defvar sh-shell-variables-initialized nil
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
349 "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
350
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
351 (defun sh-canonicalize-shell (shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
352 "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
353 (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
354 (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
355 (or (symbolp shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
356 (setq shell (intern shell)))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
357 (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
358 shell))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
359
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
360 (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
361 "The shell being programmed. This is set by \\[sh-set-shell].")
70144
60a94b1ec37e (sh-shell): Mark as safe.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 69149
diff changeset
362 ;;;###autoload(put 'sh-shell 'safe-local-variable 'symbolp)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
363
56688
6eee795cb9eb (sh-set-shell): Use sh-mode-abbrev-table.
Richard M. Stallman <rms@gnu.org>
parents: 55119
diff changeset
364 (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
365
6eee795cb9eb (sh-set-shell): Use sh-mode-abbrev-table.
Richard M. Stallman <rms@gnu.org>
parents: 55119
diff changeset
366 (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
367
6eee795cb9eb (sh-set-shell): Use sh-mode-abbrev-table.
Richard M. Stallman <rms@gnu.org>
parents: 55119
diff changeset
368
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
369 ;; 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
370 ;; 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
371 ;;(defvar sh-abbrevs
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
372 ;; '((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
373 ;; "switch" 'sh-case
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
374 ;; "getopts" 'sh-while-getopts)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
375
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
376 ;; (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
377 ;; "function" 'sh-function)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
378
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
379 ;; (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
380 ;; "select" 'sh-select)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
381
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
382 ;; (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
383 ;; "case" 'sh-case
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
384 ;; "function" 'sh-function)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
385
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
386 ;; (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
387 ;; "case" 'sh-case
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
388 ;; "function" 'sh-function
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
389 ;; "until" 'sh-until
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
390 ;; "getopts" 'sh-while-getopts)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
391
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
392 ;; ;; 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
393 ;; (shell "for" sh-for
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
394 ;; "loop" sh-indexed-loop
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
395 ;; "if" sh-if
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
396 ;; "tmpfile" sh-tmp-file
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
397 ;; "while" sh-while)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
398
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
399 ;; (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
400 ;; "repeat" 'sh-repeat))
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
401 ;; "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
402 ;;;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
403 ;;;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
404
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
407 (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
408 "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
409 (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
410 (while list
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
411 (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
412 table)
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
413
52682
a7331078ec76 (sh-mode-syntax-table): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 52619
diff changeset
414 (defvar sh-mode-syntax-table nil
a7331078ec76 (sh-mode-syntax-table): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 52619
diff changeset
415 "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
416 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
417
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
418 (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
419 (sh-mode-syntax-table ()
41349
8dd8d78194a1 (sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents: 41348
diff changeset
420 ?\# "<"
8dd8d78194a1 (sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents: 41348
diff changeset
421 ?\n ">#"
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 ?\` "\"`"
62242
cce9501aab6e (sh-mode-default-syntax-table): Set the
Dan Nicolaescu <dann@ics.uci.edu>
parents: 62214
diff changeset
425 ;; ?$ 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
426 ;; 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
427 ;; $VARNAME works.
cce9501aab6e (sh-mode-default-syntax-table): Set the
Dan Nicolaescu <dann@ics.uci.edu>
parents: 62214
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 ?% "_"
8dd8d78194a1 (sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents: 41348
diff changeset
431 ?: "_"
8dd8d78194a1 (sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents: 41348
diff changeset
432 ?. "_"
8dd8d78194a1 (sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents: 41348
diff changeset
433 ?^ "_"
8dd8d78194a1 (sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents: 41348
diff changeset
434 ?~ "_"
51970
be96dd81138a (sh-mode-syntax-table): Change syntax of ?, to "_".
Andreas Schwab <schwab@suse.de>
parents: 51727
diff changeset
435 ?, "_"
57159
e00b0d40b4bc (sh-mode-default-syntax-table): Set syntax of = to "." (punctuation).
Richard M. Stallman <rms@gnu.org>
parents: 56688
diff changeset
436 ?= "."
41349
8dd8d78194a1 (sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents: 41348
diff changeset
437 ?< "."
8dd8d78194a1 (sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents: 41348
diff changeset
438 ?> ".")
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
439 "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
440
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
441 (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
442 '((sh . nil))
41349
8dd8d78194a1 (sh-mode-syntax-table): Function restored.
Richard M. Stallman <rms@gnu.org>
parents: 41348
diff changeset
443 "Syntax-table used in Shell-Script mode. See `sh-feature'.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (defvar sh-mode-map
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
446 (let ((map (make-sparse-keymap))
93536
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
447 (menu-map (make-sparse-keymap)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (define-key map "\C-c(" 'sh-function)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (define-key map "\C-c\C-w" 'sh-while)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (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
451 (define-key map "\C-c\C-t" 'sh-tmp-file)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (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
453 (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
454 (define-key map "\C-c\C-o" 'sh-while-getopts)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (define-key map "\C-c\C-l" 'sh-indexed-loop)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (define-key map "\C-c\C-i" 'sh-if)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (define-key map "\C-c\C-f" 'sh-for)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 (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
459 (define-key map "\C-c?" 'sh-show-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
460 (define-key map "\C-c=" 'sh-set-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
461 (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
462 (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
463 (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
464
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (define-key map "=" 'sh-assignment)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (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
467 (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
468 (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
469 (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
470 (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
471 (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
472 (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
473 (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
474 (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
475 (define-key map "\"" 'skeleton-pair-insert-maybe)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
476
49176
56966d83f3a5 (sh-mode-map): Use command remapping instead of
Andreas Schwab <schwab@suse.de>
parents: 49132
diff changeset
477 (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
478 (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
479 'backward-delete-char-untabify)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (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
481 (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
482 (define-key map [remap forward-sentence] 'sh-end-of-command)
93536
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
483 (define-key map [menu-bar sh-script] (cons "Sh-Script" menu-map))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
484 (define-key menu-map [sh-learn-buffer-indent]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
485 '(menu-item "Learn buffer indentation" sh-learn-buffer-indent
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
486 :help "Learn how to indent the buffer the way it currently is."))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
487 (define-key menu-map [sh-learn-line-indent]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
488 '(menu-item "Learn line indentation" sh-learn-line-indent
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
489 :help "Learn how to indent a line as it currently is indented"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
490 (define-key menu-map [sh-show-indent]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
491 '(menu-item "Show indentation" sh-show-indent
94046
8208c3bf9e0d (sh-show-indent): Fix typo.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93805
diff changeset
492 :help "Show the how the current line would be indented"))
93536
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
493 (define-key menu-map [sh-set-indent]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
494 '(menu-item "Set indentation" sh-set-indent
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
495 :help "Set the indentation for the current line"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
496
94046
8208c3bf9e0d (sh-show-indent): Fix typo.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93805
diff changeset
497 (define-key menu-map [sh-pair]
98331
aa5de5d845d6 (sh-mode-map): Don't assume that skeleton is loaded.
Chong Yidong <cyd@stupidchicken.com>
parents: 98148
diff changeset
498 '(menu-item "Insert braces and quotes in pairs"
aa5de5d845d6 (sh-mode-map): Don't assume that skeleton is loaded.
Chong Yidong <cyd@stupidchicken.com>
parents: 98148
diff changeset
499 (lambda ()
aa5de5d845d6 (sh-mode-map): Don't assume that skeleton is loaded.
Chong Yidong <cyd@stupidchicken.com>
parents: 98148
diff changeset
500 (interactive)
aa5de5d845d6 (sh-mode-map): Don't assume that skeleton is loaded.
Chong Yidong <cyd@stupidchicken.com>
parents: 98148
diff changeset
501 (require 'skeleton)
aa5de5d845d6 (sh-mode-map): Don't assume that skeleton is loaded.
Chong Yidong <cyd@stupidchicken.com>
parents: 98148
diff changeset
502 (setq skeleton-pair (not skeleton-pair)))
aa5de5d845d6 (sh-mode-map): Don't assume that skeleton is loaded.
Chong Yidong <cyd@stupidchicken.com>
parents: 98148
diff changeset
503 :button (:toggle . (and (boundp 'skeleton-pair)
aa5de5d845d6 (sh-mode-map): Don't assume that skeleton is loaded.
Chong Yidong <cyd@stupidchicken.com>
parents: 98148
diff changeset
504 skeleton-pair))
94046
8208c3bf9e0d (sh-show-indent): Fix typo.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93805
diff changeset
505 :help "Inserting a brace or quote automatically inserts the matching pair"))
8208c3bf9e0d (sh-show-indent): Fix typo.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93805
diff changeset
506
93536
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
507 (define-key menu-map [sh-s0] '("--"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
508 ;; Insert
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
509 (define-key menu-map [sh-function]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
510 '(menu-item "Function..." sh-function
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
511 :help "Insert a function definition"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
512 (define-key menu-map [sh-add]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
513 '(menu-item "Addition..." sh-add
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
514 :help "Insert an addition of VAR and prefix DELTA for Bourne (type) shell"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
515 (define-key menu-map [sh-until]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
516 '(menu-item "Until Loop" sh-until
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
517 :help "Insert an until loop"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
518 (define-key menu-map [sh-repeat]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
519 '(menu-item "Repeat Loop" sh-repeat
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
520 :help "Insert a repeat loop definition"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
521 (define-key menu-map [sh-while]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
522 '(menu-item "While Loop" sh-while
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
523 :help "Insert a while loop"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
524 (define-key menu-map [sh-getopts]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
525 '(menu-item "Options Loop" sh-while-getopts
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
526 :help "Insert a while getopts loop."))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
527 (define-key menu-map [sh-indexed-loop]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
528 '(menu-item "Indexed Loop" sh-indexed-loop
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
529 :help "Insert an indexed loop from 1 to n."))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
530 (define-key menu-map [sh-select]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
531 '(menu-item "Select Statement" sh-select
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
532 :help "Insert a select statement "))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
533 (define-key menu-map [sh-if]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
534 '(menu-item "If Statement" sh-if
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
535 :help "Insert an if statement"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
536 (define-key menu-map [sh-for]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
537 '(menu-item "For Loop" sh-for
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
538 :help "Insert a for loop"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
539 (define-key menu-map [sh-case]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
540 '(menu-item "Case Statement" sh-case
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
541 :help "Insert a case/switch statement"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
542 (define-key menu-map [sh-s1] '("--"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
543 (define-key menu-map [sh-exec]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
544 '(menu-item "Execute region" sh-execute-region
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
545 :help "Pass optional header and region to a subshell for noninteractive execution"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
546 (define-key menu-map [sh-exec-interpret]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
547 '(menu-item "Execute script..." executable-interpret
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
548 :help "Run script with user-specified args, and collect output in a buffer"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
549 (define-key menu-map [sh-set-shell]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
550 '(menu-item "Set shell type..." sh-set-shell
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
551 :help "Set this buffer's shell to SHELL (a string)"))
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
552 (define-key menu-map [sh-backslash-region]
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
553 '(menu-item "Backslash region" sh-backslash-region
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
554 :help "Insert, align, or delete end-of-line backslashes on the lines in the region."))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 map)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 "Keymap used in Shell-Script mode.")
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557
65384
96998d31413e (sh-skeleton-pair-default-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents: 65239
diff changeset
558 (defvar sh-skeleton-pair-default-alist '((?( _ ?)) (?\))
96998d31413e (sh-skeleton-pair-default-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents: 65239
diff changeset
559 (?[ ?\s _ ?\s ?]) (?\])
96998d31413e (sh-skeleton-pair-default-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents: 65239
diff changeset
560 (?{ _ ?}) (?\}))
96998d31413e (sh-skeleton-pair-default-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents: 65239
diff changeset
561 "Value to use for `skeleton-pair-default-alist' in Shell-Script mode.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
563 (defcustom sh-dynamic-complete-functions
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
564 '(shell-dynamic-complete-environment-variable
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
565 shell-dynamic-complete-command
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
566 comint-dynamic-complete-filename)
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
567 "Functions for doing TAB dynamic completion."
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
568 :type '(repeat function)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
569 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
572 (defcustom sh-require-final-newline
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
573 '((csh . t)
59251
84ede35ffeb4 (sh-require-final-newline):
Richard M. Stallman <rms@gnu.org>
parents: 58767
diff changeset
574 (pdksh . t))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
575 "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
576 \(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
577 See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
578 :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
579 (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
580 (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
581 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
584 (defcustom sh-assignment-regexp
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
585 '((csh . "\\<\\([[:alnum:]_]+\\)\\(\\[.+\\]\\)?[ \t]*[-+*/%^]?=")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
586 ;; actually spaces are only supported in let/(( ... ))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
587 (ksh88 . "\\<\\([[:alnum:]_]+\\)\\(\\[.+\\]\\)?[ \t]*\\([-+*/%&|~^]\\|<<\\|>>\\)?=")
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
588 (rc . "\\<\\([[:alnum:]_*]+\\)[ \t]*=")
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
589 (sh . "\\<\\([[:alnum:]_]+\\)="))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
590 "Regexp for the variable name and what may follow in an assignment.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
591 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
592 sign. See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
593 :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
594 (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
595 (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
596 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
599 (defcustom sh-indentation 4
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
600 "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
601 :type 'integer
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
602 :group 'sh-script)
79662
f0e20a14ba94 * progmodes/sh-script.el (sh-indentation): Add safe-local-variable property.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78234
diff changeset
603 (put 'sh-indentation 'safe-local-variable 'integerp)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
605 (defcustom sh-remember-variable-min 3
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
606 "Don't remember variables less than this length for completing reads."
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
607 :type 'integer
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
608 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
611 (defvar sh-header-marker nil
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
612 "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
613 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
614
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
615
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
616 (defcustom sh-beginning-of-command
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
617 "\\([;({`|&]\\|\\`\\|[^\\]\n\\)[ \t]*\\([/~[:alnum:]:]\\)"
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
618 "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
619 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
620 :type 'regexp
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
621 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
623
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
624 (defcustom sh-end-of-command
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
625 "\\([/~[:alnum:]:]\\)[ \t]*\\([;#)}`|&]\\|$\\)"
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
626 "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
627 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
628 :type 'regexp
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
629 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632
61534
3d7c70a6a91e (sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 61394
diff changeset
633 (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
634 "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
635 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
636 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
637 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
638 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
639 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
640 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
641 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
642 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
643 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
644 `tab-width'.
3d7c70a6a91e (sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 61394
diff changeset
645
3d7c70a6a91e (sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 61394
diff changeset
646 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
647 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
648 :type 'string
3d7c70a6a91e (sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 61394
diff changeset
649 :group 'sh-script)
3d7c70a6a91e (sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 61394
diff changeset
650
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
652 (defvar sh-test
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
653 '((sh "[ ]" . 3)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
654 (ksh88 "[[ ]]" . 4))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
655 "Initial input in Bourne if, while and until skeletons. See `sh-feature'.")
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
656
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
658 ;; 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
659 ;; 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
660 (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
661 '((bash sh-append posix
61316
283f977b41fb (sh-builtins) <bash>: Add `caller'.
Glenn Morris <rgm@gnu.org>
parents: 60917
diff changeset
662 "." "alias" "bg" "bind" "builtin" "caller" "compgen" "complete"
52322
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
663 "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
664 "jobs" "kill" "let" "local" "popd" "printf" "pushd" "shopt"
50338995d37f (sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents: 52571
diff changeset
665 "source" "suspend" "typeset" "unalias")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
666
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
667 ;; 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
668 (bourne sh-append shell
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
669 "eval" "export" "getopts" "newgrp" "pwd" "read" "readonly"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
670 "times" "ulimit")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
671
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
672 (csh sh-append shell
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
673 "alias" "chdir" "glob" "history" "limit" "nice" "nohup" "rehash"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
674 "setenv" "source" "time" "unalias" "unhash")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
675
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
676 (dtksh sh-append wksh)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
677
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
678 (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
679 "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
680
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
681 (jsh sh-append sh
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
682 "bg" "fg" "jobs" "kill" "stop" "suspend")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
683
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
684 (jcsh sh-append csh
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
685 "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
686
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
687 (ksh88 sh-append bourne
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
688 "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
689 "typeset" "unalias" "whence")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
690
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
691 (oash sh-append sh
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
692 "checkwin" "dateline" "error" "form" "menu" "newwin" "oadeinit"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
693 "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
694 "wclear" "werase" "win" "wmclose" "wmmessage" "wmopen" "wmove"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
695 "wmtitle" "wrefresh")
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 (pdksh sh-append ksh88
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
698 "bind")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
699
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
700 (posix sh-append sh
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
701 "command")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
702
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
703 (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
704 "whatis")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
705
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
706 (sh sh-append bourne
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
707 "hash" "test" "type")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
708
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
709 ;; 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
710 (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
711
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
712 (wksh sh-append ksh88
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
713 ;; FIXME: This looks too much like a regexp. --Stef
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
714 "Xt[A-Z][A-Za-z]*")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
715
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
716 (zsh sh-append ksh88
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
717 "autoload" "bindkey" "builtin" "chdir" "compctl" "declare" "dirs"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
718 "disable" "disown" "echotc" "enable" "functions" "getln" "hash"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
719 "history" "integer" "limit" "local" "log" "popd" "pushd" "r"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
720 "readonly" "rehash" "sched" "setopt" "source" "suspend" "true"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
721 "ttyctl" "type" "unfunction" "unhash" "unlimit" "unsetopt" "vared"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
722 "which"))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
723 "List of all shell builtins for completing read and fontification.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
724 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
725 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
726 :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
727 (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
728 (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
729 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
730
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
731
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
732
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
733 (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
734 '((bash sh-append sh
52322
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
735 "time")
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
736
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
737 (csh "else")
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
738
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
739 (es "true" "unwind-protect" "whatis")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
740
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
741 (rc "else")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
742
55119
3a424bb24301 (sh-leading-keywords) <sh>: Add "!".
Andreas Schwab <schwab@suse.de>
parents: 54282
diff changeset
743 (sh "!" "do" "elif" "else" "if" "then" "trap" "type" "until" "while"))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
744 "List of keywords that may be immediately followed by a builtin or keyword.
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
745 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
746 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
747 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
748 :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
749 (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
750 (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
751 :group 'sh-script)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
752
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
753
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
754 (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
755 '((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
756 "bye" "logout" "select")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
757
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
758 ;; 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
759 (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
760 "function")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
761
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
762 (csh sh-append shell
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
763 "breaksw" "default" "end" "endif" "endsw" "foreach" "goto"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
764 "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
765
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
766 (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
767 "return" "throw" "while")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
768
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
769 (ksh88 sh-append bourne
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
770 "select")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
771
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
772 (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
773 "while")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
774
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
775 (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
776 "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
777
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
778 ;; 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
779 (shell "break" "case" "continue" "exec" "exit")
12505
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 bash
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
782 "select"))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
783 "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
784 See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
785 :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
786 (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
787 (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
788 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
792 (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
793 '((bash sh-append sh
52322
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
794 "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
795 "BASH_VERSINFO" "BASH_VERSION" "cdable_vars" "COMP_CWORD"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
796 "COMP_LINE" "COMP_POINT" "COMP_WORDS" "COMPREPLY" "DIRSTACK"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
797 "ENV" "EUID" "FCEDIT" "FIGNORE" "FUNCNAME"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
798 "glob_dot_filenames" "GLOBIGNORE" "GROUPS" "histchars"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
799 "HISTCMD" "HISTCONTROL" "HISTFILE" "HISTFILESIZE"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
800 "HISTIGNORE" "history_control" "HISTSIZE"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
801 "hostname_completion_file" "HOSTFILE" "HOSTTYPE" "IGNOREEOF"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
802 "ignoreeof" "INPUTRC" "LINENO" "MACHTYPE" "MAIL_WARNING"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
803 "noclobber" "nolinks" "notify" "no_exit_on_failed_exec"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
804 "NO_PROMPT_VARS" "OLDPWD" "OPTERR" "OSTYPE" "PIPESTATUS"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
805 "PPID" "POSIXLY_CORRECT" "PROMPT_COMMAND" "PS3" "PS4"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
806 "pushd_silent" "PWD" "RANDOM" "REPLY" "SECONDS" "SHELLOPTS"
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
807 "SHLVL" "TIMEFORMAT" "TMOUT" "UID")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
808
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
809 (csh sh-append shell
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
810 "argv" "cdpath" "child" "echo" "histchars" "history" "home"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
811 "ignoreeof" "mail" "noclobber" "noglob" "nonomatch" "path" "prompt"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
812 "shell" "status" "time" "verbose")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
813
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
814 (es sh-append shell
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
815 "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
816 "pid" "prompt" "signals")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
817
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
818 (jcsh sh-append csh
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
819 "notify")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
820
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
821 (ksh88 sh-append sh
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
822 "ENV" "ERRNO" "FCEDIT" "FPATH" "HISTFILE" "HISTSIZE" "LINENO"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
823 "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
824 "TMOUT")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
825
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
826 (oash sh-append sh
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
827 "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
828
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
829 (rc sh-append shell
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
830 "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
831 "prompt" "status")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
832
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
833 (sh sh-append shell
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
834 "CDPATH" "IFS" "OPTARG" "OPTIND" "PS1" "PS2")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
835
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
836 ;; 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
837 (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
838 "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
839 "LINES" "LOGNAME" "MAIL" "MAILCHECK" "MAILPATH" "PAGER" "PATH"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
840 "SHELL" "TERM" "TERMCAP" "TERMINFO" "VISUAL")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
841
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
842 (tcsh sh-append csh
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
843 "addsuffix" "ampm" "autocorrect" "autoexpand" "autolist"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
844 "autologout" "chase_symlinks" "correct" "dextract" "edit" "el"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
845 "fignore" "gid" "histlit" "HOST" "HOSTTYPE" "HPATH"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
846 "ignore_symlinks" "listjobs" "listlinks" "listmax" "matchbeep"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
847 "nobeep" "NOREBIND" "oid" "printexitvalue" "prompt2" "prompt3"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
848 "pushdsilent" "pushdtohome" "recexact" "recognize_only_executables"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
849 "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
850 "tperiod" "tty" "uid" "version" "visiblebell" "watch" "who"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
851 "wordchars")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
852
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
853 (zsh sh-append ksh88
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
854 "BAUD" "bindcmds" "cdpath" "DIRSTACKSIZE" "fignore" "FIGNORE" "fpath"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
855 "HISTCHARS" "hostcmds" "hosts" "HOSTS" "LISTMAX" "LITHISTSIZE"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
856 "LOGCHECK" "mailpath" "manpath" "NULLCMD" "optcmds" "path" "POSTEDIT"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
857 "prompt" "PROMPT" "PROMPT2" "PROMPT3" "PROMPT4" "psvar" "PSVAR"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
858 "READNULLCMD" "REPORTTIME" "RPROMPT" "RPS1" "SAVEHIST" "SPROMPT"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
859 "STTY" "TIMEFMT" "TMOUT" "TMPPREFIX" "varcmds" "watch" "WATCH"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
860 "WATCHFMT" "WORDCHARS" "ZDOTDIR"))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
861 "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
862 See `sh-feature'.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
863
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
864
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
865 ;; Font-Lock support
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
866
63455
1589bde025e5 Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-414
Miles Bader <miles@gnu.org>
parents: 62772
diff changeset
867 (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
868 '((((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
869 (background dark))
31aa9a390538 * mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents: 61316
diff changeset
870 (: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
871 (((class color)
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
872 (background dark))
42456
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 42075
diff changeset
873 (:foreground "yellow" :weight bold))
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
874 (((class color)
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
875 (background light))
93536
e42355d302bb (sh-mode-map): Rename the menu. Add :help.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92878
diff changeset
876 (:foreground "tan1" ))
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
877 (t
42456
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 42075
diff changeset
878 (:weight bold)))
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
879 "Face to show a here-document"
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
880 :group 'sh-indentation)
71182
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
881
96363
f9d35151b907 American English spelling fix.
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
882 ;; These colors are probably icky. It's just a placeholder though.
71182
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
883 (defface sh-quoted-exec
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
884 '((((class color) (background dark))
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
885 (:foreground "salmon"))
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
886 (((class color) (background light))
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
887 (:foreground "magenta"))
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
888 (t
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
889 (:weight bold)))
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
890 "Face to show quoted execs like ``"
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
891 :group 'sh-indentation)
104778
afa0e028ba97 Mark face aliases with "-face" suffix as obsolete.
Glenn Morris <rgm@gnu.org>
parents: 104298
diff changeset
892 (define-obsolete-face-alias 'sh-heredoc-face 'sh-heredoc "22.1")
63455
1589bde025e5 Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-414
Miles Bader <miles@gnu.org>
parents: 62772
diff changeset
893 (defvar sh-heredoc-face 'sh-heredoc)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894
61316
283f977b41fb (sh-builtins) <bash>: Add `caller'.
Glenn Morris <rgm@gnu.org>
parents: 60917
diff changeset
895 (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
896 "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
897 :group 'sh-script
283f977b41fb (sh-builtins) <bash>: Add `caller'.
Glenn Morris <rgm@gnu.org>
parents: 60917
diff changeset
898 :version "22.1")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
899
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
900 (defvar sh-font-lock-keywords-var
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
901 '((csh sh-append shell
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
902 ("\\${?[#?]?\\([[:alpha:]_][[:alnum:]_]*\\|0\\)" 1
52619
50338995d37f (sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents: 52571
diff changeset
903 font-lock-variable-name-face))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
904
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
905 (es sh-append executable-font-lock-keywords
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
906 ("\\$#?\\([[:alpha:]_][[:alnum:]_]*\\|[0-9]+\\)" 1
52619
50338995d37f (sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents: 52571
diff changeset
907 font-lock-variable-name-face))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
909 (rc sh-append es)
71182
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
910 (bash sh-append shell ("\\$(\\(\\sw+\\)" (1 'sh-quoted-exec t) ))
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
911 (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
912 ;; Variable names.
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
913 ("\\$\\({#?\\)?\\([[:alpha:]_][[:alnum:]_]*\\|[-#?@!]\\)" 2
20900
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
914 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
915 ;; Function names.
52619
50338995d37f (sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents: 52571
diff changeset
916 ("^\\(\\sw+\\)[ \t]*(" 1 font-lock-function-name-face)
50338995d37f (sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents: 52571
diff changeset
917 ("\\<\\(function\\)\\>[ \t]*\\(\\sw+\\)?"
62080
2922c607db05 (sh-font-lock-keywords): Use font-lock-negation-char-face.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 61534
diff changeset
918 (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
919 ("\\(?:^\\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
920 1 font-lock-negation-char-face))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
922 ;; The next entry is only used for defining the others
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
923 (shell
52411
9db479d16349 (sh-font-lock-keywords): Use something other than
Glenn Morris <rgm@gnu.org>
parents: 52401
diff changeset
924 ;; 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
925 ("\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\)$" 3 'sh-escaped-newline)
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
926 ("\\\\[^[:alnum:]]" 0 font-lock-string-face)
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
927 ("\\${?\\([[:alpha:]_][[:alnum:]_]*\\|[0-9]+\\|[$*_]\\)" 1
23501
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
928 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
929 (rpm sh-append rpm2
52619
50338995d37f (sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents: 52571
diff changeset
930 ("%{?\\(\\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
931 (rpm2 sh-append shell
52619
50338995d37f (sh-builtins): Add bash `shopt' builtin.
Glenn Morris <rgm@gnu.org>
parents: 52571
diff changeset
932 ("^\\(\\sw+\\):" 1 font-lock-variable-name-face)))
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
933 "Default expressions to highlight in Shell Script modes. See `sh-feature'.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
934
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
935 (defvar sh-font-lock-keywords-var-1
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
936 '((sh "[ \t]in\\>"))
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
937 "Subdued level highlighting for Shell Script modes.")
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
938
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
939 (defvar sh-font-lock-keywords-var-2 ()
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
940 "Gaudy level highlighting for Shell Script modes.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
941
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
942 ;; 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
943 ;; 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
944 (defconst sh-st-punc (string-to-syntax "."))
36631
d5345decc9a4 (sh-st-symbol): New symbol.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 35180
diff changeset
945 (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
946 (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
947
66255
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
948 (defconst sh-escaped-line-re
78197
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
949 ;; Should match until the real end-of-continued-line, but if that is not
66255
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
950 ;; possible (because we bump into EOB or the search bound), then we should
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
951 ;; match until the search bound.
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
952 "\\(?:\\(?:.*[^\\\n]\\)?\\(?:\\\\\\\\\\)*\\\\\n\\)*.*")
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
953
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
954 (defconst sh-here-doc-open-re
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
955 (concat "<<-?\\s-*\\\\?\\(\\(?:['\"][^'\"]+['\"]\\|\\sw\\)+\\)"
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
956 sh-escaped-line-re "\\(\n\\)"))
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
957
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
958 (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
959 (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
960 (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
961 (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
962
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
963 (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
964 "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
965 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
966 (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
967 ;; 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
968 (sre (concat "<<\\(-?\\)\\s-*['\"\\]?"
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
969 ;; Use \s| to cheaply check it's an open-heredoc.
66255
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
970 eof-re "['\"]?\\([ \t|;&)<>]"
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
971 sh-escaped-line-re
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
972 "\\)?\\s|"))
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
973 ;; 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
974 (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
975 (start (save-excursion
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
976 (goto-char bol)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
977 (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
978 ;; 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
979 ;; 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
980 (cond
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
981 ((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
982 (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
983 (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
984 ;; 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
985 (save-excursion
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
986 (goto-char start)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
987 (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
988 (while
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
989 (progn
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
990 (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
991 (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
992 (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
993 (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
994 ;; 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
995 (= (point) start)))
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
996 sh-here-doc-syntax)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
997 ((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
998 ;; 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
999 ;; 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
1000 (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
1001 (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
1002 (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
1003 (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
1004 nil))))
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1005
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1006 (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
1007 "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
1008 START is the position of <<.
98148
7f34c3de8f96 (sh-font-lock-open-heredoc): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 98053
diff changeset
1009 STRING is the actual word used as delimiter (e.g. \"EOF\").
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1010 INDENTED is non-nil if the here document's content (and the EOF mark) can
66255
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1011 be indented (i.e. a <<- was used rather than just <<).
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1012 Point is at the beginning of the next line."
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1013 (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
1014 (sh-in-comment-or-string start))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1015 ;; 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
1016 ;; 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
1017 (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
1018 (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
1019 (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
1020 (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
1021 (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
1022 (regexp-opt sh-here-doc-markers t) "\\(\n\\)"))))
66255
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1023 (let ((ppss (save-excursion (syntax-ppss (1- (point))))))
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1024 (if (nth 4 ppss)
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1025 ;; The \n not only starts the heredoc but also closes a comment.
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1026 ;; Let's close the comment just before the \n.
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1027 (put-text-property (1- (point)) (point) 'syntax-table '(12))) ;">"
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1028 (if (or (nth 5 ppss) (> (count-lines start (point)) 1))
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1029 ;; If the sh-escaped-line-re part of sh-here-doc-re has matched
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1030 ;; several lines, make sure we refontify them together.
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1031 ;; Furthermore, if (nth 5 ppss) is non-nil (i.e. the \n is
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1032 ;; escaped), it means the right \n is actually further down.
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1033 ;; Don't bother fixing it now, but place a multiline property so
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1034 ;; that when jit-lock-context-* refontifies the rest of the
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1035 ;; buffer, it also refontifies the current line with it.
9cf3996bb877 (sh-escaped-line-re): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66027
diff changeset
1036 (put-text-property start (point) 'font-lock-multiline t)))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1037 sh-here-doc-syntax))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1038
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1039 (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
1040 "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
1041 ;; 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
1042 (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
1043
81909
bf55b9b62e57 (sh-font-lock-quoted-subshell): Skip over the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81462
diff changeset
1044 (defun sh-font-lock-quoted-subshell (limit)
72044
3dc0557bba5f (sh-quoted-subshell): Further fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72015
diff changeset
1045 "Search for a subshell embedded in a string.
3dc0557bba5f (sh-quoted-subshell): Further fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72015
diff changeset
1046 Find all the unescaped \" characters within said subshell, remembering that
3dc0557bba5f (sh-quoted-subshell): Further fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72015
diff changeset
1047 subshells can nest."
71949
e430f5632d15 (sh-quoted-subshell): Don't match escaped `. Use `cond', push', and `dolist'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71182
diff changeset
1048 ;; FIXME: This can (and often does) match multiple lines, yet it makes no
e430f5632d15 (sh-quoted-subshell): Don't match escaped `. Use `cond', push', and `dolist'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71182
diff changeset
1049 ;; effort to handle multiline cases correctly, so it ends up being
e430f5632d15 (sh-quoted-subshell): Don't match escaped `. Use `cond', push', and `dolist'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71182
diff changeset
1050 ;; rather flakey.
72316
cedc7e7f2199 (sh-quoted-subshell): Make sure we don't mistake a closing " for an opening one.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72044
diff changeset
1051 (when (and (re-search-forward "\"\\(?:\\(?:.\\|\n\\)*?[^\\]\\(?:\\\\\\\\\\)*\\)??\\(\\$(\\|`\\)" limit t)
cedc7e7f2199 (sh-quoted-subshell): Make sure we don't mistake a closing " for an opening one.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72044
diff changeset
1052 ;; Make sure the " we matched is an opening quote.
cedc7e7f2199 (sh-quoted-subshell): Make sure we don't mistake a closing " for an opening one.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72044
diff changeset
1053 (eq ?\" (nth 3 (syntax-ppss))))
72044
3dc0557bba5f (sh-quoted-subshell): Further fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72015
diff changeset
1054 ;; bingo we have a $( or a ` inside a ""
3dc0557bba5f (sh-quoted-subshell): Further fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72015
diff changeset
1055 (let ((char (char-after (point)))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1056 ;; `state' can be: double-quote, backquote, code.
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1057 (state (if (eq (char-before) ?`) 'backquote 'code))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1058 ;; Stacked states in the context.
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1059 (states '(double-quote)))
92878
0d903db06886 (sh-font-lock-quoted-subshell): Fix handling of \ and '.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91367
diff changeset
1060 (while (and state (progn (skip-chars-forward "^'\\\\\"`$()" limit)
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1061 (< (point) limit)))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1062 ;; unescape " inside a $( ... ) construct.
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1063 (case (char-after)
102126
69c0814ddb4e (sh-font-lock-quoted-subshell): ' inside a "..." does not quote anything.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101311
diff changeset
1064 (?\' (case state
69c0814ddb4e (sh-font-lock-quoted-subshell): ' inside a "..." does not quote anything.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101311
diff changeset
1065 (double-quote nil)
69c0814ddb4e (sh-font-lock-quoted-subshell): ' inside a "..." does not quote anything.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101311
diff changeset
1066 (t (forward-char 1) (skip-chars-forward "^'" limit))))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1067 (?\\ (forward-char 1))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1068 (?\" (case state
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1069 (double-quote (setq state (pop states)))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1070 (t (push state states) (setq state 'double-quote)))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1071 (if state (put-text-property (point) (1+ (point))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1072 'syntax-table '(1))))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1073 (?\` (case state
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1074 (backquote (setq state (pop states)))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1075 (t (push state states) (setq state 'backquote))))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1076 (?\$ (if (not (eq (char-after (1+ (point))) ?\())
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1077 nil
81909
bf55b9b62e57 (sh-font-lock-quoted-subshell): Skip over the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81462
diff changeset
1078 (forward-char 1)
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1079 (case state
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1080 (t (push state states) (setq state 'code)))))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1081 (?\( (case state
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1082 (double-quote nil)
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1083 (t (push state states) (setq state 'code))))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1084 (?\) (case state
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1085 (double-quote nil)
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1086 (t (setq state (pop states)))))
81909
bf55b9b62e57 (sh-font-lock-quoted-subshell): Skip over the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81462
diff changeset
1087 (t (error "Internal error in sh-font-lock-quoted-subshell")))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1088 (forward-char 1)))
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1089 t))
84921
35543641f89c (sh-make-vars-local, sh-reset-indent-vars-to-global-values):
Juanma Barranquero <lekktu@gmail.com>
parents: 84755
diff changeset
1090
71182
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
1091
51379
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
1092 (defun sh-is-quoted-p (pos)
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
1093 (and (eq (char-before pos) ?\\)
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
1094 (not (sh-is-quoted-p (1- pos)))))
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
1095
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1096 (defun sh-font-lock-paren (start)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1097 (save-excursion
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1098 (goto-char start)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1099 ;; Skip through all patterns
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1100 (while
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1101 (progn
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1102 (forward-comment (- (point-max)))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1103 ;; Skip through one pattern
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1104 (while
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1105 (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
1106 (/= 0 (skip-chars-backward "?[]*@/\\"))
51379
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
1107 (and (sh-is-quoted-p (1- (point)))
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
1108 (goto-char (- (point) 2)))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1109 (when (memq (char-before) '(?\" ?\'))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1110 (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
1111 (error nil)))))
105753
cdd9e1b1a30f * progmodes/sh-script.el (sh-font-lock-paren): Handle case
Chong Yidong <cyd@stupidchicken.com>
parents: 105371
diff changeset
1112 ;; Patterns can be preceded by an open-paren (Bug#1320).
105823
dd97d1526b9f * progmodes/sh-script.el (sh-font-lock-paren): Fix last change.
Chong Yidong <cyd@stupidchicken.com>
parents: 105813
diff changeset
1113 (if (eq (char-before (point)) ?\()
105753
cdd9e1b1a30f * progmodes/sh-script.el (sh-font-lock-paren): Handle case
Chong Yidong <cyd@stupidchicken.com>
parents: 105371
diff changeset
1114 (backward-char 1))
67069
962ab95567f0 (sh-font-lock-paren): Handle continued lines in patterns.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66963
diff changeset
1115 (while (progn
962ab95567f0 (sh-font-lock-paren): Handle continued lines in patterns.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66963
diff changeset
1116 (forward-comment (- (point-max)))
962ab95567f0 (sh-font-lock-paren): Handle continued lines in patterns.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66963
diff changeset
1117 ;; Maybe we've bumped into an escaped newline.
962ab95567f0 (sh-font-lock-paren): Handle continued lines in patterns.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66963
diff changeset
1118 (sh-is-quoted-p (point)))
962ab95567f0 (sh-font-lock-paren): Handle continued lines in patterns.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66963
diff changeset
1119 (backward-char 1))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1120 (when (eq (char-before) ?|)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1121 (backward-char 1) t)))
78197
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1122 ;; FIXME: ";; esac )" is a case that looks like a case-pattern but it's
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1123 ;; really just a close paren after a case statement. I.e. if we skipped
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1124 ;; over `esac' just now, we're not looking at a case-pattern.
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1125 (when (progn (backward-char 2)
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1126 (if (> start (line-end-position))
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1127 (put-text-property (point) (1+ start)
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1128 'font-lock-multiline t))
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1129 ;; FIXME: The `in' may just be a random argument to
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1130 ;; a normal command rather than the real `in' keyword.
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1131 ;; I.e. we should look back to try and find the
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1132 ;; corresponding `case'.
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1133 (looking-at ";;\\|in"))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1134 sh-st-punc)))
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1135
78197
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1136 (defun sh-font-lock-backslash-quote ()
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1137 (if (eq (save-excursion (nth 3 (syntax-ppss (match-beginning 0)))) ?\')
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1138 ;; In a '...' the backslash is not escaping.
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1139 sh-st-punc
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1140 nil))
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1141
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1142 (defun sh-font-lock-flush-syntax-ppss-cache (limit)
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1143 ;; This should probably be a standard function provided by font-lock.el
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1144 ;; (or syntax.el).
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1145 (syntax-ppss-flush-cache (point))
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1146 (goto-char limit)
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1147 nil)
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1148
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
1149 (defconst sh-font-lock-syntactic-keywords
36631
d5345decc9a4 (sh-st-symbol): New symbol.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 35180
diff changeset
1150 ;; 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
1151 ;; 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
1152 ;; 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
1153 ;; 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
1154 `(("[^|&;<>()`\\\"' \t\n]\\(#+\\)" 1 ,sh-st-symbol)
67160
23ef368e1c3d (sh-font-lock-syntactic-keywords): \ doesn't escape single quotes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 67069
diff changeset
1155 ;; In a '...' the backslash is not escaping.
78197
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1156 ("\\(\\\\\\)'" (1 (sh-font-lock-backslash-quote)))
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1157 ;; The previous rule uses syntax-ppss, but the subsequent rules may
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1158 ;; change the syntax, so we have to tell syntax-ppss that the states it
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1159 ;; has just computed will need to be recomputed.
f942a5cc0de4 (sh-font-lock-backslash-quote, sh-font-lock-flush-syntax-ppss-cache): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 77593
diff changeset
1160 (sh-font-lock-flush-syntax-ppss-cache)
87311
5459c18c7d1a (sh-font-lock-syntactic-keywords): Fix
Andreas Schwab <schwab@suse.de>
parents: 86283
diff changeset
1161 ;; Make sure $@ and $? are correctly recognized as sexps.
66269
5ab4a52a31ac (sh-font-lock-syntactic-keywords): Make $@ and $? into sexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66255
diff changeset
1162 ("\\$\\([?@]\\)" 1 ,sh-st-symbol)
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1163 ;; 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
1164 (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
1165 (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
1166 (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
1167 (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
1168 (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
1169 (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
1170 nil t))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1171 ;; Distinguish the special close-paren in `case'.
72316
cedc7e7f2199 (sh-quoted-subshell): Make sure we don't mistake a closing " for an opening one.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72044
diff changeset
1172 (")" 0 (sh-font-lock-paren (match-beginning 0)))
cedc7e7f2199 (sh-quoted-subshell): Make sure we don't mistake a closing " for an opening one.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72044
diff changeset
1173 ;; highlight (possibly nested) subshells inside "" quoted regions correctly.
cedc7e7f2199 (sh-quoted-subshell): Make sure we don't mistake a closing " for an opening one.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72044
diff changeset
1174 ;; This should be at the very end because it uses syntax-ppss.
81909
bf55b9b62e57 (sh-font-lock-quoted-subshell): Skip over the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81462
diff changeset
1175 (sh-font-lock-quoted-subshell)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1176
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1177 (defun sh-font-lock-syntactic-face-function (state)
71182
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
1178 (let ((q (nth 3 state)))
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
1179 (if q
90428
a8190f7e546e Merge from emacs--devo--0
Miles Bader <miles@gnu.org>
parents: 90385 71182
diff changeset
1180 (if (characterp q)
71182
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
1181 (if (eq q ?\`) 'sh-quoted-exec font-lock-string-face)
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
1182 sh-heredoc-face)
44d77343c9ac (sh-quoted-exec): New face for quoted exec constructs like `foo bar`.
Eli Zaretskii <eliz@gnu.org>
parents: 70829
diff changeset
1183 font-lock-comment-face)))
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1184
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1185 (defgroup sh-indentation nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1186 "Variables controlling indentation in shell scripts.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1187
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1188 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
1189 `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
1190 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
1191 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
1192 :group 'sh-script)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1193
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1194
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1195 (defcustom sh-set-shell-hook nil
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1196 "Hook run by `sh-set-shell'."
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1197 :type 'hook
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1198 :group 'sh-script)
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-mode-hook nil
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1201 "Hook run by `sh-mode'."
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1202 :type 'hook
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1203 :group 'sh-script)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1204
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1205 (defcustom sh-learn-basic-offset nil
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1206 "When `sh-guess-basic-offset' should learn `sh-basic-offset'.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1207
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1208 nil mean: never.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1209 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
1210 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
1211 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1212 (const :tag "Never" nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1213 (const :tag "Only if sure" t)
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1214 (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
1215 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1216
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1217 (defcustom sh-popup-occur-buffer nil
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1218 "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
1219 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
1220 are conflicts."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1221 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1222 (const :tag "Only when there are conflicts." nil)
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1223 (const :tag "Always" t))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1224 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1225
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1226 (defcustom sh-blink t
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1227 "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
1228 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
1229 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
1230 always the case."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1231 :type 'boolean
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1232 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1233
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1234 (defcustom sh-first-lines-indent 0
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1235 "The indentation of the first non-blank non-comment line.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1236 Usually 0 meaning first column.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1237 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
1238 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1239 (const :tag "Leave as is" nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1240 (integer :tag "Column number"
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1241 :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
1242 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1243
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1244
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1245 (defcustom sh-basic-offset 4
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1246 "The default indentation increment.
62309
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1247 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
1248 :type 'integer
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1249 :group 'sh-indentation)
79885
897a4cc5c95d * progmodes/sh-script.el (sh-basic-offset):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 79717
diff changeset
1250 (put 'sh-basic-offset 'safe-local-variable 'integerp)
25986
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 (defcustom sh-indent-comment nil
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1253 "How a comment line is to be indented.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1254 nil means leave it as it is;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1255 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
1256 non-comment line;
84755
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82354
diff changeset
1257 a number means align to that column, e.g. 0 means first column."
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1258 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1259 (const :tag "Leave as is." nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1260 (const :tag "Indent as a normal line." t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1261 (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
1262 :tag "Indent to column number.") )
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1263 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1264
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1265
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1266 (defvar sh-debug nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1267 "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
1268
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1269
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1270 ;; 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
1271 ;; (defun sh-debug (&rest args)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1272 ;; "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
1273 ;; (if sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1274 ;; (apply 'message args)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1275 (defmacro sh-debug (&rest args))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1276
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1277 (defconst sh-symbol-list
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1278 '((const :tag "+ " :value +
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1279 :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
1280 (const :tag "- " :value -
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1281 :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
1282 (const :tag "++" :value ++
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1283 :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
1284 (const :tag "--" :value --
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1285 :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
1286 (const :tag "* " :value *
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1287 :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
1288 (const :tag "/ " :value /
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1289 :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
1290
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1291 (defcustom sh-indent-for-else 0
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1292 "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
1293 :type `(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1294 (integer :menu-tag "A number (positive=>indent right)"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1295 :tag "A number")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1296 (const :tag "--") ;; separator!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1297 ,@ sh-symbol-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1298 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1299 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1300
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1301 (defconst sh-number-or-symbol-list
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1302 (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
1303 :tag "A number")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1304 (const :tag "--")) ; separator
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1305 sh-symbol-list))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1306
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1307 (defcustom sh-indent-for-fi 0
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1308 "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
1309 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1310 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1311
62309
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1312 (defcustom sh-indent-for-done 0
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1313 "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
1314 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1315 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1316
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1317 (defcustom sh-indent-after-else '+
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1318 "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
1319 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1320 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1321
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1322 (defcustom sh-indent-after-if '+
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1323 "How much to indent a statement after an `if' statement.
62309
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1324 This includes lines after `else' and `elif' statements, too, but
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1325 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
1326 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1327 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1328
58767
d2c6a8b592f2 (sh-indent-for-then): Change default.
Richard M. Stallman <rms@gnu.org>
parents: 57159
diff changeset
1329 (defcustom sh-indent-for-then 0
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1330 "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
1331 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1332 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1333
62214
e451c7eb2d24 (sh-indent-for-do): Default to 0.
Richard M. Stallman <rms@gnu.org>
parents: 62080
diff changeset
1334 (defcustom sh-indent-for-do 0
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1335 "How much to indent a `do' statement.
62310
063800c5c224 More doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62309
diff changeset
1336 This is relative to the statement before the `do', typically a
063800c5c224 More doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62309
diff changeset
1337 `while', `until', `for', `repeat' or `select' statement."
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1338 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1339 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1340
62309
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1341 (defcustom sh-indent-after-do '+
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1342 "How much to indent a line after a `do' statement.
62309
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1343 This is used when the `do' is the first word of the line.
62310
063800c5c224 More doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62309
diff changeset
1344 This is relative to the statement before the `do', typically a
063800c5c224 More doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62309
diff changeset
1345 `while', `until', `for', `repeat' or `select' statement."
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1346 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1347 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1348
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1349 (defcustom sh-indent-after-loop-construct '+
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1350 "How much to indent a statement after a loop construct.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1351
62309
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1352 This variable is used when the keyword `do' is on the same line as the
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1353 loop statement (e.g., `until', `while' or `for').
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1354 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
1355 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1356 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1357
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1358
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1359 (defcustom sh-indent-after-done 0
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1360 "How much to indent a statement after a `done' keyword.
62309
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1361 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
1362 looping construct line.
62309
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1363 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
1364 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
1365 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1366 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1367
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1368 (defcustom sh-indent-for-case-label '+
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1369 "How much to indent a case label statement.
62309
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1370 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
1371 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1372 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1373
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1374 (defcustom sh-indent-for-case-alt '++
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1375 "How much to indent statements after the case label.
62309
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1376 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
1377 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1378 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1379
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1380
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1381 (defcustom sh-indent-for-continuation '+
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1382 "How much to indent for a continuation statement."
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1383 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1384 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1385
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1386 (defcustom sh-indent-after-open '+
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1387 "How much to indent after a line with an opening parenthesis or brace.
62309
93889fbf94b2 Many doc usage fixes.
Richard M. Stallman <rms@gnu.org>
parents: 62242
diff changeset
1388 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
1389 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1390 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1391
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1392 (defcustom sh-indent-after-function '+
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1393 "How much to indent after a function line."
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1394 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1395 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1396
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1397 ;; These 2 are for the rc shell:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1398
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1399 (defcustom sh-indent-after-switch '+
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1400 "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
1401 This is for the rc shell."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1402 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1403 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1404
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1405 (defcustom sh-indent-after-case '+
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1406 "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
1407 This is for the rc shell."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1408 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1409 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1410
59566
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
1411 (defcustom sh-backslash-column 48
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1412 "Column in which `sh-backslash-region' inserts backslashes."
59566
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
1413 :type 'integer
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
1414 :group 'sh)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
1415
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
1416 (defcustom sh-backslash-align t
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1417 "If non-nil, `sh-backslash-region' will align backslashes."
59566
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
1418 :type 'boolean
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
1419 :group 'sh)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
1420
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1421 ;; 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
1422
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1423 (defun sh-mkword-regexpr (word)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1424 "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
1425 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
1426 punctuation characters like '-'."
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
1427 (concat word "\\([^-[:alnum:]_]\\|$\\)"))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1428
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1429 (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
1430
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1431
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1432 (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
1433 '((sh . ( "while" "until" "for" ) )
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1434 (bash . ( "while" "until" "for" "select" ) )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1435 (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
1436 (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
1437 "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
1438
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1439
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1440 (defconst sh-indent-supported
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1441 '((sh . t)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1442 (csh . nil)
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1443 (rc . t))
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1444 "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
1445
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1446 (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
1447 "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
1448
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1449 (defconst sh-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1450 '(
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1451 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
1452 sh-indent-after-do sh-indent-after-done
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1453 sh-indent-after-else
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1454 sh-indent-after-if
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1455 sh-indent-after-loop-construct
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1456 sh-indent-after-open
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1457 sh-indent-comment
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1458 sh-indent-for-case-alt
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1459 sh-indent-for-case-label
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1460 sh-indent-for-continuation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1461 sh-indent-for-do
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1462 sh-indent-for-done
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1463 sh-indent-for-else
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1464 sh-indent-for-fi
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1465 sh-indent-for-then
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1466 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1467 "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
1468 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
1469 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
1470
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1471 (defvar sh-make-vars-local t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1472 "*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
1473 If non-nil, indentation variables are made local initially.
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1474 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
1475 command `sh-make-vars-local'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1476 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
1477 frequently editing existing scripts with different styles.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1478
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1479
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1480 ;; mode-command and utility functions
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1481
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1482 ;;;###autoload
41348
b46a4ee1a05d (sh-mode): Don't use define-derived-mode.
Richard M. Stallman <rms@gnu.org>
parents: 41233
diff changeset
1483 (defun sh-mode ()
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1484 "Major mode for editing shell scripts.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1485 This mode works for many shells, since they all have roughly the same syntax,
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1486 as far as commands, arguments, variables, pipes, comments etc. are concerned.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1487 Unless the file's magic number indicates the shell, your usual shell is
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1488 assumed. Since filenames rarely give a clue, they are not further analyzed.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1489
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1490 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
1491 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
1492 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
1493 shell-specific features.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1494
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1495 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
1496 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
1497 following commands are available, based on the current shell's syntax:
67647
ccd73c32ce19 * progmodes/sh-script.el (sh-mode): Add keymap to docstring.
Chong Yidong <cyd@stupidchicken.com>
parents: 67160
diff changeset
1498 \\<sh-mode-map>
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1499 \\[sh-case] case statement
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1500 \\[sh-for] for loop
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1501 \\[sh-function] function definition
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1502 \\[sh-if] if statement
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1503 \\[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
1504 \\[sh-while-getopts] while getopts loop
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1505 \\[sh-repeat] repeat loop
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1506 \\[sh-select] select loop
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1507 \\[sh-until] until loop
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1508 \\[sh-while] while loop
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1509
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1510 For sh and rc shells indentation commands are:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1511 \\[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
1512 \\[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
1513 \\[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
1514 would indent to the way it currently is.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1515 \\[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
1516 buffer indents as it currently is indented.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1517
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1518
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1519 \\[backward-delete-char-untabify] Delete backward one position, even if it was a tab.
96887
936b47c046f0 Remove sh-newline-and-indent
Miles Bader <miles@gnu.org>
parents: 96363
diff changeset
1520 \\[newline-and-indent] Delete unquoted space and indent new line same as this one.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1521 \\[sh-end-of-command] Go to end of successive commands.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1522 \\[sh-beginning-of-command] Go to beginning of successive commands.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1523 \\[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
1524 \\[sh-execute-region] Have optional header and region be executed in a subshell.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1525
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1526 \\[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
1527 \{, (, [, ', \", `
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1528 Unless quoted with \\, insert the pairs {}, (), [], or '', \"\", ``.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1529
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1530 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
1531 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
1532 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
1533
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1534 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
1535 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
1536 (interactive)
b46a4ee1a05d (sh-mode): Don't use define-derived-mode.
Richard M. Stallman <rms@gnu.org>
parents: 41233
diff changeset
1537 (kill-all-local-variables)
b46a4ee1a05d (sh-mode): Don't use define-derived-mode.
Richard M. Stallman <rms@gnu.org>
parents: 41233
diff changeset
1538 (setq major-mode 'sh-mode
b46a4ee1a05d (sh-mode): Don't use define-derived-mode.
Richard M. Stallman <rms@gnu.org>
parents: 41233
diff changeset
1539 mode-name "Shell-script")
b46a4ee1a05d (sh-mode): Don't use define-derived-mode.
Richard M. Stallman <rms@gnu.org>
parents: 41233
diff changeset
1540 (use-local-map sh-mode-map)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1541 (make-local-variable 'skeleton-end-hook)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1542 (make-local-variable 'paragraph-start)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1543 (make-local-variable 'paragraph-separate)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1544 (make-local-variable 'comment-start)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1545 (make-local-variable 'comment-start-skip)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1546 (make-local-variable 'require-final-newline)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1547 (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
1548 (make-local-variable 'sh-shell-file)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1549 (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
1550 (make-local-variable 'skeleton-pair-alist)
70829
b9fa14b504d3 (sh-mode): Use skeleton-pair-filter-function.
Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
parents: 70828
diff changeset
1551 (make-local-variable 'skeleton-pair-filter-function)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1552 (make-local-variable 'comint-dynamic-complete-functions)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1553 (make-local-variable 'comint-prompt-regexp)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1554 (make-local-variable 'font-lock-defaults)
70828
bc576a11127e (sh-mode): Use skeleton-filter-function.
Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
parents: 70144
diff changeset
1555 (make-local-variable 'skeleton-filter-function)
12887
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
1556 (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
1557 (make-local-variable 'sh-shell-variables)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
1558 (make-local-variable 'sh-shell-variables-initialized)
20395
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
1559 (make-local-variable 'imenu-generic-expression)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1560 (make-local-variable 'sh-indent-supported-here)
65384
96998d31413e (sh-skeleton-pair-default-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents: 65239
diff changeset
1561 (make-local-variable 'skeleton-pair-default-alist)
96998d31413e (sh-skeleton-pair-default-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents: 65239
diff changeset
1562 (setq skeleton-pair-default-alist sh-skeleton-pair-default-alist)
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1563 (setq skeleton-end-hook (lambda ()
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1564 (or (eolp) (newline) (indent-relative)))
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
1565 paragraph-start (concat page-delimiter "\\|$")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1566 paragraph-separate paragraph-start
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1567 comment-start "# "
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1568 comment-start-skip "#+[\t ]*"
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1569 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
1570 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
1571 ;; 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
1572 comint-prompt-regexp "^[ \t]*"
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1573 imenu-case-fold-search nil
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1574 font-lock-defaults
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
1575 `((sh-font-lock-keywords
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
1576 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
1577 nil nil
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
1578 ((?/ . "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
1579 (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
1580 (font-lock-syntactic-face-function
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1581 . 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
1582 skeleton-pair-alist '((?` _ ?`))
70829
b9fa14b504d3 (sh-mode): Use skeleton-pair-filter-function.
Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
parents: 70828
diff changeset
1583 skeleton-pair-filter-function 'sh-quoted-p
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1584 skeleton-further-elements '((< '(- (min sh-indentation
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1585 (current-column)))))
70828
bc576a11127e (sh-mode): Use skeleton-filter-function.
Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
parents: 70144
diff changeset
1586 skeleton-filter-function 'sh-feature
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1587 skeleton-newline-indent-rigidly t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1588 sh-indent-supported-here nil)
86283
dcb8172071f2 (sh-mode): Set defun-prompt-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 84921
diff changeset
1589 (set (make-local-variable 'defun-prompt-regexp)
dcb8172071f2 (sh-mode): Set defun-prompt-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 84921
diff changeset
1590 (concat "^\\(function[ \t]\\|[[:alnum:]]+[ \t]+()[ \t]+\\)"))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1591 (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
1592 ;; 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
1593 ;; on the shell thus determined.
69149
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1594 (sh-set-shell
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1595 (cond ((save-excursion
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1596 (goto-char (point-min))
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1597 (looking-at "#![ \t]?\\([^ \t\n]*/bin/env[ \t]\\)?\\([^ \t\n]+\\)"))
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1598 (match-string 2))
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1599 ((not buffer-file-name)
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1600 sh-shell-file)
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1601 ;; Checks that use `buffer-file-name' follow.
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1602 ((string-match "\\.m?spec\\'" buffer-file-name)
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1603 "rpm")
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1604 ((string-match "[.]sh\\>" buffer-file-name)
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1605 "sh")
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1606 ((string-match "[.]bash\\>" buffer-file-name)
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1607 "bash")
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1608 ((string-match "[.]ksh\\>" buffer-file-name)
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1609 "ksh")
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1610 ((string-match "[.]csh\\>" buffer-file-name)
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1611 "csh")
77593
dac1de8103f2 (sh-mode): Recognize .profile as sh style.
Richard M. Stallman <rms@gnu.org>
parents: 75347
diff changeset
1612 ((equal (file-name-nondirectory buffer-file-name) ".profile")
dac1de8103f2 (sh-mode): Recognize .profile as sh style.
Richard M. Stallman <rms@gnu.org>
parents: 75347
diff changeset
1613 "sh")
69149
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1614 (t
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1615 sh-shell-file))
b5043066337b (sh-mode): Fix bug: Arrange to use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69083
diff changeset
1616 nil nil)
62772
f2892faa87d4 * progmodes/ada-mode.el (ada-mode):
Lute Kamstra <lute@gnu.org>
parents: 62550
diff changeset
1617 (run-mode-hooks 'sh-mode-hook))
33430
d2648645aa9b (sh-mode-syntax-table) <defvar>:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32728
diff changeset
1618
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1619 ;;;###autoload
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1620 (defalias 'shell-script-mode 'sh-mode)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1621
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1622
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1623 (defun sh-font-lock-keywords (&optional keywords)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1624 "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
1625 This adds rules for comments and assignments."
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1626 (sh-feature sh-font-lock-keywords-var
23511
8b4cdcbaf071 (sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents: 23501
diff changeset
1627 (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
1628 (lambda (list)
8b4cdcbaf071 (sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents: 23501
diff changeset
1629 `((,(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
1630 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
1631 ,@keywords
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1632 ,@list
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1633 ,@executable-font-lock-keywords)))))
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1634
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1635 (defun sh-font-lock-keywords-1 (&optional builtins)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1636 "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
1637 (let ((keywords (concat "\\([;(){}`|&]\\|^\\)[ \t]*\\(\\("
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1638 (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
1639 "[ \t]+\\)?"
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1640 (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
1641 (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
1642 t))))
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1643 (sh-font-lock-keywords
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1644 `(,@(if builtins
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1645 `((,(concat keywords "[ \t]+\\)?"
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1646 (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
1647 "\\>")
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1648 (2 font-lock-keyword-face nil t)
72006
f483b68fd89b (sh-font-lock-keywords-1): Revert inadvertently installed patch hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71949
diff changeset
1649 (6 font-lock-builtin-face))
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1650 ,@(sh-feature sh-font-lock-keywords-var-2)))
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1651 (,(concat keywords "\\)\\>")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1652 2 font-lock-keyword-face)
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1653 ,@(sh-feature sh-font-lock-keywords-var-1)))))
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1654
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1655 (defun sh-font-lock-keywords-2 ()
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1656 "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
1657 (sh-font-lock-keywords-1 t))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1658
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1659
29422
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1660 (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
1661 "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
1662
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1663 (defvar sh-kw-alist nil
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1664 "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
1665
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1666 ;; ( 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
1667 ;; 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
1668 ;; having 3 elements:
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1669 ;; a keyword
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1670 ;; 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
1671 ;; 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
1672 ;; 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
1673 ;; 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
1674 ;; 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
1675 ;; 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
1676 ;; 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
1677 ;; 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
1678 ;; 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
1679 ;; 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
1680 ;; `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
1681 ;; 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
1682 ;; 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
1683 ;; 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
1684 ;; for both.
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1685 ;;
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1686 (defconst sh-kw
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1687 '((sh
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1688 ("if" nil sh-handle-prev-if)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1689 ("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
1690 ("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
1691 ("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
1692 ("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
1693 ("(" nil sh-handle-prev-open)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1694 ("{" nil sh-handle-prev-open)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1695 ("[" nil sh-handle-prev-open)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1696 ("}" sh-handle-this-close nil)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1697 (")" sh-handle-this-close nil)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1698 ("]" sh-handle-this-close nil)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1699 ("case" nil sh-handle-prev-case)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1700 ("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
1701 (case-label nil sh-handle-after-case-label) ;; ???
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1702 (";;" nil sh-handle-prev-case-alt-end) ;; ???
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1703 ("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
1704 ("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
1705
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1706 ;; 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
1707 ;; 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
1708 ;; these shells use.
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1709 (rc
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1710 ("{" nil sh-handle-prev-open)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1711 ("}" sh-handle-this-close nil)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1712 ("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
1713
be5a54fc840d (sh-symbol-list, sh-number-or-symbol-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29109
diff changeset
1714
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1715
14148
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1716 (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
1717 "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
1718 When used interactively, insert the proper starting #!-line,
af3eb1ed8032 (sh-set-shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 42456
diff changeset
1719 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
1720 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
1721
af3eb1ed8032 (sh-set-shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 42456
diff changeset
1722 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
1723 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
1724 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
1725 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
1726
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1727 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
1728 (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
1729 sh-shell-file)
99f9777a831b (sh-set-shell): Make sh-shell-file the default shell.
Juanma Barranquero <lekktu@gmail.com>
parents: 48032
diff changeset
1730 interpreter-mode-alist
99f9777a831b (sh-set-shell): Make sh-shell-file the default shell.
Juanma Barranquero <lekktu@gmail.com>
parents: 48032
diff changeset
1731 (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
1732 nil nil nil sh-shell-file)
14148
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1733 (eq executable-query 'function)
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1734 t))
23589
660727693bf6 (sh-canonicalize-shell): Fix regexp.
Andreas Schwab <schwab@suse.de>
parents: 23511
diff changeset
1735 (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
1736 (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
1737 (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
1738 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
1739 sh-shell))
16552
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1740 (if insert-flag
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1741 (setq sh-shell-file
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1742 (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
1743 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
1744 (let ((tem (sh-feature sh-require-final-newline)))
59251
84ede35ffeb4 (sh-require-final-newline):
Richard M. Stallman <rms@gnu.org>
parents: 58767
diff changeset
1745 (if (eq tem t)
84ede35ffeb4 (sh-require-final-newline):
Richard M. Stallman <rms@gnu.org>
parents: 58767
diff changeset
1746 (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
1747 (setq
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1748 mode-line-process (format "[%s]" sh-shell)
14195
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
1749 sh-shell-variables nil
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
1750 sh-shell-variables-initialized nil
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1751 imenu-generic-expression (sh-feature sh-imenu-generic-expression))
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
1752 (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
1753 (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
1754 (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
1755 (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
1756 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
1757 (set-syntax-table sh-mode-syntax-table)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1758 (dolist (var (sh-feature sh-variables))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1759 (sh-remember-variable var))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1760 (make-local-variable 'indent-line-function)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1761 (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
1762 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1763 (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
1764 (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
1765 (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
1766 (let ((regexp (sh-feature sh-kws-for-done)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1767 (if regexp
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1768 (set (make-local-variable 'sh-regexp-for-done)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1769 (sh-mkword-regexpr (regexp-opt regexp t)))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1770 (message "setting up indent stuff")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1771 ;; 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
1772 ;; 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
1773 (setq indent-line-function 'sh-indent-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1774 (if sh-make-vars-local
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1775 (sh-make-vars-local))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1776 (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
1777 (message "No indentation for this shell type.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1778 (setq indent-line-function 'sh-basic-indent-line))
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1779 (when font-lock-mode
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1780 (setq font-lock-set-defaults nil)
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1781 (font-lock-set-defaults)
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1782 (font-lock-fontify-buffer))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1783 (run-hooks 'sh-set-shell-hook))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1784
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1785
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
1786 (defun sh-feature (alist &optional function)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1787 "Index ALIST by the current shell.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1788 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
1789 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
1790
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1791 - 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
1792 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
1793 The ultimate default is always `sh'.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1794
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
1795 - 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
1796 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
1797 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
1798 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
1799 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
1800 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
1801 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
1802
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1803 If FUNCTION is non-nil, it is called with one argument,
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1804 the value thus obtained, and the result is used instead."
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
1805 (or (if (consp alist)
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1806 ;; Check for something that isn't a valid alist.
52571
6de55a10c444 (sh-mode-default-syntax-table): Renamed from sh-mode-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents: 52549
diff changeset
1807 (let ((l alist))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1808 (while (and l (consp (car l)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1809 (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
1810 (if l alist)))
64971
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1811
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1812 (let ((orig-sh-shell sh-shell))
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1813 (let ((sh-shell sh-shell)
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1814 elt val)
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1815 (while (and sh-shell
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1816 (not (setq elt (assq sh-shell alist))))
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1817 (setq sh-shell (cdr (assq sh-shell sh-ancestor-alist))))
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1818 ;; If the shell is not known, treat it as sh.
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1819 (unless elt
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1820 (setq elt (assq 'sh alist)))
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1821 (setq val (cdr elt))
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1822 (if (and (consp val)
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1823 (memq (car val) '(sh-append sh-modify)))
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1824 (setq val
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1825 (apply (car val)
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1826 ;; Refer to the value for a different shell,
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1827 ;; as a kind of inheritance.
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1828 (let ((sh-shell (car (cdr val))))
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1829 (sh-feature alist))
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1830 (cddr val))))
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1831 (if function
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1832 (setq sh-shell orig-sh-shell
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1833 val (funcall function val)))
7fb2b79e33d0 (sh-font-lock-keywords-var): Variable renamed from sh-font-lock-keywords.
Richard M. Stallman <rms@gnu.org>
parents: 64266
diff changeset
1834 val))))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1835
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1836
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1837
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1838 ;; 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
1839 ;;(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
1840 ;; "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
1841 ;;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
1842 ;;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
1843 ;;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
1844 ;;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
1845 ;; (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
1846 ;; (symbol-value sh-shell))
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1847 ;; (progn
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1848 ;; (if (listp ancestor)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1849 ;; (nconc list ancestor))
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1850 ;; (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
1851 ;; (if (vectorp ancestor)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1852 ;; (mapatoms (lambda (atom)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1853 ;; (or (eq atom 0)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1854 ;; (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
1855 ;; (symbol-name atom)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1856 ;; (symbol-value atom)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1857 ;; (symbol-function atom))))
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1858 ;; ancestor))
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1859 ;; (while list
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1860 ;; (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
1861 ;; (car list)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1862 ;; (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
1863 ;; (car (cdr list))
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1864 ;; "")
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1865 ;; (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
1866 ;; (car (cdr list))))
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
1867 ;; (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
1868 ;; (symbol-value sh-shell)))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1869
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1870
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1871 (defun sh-append (ancestor &rest list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1872 "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
1873 (nconc list ancestor))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1874
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1875
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1876 (defun sh-modify (skeleton &rest list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1877 "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
1878 (setq skeleton (copy-sequence skeleton))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1879 (while list
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1880 (setcar (or (nthcdr (car list) skeleton)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1881 (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
1882 (car (cdr list)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1883 (setq list (nthcdr 2 list)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1884 skeleton)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1885
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1886
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1887 (defun sh-basic-indent-line ()
19480
7f11f103a0ca (sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 18382
diff changeset
1888 "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
1889 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
1890 Lines containing only comments are considered empty."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1891 (interactive)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1892 (let ((previous (save-excursion
19480
7f11f103a0ca (sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 18382
diff changeset
1893 (while (and (progn (beginning-of-line)
7f11f103a0ca (sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 18382
diff changeset
1894 (not (bobp)))
14211
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1895 (progn
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1896 (forward-line -1)
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1897 (back-to-indentation)
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1898 (or (eolp)
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1899 (eq (following-char) ?#)))))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1900 (current-column)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1901 current)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1902 (save-excursion
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1903 (indent-to (if (eq this-command 'newline-and-indent)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1904 previous
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1905 (if (< (current-column)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1906 (setq current (progn (back-to-indentation)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1907 (current-column))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1908 (if (eolp) previous 0)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1909 (delete-region (point)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1910 (progn (beginning-of-line) (point)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1911 (if (eolp)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1912 (max previous (* (1+ (/ current sh-indentation))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1913 sh-indentation))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1914 (* (1+ (/ current sh-indentation)) sh-indentation))))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1915 (if (< (current-column) (current-indentation))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1916 (skip-chars-forward " \t"))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1917
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1918
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1919 (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
1920 "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
1921 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
1922 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
1923
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1924 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
1925 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
1926 region, clear header."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1927 (interactive "r\nP")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1928 (if flag
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1929 (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
1930 (point-marker)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1931 (if sh-header-marker
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1932 (save-excursion
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1933 (let (buffer-undo-list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1934 (goto-char sh-header-marker)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1935 (append-to-buffer (current-buffer) start end)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1936 (shell-command-on-region (point-min)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1937 (setq end (+ sh-header-marker
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1938 (- end start)))
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1939 sh-shell-file)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1940 (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
1941 (shell-command-on-region start end (concat sh-shell-file " -")))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1942
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1943
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1944 (defun sh-remember-variable (var)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1945 "Make VARIABLE available for future completing reads in this buffer."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1946 (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
1947 (getenv var)
14195
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
1948 (assoc var sh-shell-variables)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1949 (push (cons var var) sh-shell-variables))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1950 var)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1951
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1952
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1953
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1954 (defun sh-quoted-p ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1955 "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
1956 (eq -1 (% (save-excursion (skip-chars-backward "\\\\")) 2)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1957
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1958 ;; Indentation stuff.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1959 (defun sh-must-support-indent ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1960 "*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
1961 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
1962 (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
1963 (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
1964
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1965 (defun sh-make-vars-local ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1966 "Make the indentation variables local to this buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1967 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
1968 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
1969
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1970 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
1971 command `sh-reset-indent-vars-to-global-values'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1972 (interactive)
84921
35543641f89c (sh-make-vars-local, sh-reset-indent-vars-to-global-values):
Juanma Barranquero <lekktu@gmail.com>
parents: 84755
diff changeset
1973 (mapc 'make-local-variable sh-var-list)
74829
55f1722d93af (sh-make-vars-local): Fix a typo in message string.
Eli Zaretskii <eliz@gnu.org>
parents: 74547
diff changeset
1974 (message "Indentation variables are now local."))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1975
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1976 (defun sh-reset-indent-vars-to-global-values ()
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1977 "Reset local indentation variables to the global values.
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1978 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
1979 (interactive)
84921
35543641f89c (sh-make-vars-local, sh-reset-indent-vars-to-global-values):
Juanma Barranquero <lekktu@gmail.com>
parents: 84755
diff changeset
1980 (mapc 'kill-local-variable sh-var-list)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1981 (if sh-make-vars-local
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1982 (mapcar 'make-local-variable sh-var-list)))
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
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1985 ;; 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
1986 ;; 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
1987 (defconst sh-special-keywords "then\\|do")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1988
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1989 (defun sh-help-string-for-variable (var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1990 "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
1991 (let ((msg (documentation-property var 'variable-documentation))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1992 (msg2 ""))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
1993 (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
1994 (setq msg2
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1995 (format "\n
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1996 You can enter a number (positive to increase indentation,
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1997 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
1998
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
1999 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
2000 the value of variable `sh-basic-offset'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2001 which in this buffer is currently %s.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2002
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2003 \t%s."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2004 sh-basic-offset
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
2005 (mapconcat (lambda (x)
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
2006 (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
2007 sh-symbol-list "\n\t"))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2008 (concat
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2009 ;; 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
2010 ;; (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
2011 msg msg2)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2012
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2013 (defun sh-read-variable (var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2014 "Read a new value for indentation variable VAR."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2015 (interactive "*variable? ") ;; to test
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2016 (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
2017 (quote ,var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2018 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2019 (setq val (read-from-minibuffer
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2020 (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
2021 var (single-key-description help-char))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2022 (format "%s" (symbol-value var))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2023 nil t))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2024 val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2025
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2026
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2027
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2028 (defun sh-in-comment-or-string (start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2029 "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
2030 (save-excursion
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
2031 (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
2032 (or (nth 3 state) (nth 4 state)))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2033
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2034 (defun sh-goto-matching-if ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2035 "Go to the matching if for a fi.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2036 This handles nested if..fi pairs."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2037 (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
2038 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2039 (goto-char found))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2040
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2041
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2042 ;; 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
2043 ;; line whose indentation is being handled contain XXX;
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2044 ;; 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
2045
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2046 (defun sh-handle-prev-if ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2047 (list '(+ sh-indent-after-if)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2048
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2049 (defun sh-handle-this-else ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2050 (if (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2051 ;; (list "aligned to if")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2052 (list "aligned to if" '(+ sh-indent-for-else))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2053 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2054 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2055
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2056 (defun sh-handle-prev-else ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2057 (if (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2058 (list '(+ sh-indent-after-if))
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 (defun sh-handle-this-fi ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2062 (if (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2063 (list "aligned to if" '(+ sh-indent-for-fi))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2064 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2065 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2066
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2067 (defun sh-handle-prev-fi ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2068 ;; 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
2069 ;; 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
2070 ;; 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
2071 ;; 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
2072 ;; 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
2073 (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2074 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2075
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2076 (defun sh-handle-this-then ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2077 (let ((p (sh-goto-matching-if)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2078 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2079 (list '(+ sh-indent-for-then))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2080 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2081
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2082 (defun sh-handle-prev-then ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2083 (let ((p (sh-goto-matching-if)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2084 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2085 (list '(+ sh-indent-after-if))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2086 )))
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 (defun sh-handle-prev-open ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2089 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2090 (let ((x (sh-prev-stmt)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2091 (if (and x
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2092 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2093 (goto-char x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2094 (or
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2095 (looking-at "function\\b")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2096 (looking-at "\\s-*\\S-+\\s-*()")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2097 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2098 (list '(+ sh-indent-after-function))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2099 (list '(+ sh-indent-after-open)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2100 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2101
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2102 (defun sh-handle-this-close ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2103 (forward-char 1) ;; move over ")"
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2104 (if (sh-safe-forward-sexp -1)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2105 (list "aligned to opening paren")))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2106
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2107 (defun sh-goto-matching-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2108 (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
2109 (if found (goto-char found))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2110
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2111 (defun sh-handle-prev-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2112 ;; 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
2113 ;; 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
2114 (if (looking-at ".*\\<case\\>")
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2115 (list '(+ sh-indent-for-case-label))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2116 (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
2117
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2118 (defun sh-handle-this-esac ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2119 (if (sh-goto-matching-case)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2120 (list "aligned to matching case")))
25986
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 (defun sh-handle-prev-esac ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2123 (if (sh-goto-matching-case)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2124 (list "matching case")))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2125
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2126 (defun sh-handle-after-case-label ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2127 (if (sh-goto-matching-case)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2128 (list '(+ sh-indent-for-case-alt))))
25986
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 (defun sh-handle-prev-case-alt-end ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2131 (if (sh-goto-matching-case)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2132 (list '(+ sh-indent-for-case-label))))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2133
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2134 (defun sh-safe-forward-sexp (&optional arg)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2135 "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
2136 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
2137 (condition-case nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2138 (progn
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2139 (forward-sexp (or arg 1))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2140 (point)) ;; return point if successful
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2141 (error
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2142 (sh-debug "oops!(1) %d" (point))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2143 nil))) ;; return nil if fail
25986
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 (defun sh-goto-match-for-done ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2146 (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
2147 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2148 (goto-char found))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2149
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2150 (defun sh-handle-this-done ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2151 (if (sh-goto-match-for-done)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2152 (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
2153
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2154 (defun sh-handle-prev-done ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2155 (if (sh-goto-match-for-done)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2156 (list "previous done")))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2157
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2158 (defun sh-handle-this-do ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2159 (if (sh-goto-match-for-done)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2160 (list '(+ sh-indent-for-do))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2161
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2162 (defun sh-handle-prev-do ()
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2163 (cond
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2164 ((save-restriction
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2165 (narrow-to-region
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2166 (point)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2167 (save-excursion
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2168 (beginning-of-line)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2169 (point)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2170 (sh-goto-match-for-done))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2171 (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
2172 (list '(+ sh-indent-after-loop-construct)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2173 ((sh-goto-match-for-done)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2174 (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
2175 (list '(+ sh-indent-after-do)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2176 (t
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2177 (message "match for done NOT found")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2178 nil)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2179
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2180 ;; for rc:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2181 (defun sh-find-prev-switch ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2182 "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
2183 (re-search-backward "\\<switch\\>" nil t))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2184
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2185 (defun sh-handle-this-rc-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2186 (if (sh-find-prev-switch)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2187 (list '(+ sh-indent-after-switch))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2188 ;; (list '(+ sh-indent-for-case-label))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2189 nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2190
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2191 (defun sh-handle-prev-rc-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2192 (list '(+ sh-indent-after-case)))
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 (defun sh-check-rule (n thing)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2195 (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
2196 (val nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2197 (if rule
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2198 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2199 (setq val (funcall rule))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2200 (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
2201 n thing (point) rule val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2202 val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2203
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2204
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2205 (defun sh-get-indent-info ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2206 "Return indent-info for this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2207 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
2208 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
2209 \(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
2210 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
2211 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
2212 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
2213 modified by subsequent sublists.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2214 \(+ VAR\)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2215 \(- 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
2216 the indentation calculated so far.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2217 \(= 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
2218 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
2219 special variables such as `sh-indent-comment'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2220 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
2221 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
2222 what the indentation is based on."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2223 ;; See comments before `sh-kw'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2224 (save-excursion
51379
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
2225 (let ((have-result nil)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2226 this-kw
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2227 start
51379
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
2228 val
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2229 (result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2230 (align-point nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2231 prev-line-end x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2232 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2233 ;; 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
2234 ;;(This function never returns just t.)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2235 (cond
51379
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
2236 ((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
2237 (eq (get-text-property (1- (point)) 'face)
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
2238 font-lock-string-face))
37542
51f2e2a0c455 (sh-prev-line): Look for sh-heredoc-face
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37528
diff changeset
2239 (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
2240 (setq result t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2241 (setq have-result t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2242 ((looking-at "\\s-*#") ; was (equal this-kw "#")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2243 (if (bobp)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2244 (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
2245 (setq result (list '(= sh-indent-comment)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2246 ;; 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
2247 ;; 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
2248 (setq align-point (sh-prev-line nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2249 (setq have-result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2250 ))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2251 ) ;; cond
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
2252
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2253 (unless have-result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2254 ;; Continuation lines are handled specially
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2255 (if (sh-this-is-a-continuation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2256 (progn
64266
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2257 (setq result
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2258 (if (save-excursion
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2259 (beginning-of-line)
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2260 (not (memq (char-before (- (point) 2)) '(?\s ?\t))))
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2261 ;; By convention, if the continuation \ is not
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2262 ;; preceded by a SPC or a TAB it means that the line
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2263 ;; is cut at a place where spaces cannot be freely
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2264 ;; added/removed. I.e. do not indent the line.
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2265 (list '(= nil))
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2266 ;; We assume the line being continued is already
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2267 ;; properly indented...
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2268 ;; (setq prev-line-end (sh-prev-line))
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2269 (setq align-point (sh-prev-line nil))
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2270 (list '(+ sh-indent-for-continuation))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2271 (setq have-result t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2272 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2273 (skip-chars-forward " \t")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2274 (setq this-kw (sh-get-kw)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2275
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2276 ;; 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
2277 ;; calculating indentation info for.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2278 (if this-kw
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2279 (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
2280 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2281 (setq align-point (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2282 (sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2283 "this - setting align-point to %d" align-point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2284 (setq result (append result val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2285 (setq have-result t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2286 ;; set prev-line to continue processing remainder
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2287 ;; of this line as a previous line
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2288 (setq prev-line-end (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2289 ))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2290
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2291 (unless have-result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2292 (setq prev-line-end (sh-prev-line 'end)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2293
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2294 (if prev-line-end
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2295 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2296 ;; We start off at beginning of this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2297 ;; Scan previous statements while this is <=
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2298 ;; start of previous line.
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2299 (setq start (point)) ;; for debug only
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2300 (goto-char prev-line-end)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2301 (setq x t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2302 (while (and x (setq x (sh-prev-thing)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2303 (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
2304 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2305 ((and (equal x ")")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2306 (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
2307 sh-st-punc))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2308 (sh-debug "Case label) here")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2309 (setq x 'case-label)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2310 (if (setq val (sh-check-rule 2 x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2311 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2312 (setq result (append result val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2313 (setq align-point (point))))
53419
7864e9172d4e (sh-get-indent-info):
Richard M. Stallman <rms@gnu.org>
parents: 52758
diff changeset
2314 (or (bobp)
7864e9172d4e (sh-get-indent-info):
Richard M. Stallman <rms@gnu.org>
parents: 52758
diff changeset
2315 (forward-char -1))
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
2316 ;; FIXME: This charset looks too much like a regexp. --Stef
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2317 (skip-chars-forward "[a-z0-9]*?")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2318 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2319 ((string-match "[])}]" x)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2320 (setq x (sh-safe-forward-sexp -1))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2321 (if x
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2322 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2323 (setq align-point (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2324 (setq result (append result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2325 (list "aligned to opening paren")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2326 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2327 ((string-match "[[({]" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2328 (sh-debug "Checking special thing: %s" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2329 (if (setq val (sh-check-rule 2 x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2330 (setq result (append result val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2331 (forward-char -1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2332 (setq align-point (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2333 ((string-match "[\"'`]" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2334 (sh-debug "Skipping back for %s" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2335 ;; this was oops-2
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2336 (setq x (sh-safe-forward-sexp -1)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2337 ((stringp x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2338 (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
2339 (if (setq val (sh-check-rule 2 x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2340 ;; (or (eq t (car val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2341 ;; (eq t (car (car val))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2342 (setq result (append result val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2343 ;; 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
2344 (setq align-point (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2345 (unless (bolp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2346 (forward-char -1)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2347 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2348 (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
2349 )
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2350 ) ;; while
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2351 (sh-debug "result is %s" result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2352 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2353 (sh-debug "No prev line!")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2354 (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
2355 )
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
2356
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2357 (if align-point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2358 ;; 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
2359 (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
2360 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2361 (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
2362
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2363 (or result
64266
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2364 (setq result (list (if prev-line-end
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2365 (list t prev-line-end)
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2366 (list '= 'sh-first-lines-indent)))))
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
2367
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2368 (if (eq result t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2369 (setq result nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2370 (sh-debug "result is: %s" result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2371 result
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2372 ) ;; let
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2373 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2374
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2375
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2376 (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
2377 "Return the variable controlling indentation for this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2378 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
2379 indicating the problem.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2380 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
2381 (let ((var nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2382 (result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2383 (reason nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2384 sym elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2385 (or info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2386 (setq info (sh-get-indent-info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2387 (if (null info)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2388 (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
2389 (while (and info (null result))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2390 (setq elt (car info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2391 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2392 ((stringp elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2393 (setq reason elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2394 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2395 ((not (listp elt))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2396 (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
2397 ;; so it is a list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2398 ((eq t (car elt))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2399 ) ;; nothing
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2400 ((symbolp (setq sym (nth 1 elt)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2401 ;; 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
2402 ;; ignore other variables. Otherwise it is tricky to
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2403 ;; "learn" the comment indentation.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2404 (if (eq var 'sh-indent-comment)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2405 (setq result var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2406 (if var
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2407 (setq result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2408 "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
2409 (setq var sym))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2410 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2411 (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
2412 (setq info (cdr info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2413 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2414 (or result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2415 (setq result var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2416 (or result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2417 (setq result reason))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2418 (if (null result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2419 ;; e.g. just had (t POS)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2420 (setq result "line has default indentation"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2421 result))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2422
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2423
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2424
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2425 ;; Finding the previous line isn't trivial.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2426 ;; 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
2427 ;; 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
2428 ;; we are going to!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2429 ;; 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
2430 ;; 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
2431 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2432 ;; What we do:
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2433 ;; - go back to previous non-empty line
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2434 ;; - 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
2435 ;; - 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
2436 (defun sh-prev-line (&optional end)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2437 "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
2438 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
2439 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
2440 (save-excursion
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2441 (beginning-of-line)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2442 (forward-comment (- (point-max)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2443 (unless end (beginning-of-line))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2444 (when (and (not (bobp))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2445 (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
2446 sh-heredoc-face))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2447 (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
2448 (when p1
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2449 (goto-char p1)
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2450 (if end
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2451 (end-of-line)
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2452 (beginning-of-line)))))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2453 (unless end
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2454 ;; 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
2455 ;; 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
2456 (while (and (sh-this-is-a-continuation)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2457 (>= 0 (forward-line -1))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2458 (beginning-of-line)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2459 (skip-chars-forward " \t"))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2460 (point)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2461
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2462
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2463 (defun sh-prev-stmt ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2464 "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
2465 ;; 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
2466 ;; 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
2467 ;; 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
2468 ;; 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
2469 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2470 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2471 (let ((going t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2472 (start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2473 (found nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2474 (prev nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2475 (skip-chars-backward " \t;|&({[")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2476 (while (and (not found)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2477 (not (bobp))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2478 going)
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2479 ;; 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
2480 (if (sh-safe-forward-sexp -1)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2481 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2482 (if (looking-at sh-special-keywords)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2483 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2484 (setq found prev))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2485 (setq prev (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2486 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2487 ;; backward-sexp failed
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2488 (if (zerop (skip-chars-backward " \t()[\]{};`'"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2489 (forward-char -1))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2490 (if (bolp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2491 (let ((back (sh-prev-line nil)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2492 (if back
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2493 (goto-char back)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2494 (setq going nil)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2495 (unless found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2496 (skip-chars-backward " \t")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2497 (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
2498 (eq (char-before) ?\;)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2499 (looking-at "\\s-*[|&]"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2500 (setq found (point)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2501 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2502 (goto-char found))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2503 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2504 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2505 (skip-chars-forward " \t|&({[")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2506 (setq found (point))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2507 (if (>= (point) start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2508 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2509 (debug "We didn't move!")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2510 (setq found nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2511 (or found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2512 (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
2513 found)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2514
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2515
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2516 (defun sh-get-word ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2517 "Get a shell word skipping whitespace from point."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2518 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2519 (skip-chars-forward "\t ")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2520 (let ((start (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2521 (while
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2522 (if (looking-at "[\"'`]")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2523 (sh-safe-forward-sexp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2524 ;; (> (skip-chars-forward "^ \t\n\"'`") 0)
81380
db32b7ba9c76 Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 81313
diff changeset
2525 (> (skip-chars-forward "-_$[:alnum:]") 0)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2526 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2527 (buffer-substring start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2528 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2529
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2530 (defun sh-prev-thing ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2531 "Return the previous thing this logical line."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2532 ;; 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
2533 ;; 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
2534 ;; 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
2535 ;; 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
2536 ;; line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2537 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2538 ;; Added a kludge for ";;"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2539 ;; Possible return values:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2540 ;; nil - nothing
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2541 ;; 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
2542 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2543 (if (bolp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2544 nil
73239
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2545 (let ((start (point))
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2546 (min-point (if (sh-this-is-a-continuation)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2547 (sh-prev-line nil)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2548 (line-beginning-position))))
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2549 (skip-chars-backward " \t;" min-point)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2550 (if (looking-at "\\s-*;;")
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2551 ;; (message "Found ;; !")
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2552 ";;"
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2553 (skip-chars-backward "^)}];\"'`({[" min-point)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2554 (let ((c (if (> (point) min-point) (char-before))))
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2555 (sh-debug "stopping at %d c is %s start=%d min-point=%d"
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2556 (point) c start min-point)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2557 (if (not (memq c '(?\n nil ?\;)))
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2558 ;; c -- return a string
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2559 (char-to-string c)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2560 ;; Return the leading keyword of the "command" we supposedly
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2561 ;; skipped over. Maybe we skipped too far (e.g. past a `do' or
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2562 ;; `then' that precedes the actual command), so check whether
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2563 ;; we're looking at such a keyword and if so, move back forward.
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2564 (let ((boundary (point))
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2565 kwd next)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2566 (while
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2567 (progn
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2568 ;; Skip forward over white space newline and \ at eol.
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2569 (skip-chars-forward " \t\n\\\\" start)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2570 (if (>= (point) start)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2571 (progn
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2572 (sh-debug "point: %d >= start: %d" (point) start)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2573 nil)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2574 (if next (setq boundary next))
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2575 (sh-debug "Now at %d start=%d" (point) start)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2576 (setq kwd (sh-get-word))
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2577 (if (member kwd (sh-feature sh-leading-keywords))
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2578 (progn
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2579 (setq next (point))
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2580 t)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2581 nil))))
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2582 (goto-char boundary)
b6db8e4b9bbe (sh-prev-thing): Massage to untangle the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 73216
diff changeset
2583 kwd)))))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2584
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 (defun sh-this-is-a-continuation ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2587 "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
2588 (save-excursion
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2589 (and (zerop (forward-line -1))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2590 (looking-at ".*\\\\$")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2591 (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
2592 nil nil nil t))))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2593
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2594 (defun sh-get-kw (&optional where and-move)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2595 "Return first word of line from WHERE.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2596 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
2597 (let ((start (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2598 (if where
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2599 (goto-char where))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2600 (prog1
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2601 (buffer-substring (point)
98053
b81c85111ef9 (sh-get-kw): Remove '()' from the list of
Glenn Morris <rgm@gnu.org>
parents: 96887
diff changeset
2602 (progn (skip-chars-forward "^ \t\n;&|")(point)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2603 (unless and-move
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
2604 (goto-char start)))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2605
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2606 (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
2607 "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
2608 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
2609 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
2610 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
2611 (let ((parse-sexp-ignore-comments t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2612 prev)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2613 (setq depth (or depth 1))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2614 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2615 (condition-case nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2616 (while (and
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2617 (/= 0 depth)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2618 (not (bobp))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2619 (setq prev (sh-prev-stmt)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2620 (goto-char prev)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2621 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2622 (if (looking-at "\\\\\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2623 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2624 (forward-char 2)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2625 (skip-chars-forward " \t")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2626 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2627 ((looking-at open)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2628 (setq depth (1- depth))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2629 (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
2630 ((looking-at close)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2631 (setq depth (1+ depth))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2632 (sh-debug "found close - depth = %d" depth))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2633 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2634 ))))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2635 (error nil))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2636 (if (eq depth 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2637 prev ;; (point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2638 nil)
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
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2641
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2642 (defun sh-var-value (var &optional ignore-error)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2643 "Return the value of variable VAR, interpreting symbols.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2644 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
2645 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
2646 IGNORE-ERROR is non-nil."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2647 (let ((val (symbol-value var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2648 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2649 ((numberp val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2650 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2651 ((eq val t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2652 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2653 ((null val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2654 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2655 ((eq val '+)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2656 sh-basic-offset)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2657 ((eq val '-)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2658 (- sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2659 ((eq val '++)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2660 (* 2 sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2661 ((eq val '--)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2662 (* 2 (- sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2663 ((eq val '*)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2664 (/ sh-basic-offset 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2665 ((eq val '/)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2666 (/ (- sh-basic-offset) 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2667 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2668 (if ignore-error
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2669 (progn
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2670 (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
2671 0)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2672 (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
2673 ))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2674
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2675 (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
2676 "Set variable VAR to VALUE.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2677 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
2678 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
2679 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2680 (no-symbol
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2681 (set var value))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2682 ((= value sh-basic-offset)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2683 (set var '+))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2684 ((= value (- sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2685 (set var '-))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2686 ((eq value (* 2 sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2687 (set var '++))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2688 ((eq value (* 2 (- sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2689 (set var '--))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2690 ((eq value (/ sh-basic-offset 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2691 (set var '*))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2692 ((eq value (/ (- sh-basic-offset) 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2693 (set var '/))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2694 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2695 (set var value)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2696 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2697
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2698
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2699 (defun sh-calculate-indent (&optional info)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2700 "Return the indentation for the current line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2701 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
2702 (let ((ofs 0)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2703 (base-value 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2704 elt a b var val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2705 (or info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2706 (setq info (sh-get-indent-info)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2707 (when info
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2708 (while info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2709 (sh-debug "info: %s ofs=%s" info ofs)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2710 (setq elt (car info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2711 (cond
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2712 ((stringp elt)) ;; do nothing?
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2713 ((listp elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2714 (setq a (car (car info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2715 (setq b (nth 1 (car info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2716 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2717 ((eq a t)
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 (goto-char b)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2720 (setq val (current-indentation)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2721 (setq base-value val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2722 ((symbolp b)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2723 (setq val (sh-var-value b))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2724 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2725 ((eq a '=)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2726 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2727 ((null val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2728 ;; no indentation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2729 ;; set info to nil so we stop immediately
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2730 (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
2731 ((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
2732 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2733 ;; The following assume the (t POS) come first!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2734 (setq ofs val base-value 0)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2735 (setq info nil)))) ;; ? stop now
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2736 ((eq a '+) (setq ofs (+ ofs val)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2737 ((eq a '-) (setq ofs (- ofs val)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2738 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2739 (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
2740 (t
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2741 (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
2742 (t
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2743 (error "sh-calculate-indent invalid elt %s" elt)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2744 (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
2745 a b val base-value ofs)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2746 (setq info (cdr info)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2747 ;; return value:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2748 (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
2749
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2750 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2751 ((or (null base-value)(null ofs))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2752 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2753 ((and (numberp base-value)(numberp ofs))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2754 (sh-debug "base (%d) + ofs (%d) = %d"
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2755 base-value ofs (+ base-value ofs))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2756 (+ base-value ofs)) ;; return value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2757 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2758 (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
2759 base-value ofs)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2760 nil)))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2761
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2762
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
2763 (defun sh-indent-line ()
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2764 "Indent the current line."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2765 (interactive)
49306
ed0ec7e165de (sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49176
diff changeset
2766 (let ((indent (sh-calculate-indent))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2767 (pos (- (point-max) (point))))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2768 (when indent
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2769 (beginning-of-line)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2770 (skip-chars-forward " \t")
49306
ed0ec7e165de (sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49176
diff changeset
2771 (indent-line-to indent)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2772 ;; If initial point was within line's indentation,
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2773 ;; 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
2774 (if (> (- (point-max) pos) (point))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2775 (goto-char (- (point-max) pos))))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2776
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2777
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2778 (defun sh-blink (blinkpos &optional msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2779 "Move cursor momentarily to BLINKPOS and display MSG."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2780 ;; 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
2781 (if (numberp blinkpos)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2782 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2783 (goto-char blinkpos)
65584
6dbba0bd58df Message format fixes, commit no. 3
Deepak Goel <deego@gnufans.org>
parents: 65384
diff changeset
2784 (if msg (message "%s" msg) (message nil))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2785 (sit-for blink-matching-delay))
65610
5c0acc1c2a2c (sh-blink): Fix spurious reference to variable `message'.
Juanma Barranquero <lekktu@gmail.com>
parents: 65584
diff changeset
2786 (if msg (message "%s" msg) (message nil))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2787
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2788 (defun sh-show-indent (arg)
94046
8208c3bf9e0d (sh-show-indent): Fix typo.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93805
diff changeset
2789 "Show the how the current line would be indented.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2790 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
2791 this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2792 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
2793 a pop up window describes this variable.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2794 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
2795 we are indenting relative to, if applicable."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2796 (interactive "P")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2797 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2798 (let* ((info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2799 (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
2800 (curr-indent (current-indentation))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2801 val msg)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2802 (if (stringp var)
65584
6dbba0bd58df Message format fixes, commit no. 3
Deepak Goel <deego@gnufans.org>
parents: 65384
diff changeset
2803 (message "%s" (setq msg var))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2804 (setq val (sh-calculate-indent info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2805
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2806 (if (eq curr-indent val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2807 (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
2808 (setq msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2809 (if val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2810 (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
2811 var (symbol-value var) curr-indent val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2812 (format "%s (%s) would leave line as is"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2813 var (symbol-value var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2814 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2815 (if (and arg var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2816 (describe-variable var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2817 (if sh-blink
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2818 (let ((info (sh-get-indent-info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2819 (if (and info (listp (car info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2820 (eq (car (car info)) t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2821 (sh-blink (nth 1 (car info)) msg)
65584
6dbba0bd58df Message format fixes, commit no. 3
Deepak Goel <deego@gnufans.org>
parents: 65384
diff changeset
2822 (message "%s" msg)))
6dbba0bd58df Message format fixes, commit no. 3
Deepak Goel <deego@gnufans.org>
parents: 65384
diff changeset
2823 (message "%s" msg))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2824 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2825
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2826 (defun sh-set-indent ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2827 "Set the indentation for the current line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2828 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
2829 for a new value for it."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2830 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2831 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2832 (let* ((info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2833 (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
2834 val old-val indent-val)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2835 (if (stringp var)
65584
6dbba0bd58df Message format fixes, commit no. 3
Deepak Goel <deego@gnufans.org>
parents: 65384
diff changeset
2836 (message "Cannot set indent - %s" var)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2837 (setq old-val (symbol-value var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2838 (setq val (sh-read-variable var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2839 (condition-case nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2840 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2841 (set var val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2842 (setq indent-val (sh-calculate-indent info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2843 (if indent-val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2844 (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
2845 var (symbol-value var) indent-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2846 (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
2847 var (symbol-value var)))
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2848 ;; 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
2849 ;; 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
2850 ;; 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
2851 ;; (sh-indent-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2852 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2853 (error
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2854 (set var old-val)
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2855 (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
2856 var old-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2857 (sit-for 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2858 nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2859 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2860
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2861
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2862 (defun sh-learn-line-indent (arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2863 "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
2864
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2865 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
2866 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
2867 presently is.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2868
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2869 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
2870 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
2871 (interactive "*P")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2872 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2873 ;; 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
2874 ;; 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
2875 ;; would just be confusing.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2876 (if (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2877 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2878 (looking-at "\\s-*$"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2879 (message "sh-learn-line-indent ignores empty lines.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2880 (let* ((info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2881 (var (sh-get-indent-var-for-line info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2882 ival sval diff new-val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2883 (no-symbol arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2884 (curr-indent (current-indentation)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2885 (cond
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2886 ((stringp var)
65584
6dbba0bd58df Message format fixes, commit no. 3
Deepak Goel <deego@gnufans.org>
parents: 65384
diff changeset
2887 (message "Cannot learn line - %s" var))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2888 ((eq var 'sh-indent-comment)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2889 ;; This is arbitrary...
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2890 ;; - 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
2891 ;; - 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
2892 ;; then set to t
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2893 ;; - else set to curr-indent.
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2894 (setq sh-indent-comment
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2895 (if (= curr-indent 0)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2896 0
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2897 (let* ((sh-indent-comment t)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2898 (val2 (sh-calculate-indent info)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2899 (if (= val2 curr-indent)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2900 t
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2901 curr-indent))))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2902 (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
2903 )
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2904 ((numberp (setq sval (sh-var-value var)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2905 (setq ival (sh-calculate-indent info))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2906 (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
2907
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2908 (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
2909 curr-indent ival diff var sval)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2910 (setq new-val (+ sval diff))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2911 ;;; 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
2912 ;;; 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
2913 ;;; or vice-versa.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2914 ;;; (if (= 0 diff)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2915 ;;; (message "No change needed!")
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2916 (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
2917 (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
2918 )
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2919 (t
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2920 (debug)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2921 (message "Cannot change %s" var))))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2922
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2923
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2924
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2925 (defun sh-mark-init (buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2926 "Initialize a BUFFER to be used by `sh-mark-line'."
64266
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2927 (with-current-buffer (get-buffer-create buffer)
47595
64e6b86fa461 (sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47264
diff changeset
2928 (erase-buffer)
64266
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
2929 (occur-mode)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2930
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2931
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2932 (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
2933 "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
2934 Buffer BUFFER is in `occur-mode'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2935 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
2936 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
2937 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
2938 (let ((m1 (make-marker))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2939 start
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2940 (line ""))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2941 (when point
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2942 (set-marker m1 point (current-buffer))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2943 (if add-linenum
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
2944 (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
2945 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2946 (if (get-buffer buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2947 (set-buffer (get-buffer buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2948 (set-buffer (get-buffer-create buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2949 (occur-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2950 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2951 (goto-char (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2952 (setq start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2953 (insert line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2954 (if occur-point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2955 (setq occur-point (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2956 (insert message)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2957 (if point
38079
7563c3b44130 (sh-mark-line): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents: 37542
diff changeset
2958 (add-text-properties
7563c3b44130 (sh-mark-line): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents: 37542
diff changeset
2959 start (point)
7563c3b44130 (sh-mark-line): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents: 37542
diff changeset
2960 '(mouse-face highlight
7563c3b44130 (sh-mark-line): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents: 37542
diff changeset
2961 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
2962 (insert "\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2963 (if point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2964 (progn
47595
64e6b86fa461 (sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47264
diff changeset
2965 (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
2966 (if occur-point
47595
64e6b86fa461 (sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47264
diff changeset
2967 (put-text-property start occur-point
64e6b86fa461 (sh-mark-init): Don't set `occur-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47264
diff changeset
2968 'occur-match t))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2969 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2970 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2971
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2972
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2973
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2974 ;; Is this really worth having?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2975 (defvar sh-learned-buffer-hook nil
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
2976 "*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
2977 ;; 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
2978 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2979 ;; (defun what-i-learned (list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2980 ;; (let ((p list))
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 105753
diff changeset
2981 ;; (with-current-buffer "*scratch*"
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2982 ;; (goto-char (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2983 ;; (insert "(setq\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2984 ;; (while p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2985 ;; (insert (format " %s %s \n"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2986 ;; (nth 0 (car p)) (nth 1 (car p))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2987 ;; (setq p (cdr p)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2988 ;; (insert ")\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2989 ;; )))
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
2990 ;;
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2991 ;; (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
2992
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2993
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2994 ;; 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
2995 ;; 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
2996 ;; use the whole buffer. Use narrowing if needbe.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2997 (defun sh-learn-buffer-indent (&optional arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2998 "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
2999
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3000 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
3001 values of a variable, and the final value of all variables learned.
105109
178c9761642e * progmodes/sh-script.el (sh-learn-buffer-indent): Pop to the
Chong Yidong <cyd@stupidchicken.com>
parents: 104778
diff changeset
3002 When called interactively, pop to this buffer automatically if
178c9761642e * progmodes/sh-script.el (sh-learn-buffer-indent): Pop to the
Chong Yidong <cyd@stupidchicken.com>
parents: 104778
diff changeset
3003 there are any discrepancies.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
3004
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
3005 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
3006 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
3007 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
3008 basic indent.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3009 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
3010 is set to the prefix's numerical value.
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
3011 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
3012 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
3013
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3014 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
3015 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
3016 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
3017 removed in the future.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3018
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3019 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
3020 (interactive "P")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3021 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3022 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3023 (goto-char (point-min))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3024 (let ((learned-var-list nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3025 (out-buffer "*indent*")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3026 (num-diffs 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3027 previous-set-info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3028 (max 17)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3029 vec
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3030 msg
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
3031 (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
3032 (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
3033 initial-msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3034 (specified-basic-offset (and arg (numberp arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3035 (> arg 0)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3036 (linenum 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3037 suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3038 (setq vec (make-vector max 0))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3039 (sh-mark-init out-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3040
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3041 (if specified-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3042 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3043 (setq sh-basic-offset arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3044 (setq initial-msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3045 (format "Using specified sh-basic-offset of %d"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3046 sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3047 (setq initial-msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3048 (format "Initial value of sh-basic-offset: %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3049 sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3050
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3051 (while (< (point) (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3052 (setq linenum (1+ linenum))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3053 ;; (if (zerop (% linenum 10))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3054 (message "line %d" linenum)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3055 ;; )
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3056 (unless (looking-at "\\s-*$") ;; ignore empty lines!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3057 (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
3058 (info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3059 (var (sh-get-indent-var-for-line info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3060 sval ival diff new-val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3061 (curr-indent (current-indentation)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3062 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3063 ((null var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3064 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3065 ((stringp var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3066 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3067 ((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
3068 ;; 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
3069 (setq ival (sh-calculate-indent))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3070 (setq diff (- curr-indent ival))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3071 (setq new-val (+ sval diff))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3072 (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
3073 (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
3074 (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
3075 (progn
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
3076 ;; 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
3077 (unless (eq (symbol-value var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3078 (nth 1 previous-set-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3079 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3080 (format "Variable %s was set to %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3081 var (symbol-value var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3082 (point) out-buffer t t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3083 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3084 (format " but was previously set to %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3085 (nth 1 previous-set-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3086 (nth 2 previous-set-info) out-buffer t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3087 (setq num-diffs (1+ num-diffs))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3088 ;; (delete previous-set-info learned-var-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3089 (setcdr previous-set-info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3090 (list (symbol-value var) (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3091 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3092 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3093 (setq learned-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3094 (append (list (list var (symbol-value var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3095 (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3096 learned-var-list)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3097 (if (numberp new-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3098 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3099 (sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3100 "This line's indent value: %d" new-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3101 (if (< new-val 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3102 (setq new-val (- new-val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3103 (if (< new-val max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3104 (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
3105 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3106 ((eq var 'sh-indent-comment)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3107 (unless (= curr-indent (sh-calculate-indent info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3108 ;; this is not the default indentation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3109 (setq comments-always-default nil)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3110 (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
3111 (or (eq comment-col curr-indent)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3112 (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
3113 (setq comment-col curr-indent))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3114 ))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3115 (t
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3116 (sh-debug "Cannot learn this line!!!")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3117 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3118 (sh-debug
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3119 "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
3120 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3121 (forward-line 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3122 ) ;; while
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3123 (if sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3124 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3125 (setq msg (format
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3126 "comment-col = %s comments-always-default = %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3127 comment-col comments-always-default))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3128 ;; (message msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3129 (sh-mark-line msg nil out-buffer)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3130 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3131 ((eq comment-col 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3132 (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
3133 (comments-always-default
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3134 (setq msg "\nComments follow default indentation.\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3135 (setq comment-col t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3136 ((numberp comment-col)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3137 (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
3138 (t
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
3139 (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
3140 (setq comment-col nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3141 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3142 (sh-debug msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3143 (sh-mark-line msg nil out-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3144
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3145 (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
3146
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3147 (setq suggested (sh-guess-basic-offset vec))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3148
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3149 (if (and suggested (not specified-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3150 (let ((new-value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3151 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3152 ;; 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
3153 ((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
3154 suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3155 ;; 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
3156 (sh-learn-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3157 (if (numberp suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3158 suggested
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3159 (if (= (length suggested) 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3160 (car suggested))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3161 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3162 nil))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3163 (if new-value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3164 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3165 (setq learned-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3166 (append (list (list 'sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3167 (setq sh-basic-offset new-value)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3168 (point-max)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3169 learned-var-list))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3170 ;; 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
3171 ;; it will appear in the "Learned variable settings".
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3172 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3173 (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
3174 nil out-buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3175 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3176 (if (listp suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3177 (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
3178 (mapconcat 'int-to-string suggested " "))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3179 (format "Suggested sh-basic-offset: %d" suggested))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3180 nil out-buffer))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3181
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
3182
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3183 (setq learned-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3184 (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
3185 learned-var-list))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3186 (setq sh-indent-comment comment-col)
51379
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
3187 (let ((name (buffer-name)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3188 (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
3189 (if arg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3190 ;; Set learned variables to symbolic rather than numeric
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3191 ;; values where possible.
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3192 (dolist (learned-var (reverse learned-var-list))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3193 (let ((var (car learned-var))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3194 (val (nth 1 learned-var)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3195 (when (and (not (eq var 'sh-basic-offset))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3196 (numberp val))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3197 (sh-set-var-value var val)))))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3198 (dolist (learned-var (reverse learned-var-list))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3199 (let ((var (car learned-var)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3200 (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
3201 (nth 2 learned-var) out-buffer)))
64266
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
3202 (with-current-buffer out-buffer
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3203 (goto-char (point-min))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3204 (insert
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3205 (format "Indentation values for buffer %s.\n" name)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3206 (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
3207 num-diffs
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3208 (if (= num-diffs 1)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3209 " has" "s have")
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3210 (if (zerop num-diffs)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3211 "." ":"))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3212 )))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3213 ;; Are abnormal hooks considered bad form?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3214 (run-hook-with-args 'sh-learned-buffer-hook learned-var-list)
105371
0769a73f1d18 * image-mode.el (image-toggle-display):
Juanma Barranquero <lekktu@gmail.com>
parents: 105109
diff changeset
3215 (and (called-interactively-p 'any)
105109
178c9761642e * progmodes/sh-script.el (sh-learn-buffer-indent): Pop to the
Chong Yidong <cyd@stupidchicken.com>
parents: 104778
diff changeset
3216 (or sh-popup-occur-buffer (> num-diffs 0))
178c9761642e * progmodes/sh-script.el (sh-learn-buffer-indent): Pop to the
Chong Yidong <cyd@stupidchicken.com>
parents: 104778
diff changeset
3217 (pop-to-buffer out-buffer)))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3218
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3219 (defun sh-guess-basic-offset (vec)
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
3220 "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
3221 This is experimental, heuristic and arbitrary!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3222 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
3223 `sh-learn-buffer-indent'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3224 Return values:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3225 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
3226 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
3227 reasonable choices
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3228 nil - we couldn't find a reasonable one."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3229 (let* ((max (1- (length vec)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3230 (i 1)
51379
f61b3dac769b (sh-is-quoted-p): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 51265
diff changeset
3231 (totals (make-vector max 0)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3232 (while (< i max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3233 (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
3234 (if (zerop (% i 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3235 (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
3236 (if (< (* i 2) max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3237 (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
3238 (setq i (1+ i)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3239
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3240 (let ((x nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3241 (result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3242 tot sum p)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3243 (setq i 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3244 (while (< i max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3245 (if (/= (aref totals i) 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3246 (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
3247 (setq i (1+ i)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3248
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3249 (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
3250 (setq tot (apply '+ (append totals nil)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3251 (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
3252 vec totals tot))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3253 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3254 ((zerop (length x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3255 (message "no values!")) ;; we return nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3256 ((= (length x) 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3257 (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
3258 (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
3259 ((> (cdr (car x)) (/ tot 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3260 ;; 1st is > 50%
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3261 (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
3262 (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
3263 ((>= (cdr (car x)) (* 2 (cdr (car (cdr x)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3264 ;; 1st is >= 2 * 2nd
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3265 (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
3266 (setq result (car (car x))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3267 ((>= (+ (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
3268 ;; 1st & 2nd together >= 50% - return a list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3269 (setq p x sum 0 result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3270 (while (and p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3271 (<= (setq sum (+ sum (cdr (car p)))) (/ tot 2)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3272 (setq result (append result (list (car (car p)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3273 (setq p (cdr p)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3274 (message "Possible choices for sh-basic-offset: %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3275 (mapconcat 'int-to-string result " ")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3276 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3277 (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
3278 (car (car x)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3279 ;; result is nil here
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3280 ))
32728
6fe525e8880c (sh-mode-map): Remove bindings for
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32503
diff changeset
3281 result)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3282
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3283 ;; ========================================================================
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3284
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
3285 ;; 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
3286
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3287 (defvar sh-styles-alist nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3288 "A list of all known shell indentation styles.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3289
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3290 (defun sh-name-style (name &optional confirm-overwrite)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3291 "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
3292 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
3293 overwritten if
30956
4c05432300f8 Big bag of typos.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29844
diff changeset
3294 - - 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
3295 - - 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
3296 ;; (interactive "sName for this style: ")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3297 (interactive
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3298 (list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3299 (read-from-minibuffer "Name for this style? " )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3300 (not current-prefix-arg)))
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3301 (let ((slist (cons name
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3302 (mapcar (lambda (var) (cons var (symbol-value var)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3303 sh-var-list)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3304 (style (assoc name sh-styles-alist)))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3305 (if style
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3306 (if (and confirm-overwrite
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3307 (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
3308 (message "Not changing style %s" name)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3309 (message "Updating style %s" name)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3310 (setcdr style (cdr slist)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3311 (message "Creating new style %s" name)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3312 (push slist sh-styles-alist))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3313
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3314 (defun sh-load-style (name)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3315 "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
3316 (interactive (list (completing-read
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3317 "Which style to use for this buffer? "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3318 sh-styles-alist nil t)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3319 (let ((sl (assoc name sh-styles-alist)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3320 (if (null sl)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3321 (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
3322 (dolist (var (cdr sl))
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3323 (set (car var) (cdr var))))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3324
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3325 (defun sh-save-styles-to-buffer (buff)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3326 "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
3327 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
3328 (interactive (list
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3329 (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
3330 (with-current-buffer (get-buffer-create buff)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3331 (goto-char (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3332 (insert "\n")
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3333 (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
3334
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3335
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3336
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3337 ;; statement syntax-commands for various shells
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3338
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3339 ;; You are welcome to add the syntax or even completely new statements as
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3340 ;; appropriate for your favorite shell.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3341
49306
ed0ec7e165de (sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49176
diff changeset
3342 (defconst sh-non-closing-paren
ed0ec7e165de (sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49176
diff changeset
3343 ;; 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
3344 ;; 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
3345 (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
3346
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3347 (define-skeleton sh-case
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3348 "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
3349 (csh "expression: "
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3350 "switch( " str " )" \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3351 > "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
3352 > _ \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3353 "breaksw" \n
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3354 ( "other pattern, %s: "
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3355 < "case " str ?: \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3356 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3357 "breaksw" \n)
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3358 < "default:" \n
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3359 > _ \n
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3360 resume:
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3361 < < "endsw" \n)
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3362 (es)
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3363 (rc "expression: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3364 > "switch( " str " ) {" \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3365 > "case " (read-string "pattern: ") \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3366 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3367 ( "other pattern, %s: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3368 "case " str > \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3369 > _ \n)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3370 "case *" > \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3371 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3372 resume:
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
3373 ?\} > \n)
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3374 (sh "expression: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3375 > "case " str " in" \n
49306
ed0ec7e165de (sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49176
diff changeset
3376 ( "pattern, %s: "
ed0ec7e165de (sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49176
diff changeset
3377 > str sh-non-closing-paren \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3378 > _ \n
51594
ad56e8962943 (sh-while-getopts, sh-if, sh-case): Revert part of previous change.
Juanma Barranquero <lekktu@gmail.com>
parents: 51515
diff changeset
3379 ";;" \n)
49306
ed0ec7e165de (sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49176
diff changeset
3380 > "*" sh-non-closing-paren \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3381 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3382 resume:
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3383 "esac" > \n))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3384
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3385 (define-skeleton sh-for
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3386 "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
3387 (csh sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3388 1 ""
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3389 2 "foreach "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3390 4 " ( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3391 6 " )"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3392 15 '<
37542
51f2e2a0c455 (sh-prev-line): Look for sh-heredoc-face
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37528
diff changeset
3393 16 "end")
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
3394 (es sh-modify rc
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3395 4 " = ")
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
3396 (rc sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3397 2 "for( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3398 6 " ) {"
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
3399 15 ?\} )
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3400 (sh "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3401 > "for " str " in " _ "; do" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3402 > _ | ?$ & (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
3403 "done" > \n))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3404
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3405
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3406
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3407 (define-skeleton sh-indexed-loop
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3408 "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
3409 (bash sh-modify posix)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3410 (csh "Index variable: "
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3411 "@ " str " = 1" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3412 "while( $" str " <= " (read-string "upper limit: ") " )" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3413 > _ ?$ str \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3414 "@ " str "++" \n
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3415 < "end" \n)
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
3416 (es sh-modify rc
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3417 4 " =")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3418 (ksh88 "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3419 > "integer " str "=0" \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3420 > "while (( ( " str " += 1 ) <= "
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3421 (read-string "upper limit: ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3422 " )); do" \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3423 > _ ?$ (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
3424 "done" > \n)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3425 (posix "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3426 > str "=1" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3427 "while [ $" str " -le "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3428 (read-string "upper limit: ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3429 " ]; do" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3430 > _ ?$ str \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3431 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
3432 "done" > \n)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3433 (rc "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3434 > "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
3435 (read-string "upper limit: ")
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3436 "; i++ ) print i }'`}) {" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3437 > _ ?$ (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
3438 ?\} > \n)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3439 (sh "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3440 > "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
3441 (read-string "upper limit: ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3442 "; i++ ) print i }'`; do" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3443 > _ ?$ (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
3444 "done" > \n))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3445
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3446
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3447 (defun sh-shell-initialize-variables ()
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3448 "Scan the buffer for variable assignments.
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3449 Add these variables to `sh-shell-variables'."
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3450 (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
3451 (save-excursion
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3452 (goto-char (point-min))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3453 (setq sh-shell-variables-initialized t)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3454 (while (search-forward "=" nil t)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3455 (sh-assignment 0)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3456 (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
3457 (buffer-name)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3458
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3459 (defvar sh-add-buffer)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3460
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3461 (defun sh-add-completer (string predicate code)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3462 "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
3463 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
3464 so it takes three arguments:
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3465 STRING, the current buffer contents;
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3466 PREDICATE, the predicate for filtering possible matches;
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3467 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
3468 CODE can be nil, t or `lambda'.
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3469 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
3470 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
3471 `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
3472 (let ((sh-shell-variables
64266
a634aa374675 (sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 64085
diff changeset
3473 (with-current-buffer sh-add-buffer
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3474 (or sh-shell-variables-initialized
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3475 (sh-shell-initialize-variables))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3476 (nconc (mapcar (lambda (var)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3477 (let ((name
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3478 (substring var 0 (string-match "=" var))))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3479 (cons name name)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3480 process-environment)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3481 sh-shell-variables))))
49306
ed0ec7e165de (sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49176
diff changeset
3482 (case code
52322
e9922af67382 (sh-builtins): Add some bash builtins.
Glenn Morris <rgm@gnu.org>
parents: 52099
diff changeset
3483 ((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
3484 (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
3485 (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
3486
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3487 (defun sh-add (var delta)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3488 "Insert an addition of VAR and prefix DELTA for Bourne (type) shell."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3489 (interactive
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3490 (let ((sh-add-buffer (current-buffer)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3491 (list (completing-read "Variable: " 'sh-add-completer)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3492 (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
3493 (insert (sh-feature '((bash . "$(( ")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3494 (ksh88 . "$(( ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3495 (posix . "$(( ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3496 (rc . "`{expr $")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3497 (sh . "`expr $")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3498 (zsh . "$[ ")))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3499 (sh-remember-variable var)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3500 (if (< delta 0) " - " " + ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3501 (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
3502 (sh-feature '((bash . " ))")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3503 (ksh88 . " ))")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3504 (posix . " ))")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3505 (rc . "}")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3506 (sh . "`")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3507 (zsh . " ]")))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3508
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3509
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3510
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3511 (define-skeleton sh-function
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3512 "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
3513 (bash sh-modify ksh88
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3514 3 "() {")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3515 (ksh88 "name: "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3516 "function " str " {" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3517 > _ \n
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3518 < "}" \n)
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
3519 (rc sh-modify ksh88
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3520 1 "fn ")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3521 (sh ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3522 "() {" \n
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3523 > _ \n
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3524 < "}" \n))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3525
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3526
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3527
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3528 (define-skeleton sh-if
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3529 "Insert an if statement. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3530 (csh "condition: "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3531 "if( " str " ) then" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3532 > _ \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3533 ( "other condition, %s: "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3534 < "else if( " str " ) then" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3535 > _ \n)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3536 < "else" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3537 > _ \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3538 resume:
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3539 < "endif" \n)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3540 (es "condition: "
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3541 > "if { " str " } {" \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3542 > _ \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3543 ( "other condition, %s: "
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3544 "} { " str " } {" > \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3545 > _ \n)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3546 "} {" > \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3547 > _ \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3548 resume:
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
3549 ?\} > \n)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3550 (rc "condition: "
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3551 > "if( " str " ) {" \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3552 > _ \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3553 ( "other condition, %s: "
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3554 "} else if( " str " ) {" > \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3555 > _ \n)
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3556 "} else {" > \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3557 > _ \n
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3558 resume:
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
3559 ?\} > \n)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3560 (sh "condition: "
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3561 '(setq input (sh-feature sh-test))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3562 > "if " str "; then" \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3563 > _ \n
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3564 ( "other condition, %s: "
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3565 > "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
3566 > \n)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3567 "else" > \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3568 > \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3569 resume:
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3570 "fi" > \n))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3571
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3572
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3573
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3574 (define-skeleton sh-repeat
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3575 "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
3576 (es nil
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3577 > "forever {" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3578 > _ \n
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
3579 ?\} > \n)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3580 (zsh "factor: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3581 > "repeat " str "; do" > \n
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3582 > \n
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3583 "done" > \n))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3584
17501
478f9bb8575c Remove all menu-enable properties except for sh-case.
Richard M. Stallman <rms@gnu.org>
parents: 17480
diff changeset
3585 ;;;(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
3586
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3587
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3588
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3589 (define-skeleton sh-select
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3590 "Insert a select statement. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3591 (ksh88 "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3592 > "select " str " in " _ "; do" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3593 > ?$ str \n
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3594 "done" > \n)
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
3595 (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
3596 ;;;(put 'sh-select 'menu-enable '(sh-feature sh-select))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3597
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3598
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3599
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3600 (define-skeleton sh-tmp-file
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3601 "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
3602 (bash sh-append ksh88)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3603 (csh (file-name-nondirectory (buffer-file-name))
66027
61174c5e6da6 (sh-tmp-file): Use mktemp -t. Finish support for es and rc shells.
Richard M. Stallman <rms@gnu.org>
parents: 65996
diff changeset
3604 "set tmp = `mktemp -t " str ".XXXXXX`" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3605 "onintr exit" \n _
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3606 (and (goto-char (point-max))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3607 (not (bolp))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3608 ?\n)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3609 "exit:\n"
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3610 "rm $tmp* >&/dev/null" > \n)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3611 (es (file-name-nondirectory (buffer-file-name))
66027
61174c5e6da6 (sh-tmp-file): Use mktemp -t. Finish support for es and rc shells.
Richard M. Stallman <rms@gnu.org>
parents: 65996
diff changeset
3612 > "local( signals = $signals sighup sigint;" \n
61174c5e6da6 (sh-tmp-file): Use mktemp -t. Finish support for es and rc shells.
Richard M. Stallman <rms@gnu.org>
parents: 65996
diff changeset
3613 > "tmp = `{ mktemp -t " str ".XXXXXX } ) {" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3614 > "catch @ e {" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3615 > "rm $tmp^* >[2]/dev/null" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3616 "throw $e" \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3617 "} {" > \n
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3618 _ \n
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
3619 ?\} > \n
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
3620 ?\} > \n)
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
3621 (ksh88 sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3622 7 "EXIT")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3623 (rc (file-name-nondirectory (buffer-file-name))
66027
61174c5e6da6 (sh-tmp-file): Use mktemp -t. Finish support for es and rc shells.
Richard M. Stallman <rms@gnu.org>
parents: 65996
diff changeset
3624 > "tmp = `{ mktemp -t " str ".XXXXXX }" \n
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3625 "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
3626 (sh (file-name-nondirectory (buffer-file-name))
66027
61174c5e6da6 (sh-tmp-file): Use mktemp -t. Finish support for es and rc shells.
Richard M. Stallman <rms@gnu.org>
parents: 65996
diff changeset
3627 > "TMP=`mktemp -t " str ".XXXXXX`" \n
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3628 "trap \"rm $TMP* 2>/dev/null\" " ?0 \n))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3629
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3630
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3631
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3632 (define-skeleton sh-until
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3633 "Insert an until loop. See `sh-feature'."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3634 (sh "condition: "
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3635 '(setq input (sh-feature sh-test))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3636 > "until " str "; do" \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3637 > _ \n
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3638 "done" > \n))
17501
478f9bb8575c Remove all menu-enable properties except for sh-case.
Richard M. Stallman <rms@gnu.org>
parents: 17480
diff changeset
3639 ;;;(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
3640
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3641
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3642
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3643 (define-skeleton sh-while
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3644 "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
3645 (csh sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3646 2 ""
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3647 3 "while( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3648 5 " )"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3649 10 '<
37542
51f2e2a0c455 (sh-prev-line): Look for sh-heredoc-face
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37528
diff changeset
3650 11 "end")
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
3651 (es sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3652 3 "while { "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3653 5 " } {"
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
3654 10 ?\} )
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
3655 (rc sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3656 3 "while( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3657 5 " ) {"
40335
96186171af6d no functional changes - a preparation for the next patch
Sam Steingold <sds@gnu.org>
parents: 39890
diff changeset
3658 10 ?\} )
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3659 (sh "condition: "
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3660 '(setq input (sh-feature sh-test))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3661 > "while " str "; do" \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3662 > _ \n
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3663 "done" > \n))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3664
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3665
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3666
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3667 (define-skeleton sh-while-getopts
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3668 "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
3669 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
3670 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
3671 (bash sh-modify sh
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3672 18 "${0##*/}")
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3673 (csh nil
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3674 "while( 1 )" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3675 > "switch( \"$1\" )" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3676 '(setq input '("- x" . 2))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3677 > >
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3678 ( "option, %s: "
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3679 < "case " '(eval str)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3680 '(if (string-match " +" str)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3681 (setq v1 (substring str (match-end 0))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3682 str (substring str 0 (match-beginning 0)))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3683 (setq v1 nil))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3684 str ?: \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3685 > "set " v1 & " = $2" | -4 & _ \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3686 (if v1 "shift") & \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3687 "breaksw" \n)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3688 < "case --:" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3689 > "shift" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3690 < "default:" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3691 > "break" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3692 resume:
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3693 < < "endsw" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3694 "shift" \n
39890
bc9296467c86 (sh-font-lock-syntactic-keywords): Handle here-docs differently.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38079
diff changeset
3695 < "end" \n)
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
3696 (ksh88 sh-modify sh
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3697 16 "print"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3698 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
3699 37 "OPTIND-1")
52758
aaeb60b0150f (sh-feature): Handle sh-modify like sh-append.
Richard M. Stallman <rms@gnu.org>
parents: 52682
diff changeset
3700 (posix sh-modify sh
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3701 18 "$(basename $0)")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3702 (sh "optstring: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3703 > "while getopts :" str " OPT; do" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3704 > "case $OPT in" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3705 '(setq v1 (append (vconcat str) nil))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3706 ( (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
3707 (if (eq (nth 1 v1) ?:)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3708 (setq v1 (nthcdr 2 v1)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3709 v2 "\"$OPTARG\"")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3710 (setq v1 (cdr v1)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3711 v2 nil)))
49306
ed0ec7e165de (sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49176
diff changeset
3712 > 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
3713 > _ 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
3714 > ";;" \n)
49306
ed0ec7e165de (sh-indent-line): Use indent-line-to.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49176
diff changeset
3715 > "*" sh-non-closing-paren \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3716 > "echo" " \"usage: " "`basename $0`"
15027
30c4f64f3579 (sh-while-getopts): Punctuate help message better.
Richard M. Stallman <rms@gnu.org>
parents: 14892
diff changeset
3717 " [+-" '(setq v1 (point)) str
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3718 '(save-excursion
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3719 (while (search-backward ":" v1 t)
15027
30c4f64f3579 (sh-while-getopts): Punctuate help message better.
Richard M. Stallman <rms@gnu.org>
parents: 14892
diff changeset
3720 (replace-match " ARG] [+-" t t)))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3721 (if (eq (preceding-char) ?-) -5)
29844
093c79809c9e (sh-while-getopts): Fix handling of
Gerd Moellmann <gerd@gnu.org>
parents: 29422
diff changeset
3722 (if (and (sequencep v1) (length v1)) "] " "} ")
28923
dcafe3c9cd6c (sh-while-getopts) <sh>: Handle case that
Gerd Moellmann <gerd@gnu.org>
parents: 26967
diff changeset
3723 "[--] ARGS...\"" \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3724 "exit 2" > \n
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3725 "esac" >
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3726 \n "done"
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3727 > \n
61534
3d7c70a6a91e (sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 61394
diff changeset
3728 "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
3729 "OPTIND=1" \n))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3730
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3731
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3732
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3733 (defun sh-assignment (arg)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3734 "Remember preceding identifier for future completion and do self-insert."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3735 (interactive "p")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3736 (self-insert-command arg)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3737 (if (<= arg 1)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3738 (sh-remember-variable
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3739 (save-excursion
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3740 (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
3741 (prog1 (point)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3742 (beginning-of-line 1))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3743 t)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
3744 (match-string 1))))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3745
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3746
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3747 (defun sh-maybe-here-document (arg)
32480
261dcd5e9f0a (sh-imenu-generic-expression): Fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31731
diff changeset
3748 "Insert self. Without prefix, following unquoted `<' inserts here document.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3749 The document is bounded by `sh-here-document-word'."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3750 (interactive "*P")
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3751 (self-insert-command (prefix-numeric-value arg))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3752 (or arg
104298
75f3a35d516e * progmodes/sh-script.el (sh-maybe-here-document): Avoid inserting
Chong Yidong <cyd@stupidchicken.com>
parents: 102126
diff changeset
3753 (not (looking-back "[^<]<<"))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3754 (save-excursion
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3755 (backward-char 2)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3756 (sh-quoted-p))
61534
3d7c70a6a91e (sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 61394
diff changeset
3757 (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
3758 (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
3759 ""))
3d7c70a6a91e (sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 61394
diff changeset
3760 (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
3761 sh-here-document-word)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3762 (insert sh-here-document-word)
64051
d700ccca5bd4 (sh, sh-script): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents: 63885
diff changeset
3763 (or (eolp) (looking-at "[ \t]") (insert ?\s))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3764 (end-of-line 1)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3765 (while
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3766 (sh-quoted-p)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3767 (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
3768 (insert ?\n tabs)
51265
575ad90ca254 (sh-here-document-word): Document new treatment of leading "-".
Glenn Morris <rgm@gnu.org>
parents: 49743
diff changeset
3769 (save-excursion
61534
3d7c70a6a91e (sh-here-document-word): Make it a defcustom. Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 61394
diff changeset
3770 (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
3771 "\\`-?[ \t]*" "" delim))))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3772
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3773
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3774 ;; various other commands
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3775
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3776 (autoload 'comint-dynamic-complete "comint"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3777 "Dynamically perform completion at point." t)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3778
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3779 (autoload 'shell-dynamic-complete-command "shell"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3780 "Dynamically complete the command at point." t)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3781
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3782 (autoload 'comint-dynamic-complete-filename "comint"
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3783 "Dynamically complete the filename at point." t)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3784
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3785 (autoload 'shell-dynamic-complete-environment-variable "shell"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3786 "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
3787
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3788
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3789
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3790 (defun sh-beginning-of-command ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3791 "Move point to successive beginnings of commands."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3792 (interactive)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3793 (if (re-search-backward sh-beginning-of-command nil t)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3794 (goto-char (match-beginning 2))))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3795
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3796 (defun sh-end-of-command ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3797 "Move point to successive ends of commands."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3798 (interactive)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3799 (if (re-search-forward sh-end-of-command nil t)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3800 (goto-char (match-end 1))))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3801
59566
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3802 ;; Backslashification. Stolen from make-mode.el.
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3803
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3804 (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
3805 "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
3806 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
3807 With an argument, deletes the backslashes.
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3808
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3809 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
3810 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
3811 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
3812 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
3813 (interactive "r\nP")
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3814 (save-excursion
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3815 (goto-char from)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3816 (let ((column sh-backslash-column)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3817 (endmark (make-marker)))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3818 (move-marker endmark to)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3819 ;; 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
3820 (if sh-backslash-align
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3821 (progn
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3822 (if (not delete-flag)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3823 (while (< (point) to)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3824 (end-of-line)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3825 (if (= (preceding-char) ?\\)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3826 (progn (forward-char -1)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3827 (skip-chars-backward " \t")))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3828 (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
3829 (forward-line 1)))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3830 ;; 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
3831 ;; past the margin.
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3832 (if (> (% column tab-width) 0)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3833 (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
3834 tab-width)))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3835 (if (< adjusted (window-width))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3836 (setq column adjusted))))))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3837 ;; 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
3838 (goto-char from)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3839 (while (and (< (point) endmark) (eolp))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3840 (forward-line 1))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3841 ;; 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
3842 (while (and (< (point) endmark)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3843 ;; Don't backslashify the last line
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3844 ;; 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
3845 (save-excursion
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3846 (forward-line 1)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3847 (< (point) endmark)))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3848 (if (not delete-flag)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3849 (sh-append-backslash column)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3850 (sh-delete-backslash))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3851 (forward-line 1))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3852 (move-marker endmark nil))))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3853
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3854 (defun sh-append-backslash (column)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3855 (end-of-line)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3856 ;; 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
3857 (if (= (preceding-char) ?\\)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3858 (progn (forward-char -1)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3859 (delete-horizontal-space)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3860 (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
3861 (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
3862 (insert "\\")))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3863
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3864 (defun sh-delete-backslash ()
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3865 (end-of-line)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3866 (or (bolp)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3867 (progn
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3868 (forward-char -1)
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3869 (if (looking-at "\\\\")
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3870 (delete-region (1+ (point))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3871 (progn (skip-chars-backward " \t") (point)))))))
7b97d6104891 (sh-mode-map): Bind C-c C-\.
Richard M. Stallman <rms@gnu.org>
parents: 59251
diff changeset
3872
13707
9356c7d7dcd6 Provide sh-script.
Karl Heuer <kwzh@gnu.org>
parents: 13705
diff changeset
3873 (provide 'sh-script)
18382
0e4943a370e2 Whitespace change.
Richard M. Stallman <rms@gnu.org>
parents: 18024
diff changeset
3874
59622
5ec981fa30e5 (sh-here-doc-open-re): Don't allow `|' or other
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 59566
diff changeset
3875 ;; arch-tag: eccd8b72-f337-4fc2-ae86-18155a69d937
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3876 ;;; sh-script.el ends here