annotate lisp/progmodes/sh-script.el @ 26488:bfcbc828fdbc

(compilation-parse-errors): Use compilation-buffer-p instead of testing major-mode.
author Gerd Moellmann <gerd@gnu.org>
date Thu, 18 Nov 1999 15:54:18 +0000
parents 29aeb35781cd
children da094b0ffe3c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; sh-script.el --- shell-script editing commands for Emacs
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14148
diff changeset
2
25554
e52ba2d9f6d7 (sh-tmp-file): Use $TMPDIR, if defined, for sh.
Eli Zaretskii <eliz@gnu.org>
parents: 24906
diff changeset
3 ;; Copyright (C) 1993, 94, 95, 96, 97, 1999 by Free Software Foundation, Inc.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
23869
8d2bb5d1416a Update comment.
Karl Heuer <kwzh@gnu.org>
parents: 23589
diff changeset
5 ;; Author: Daniel Pfeiffer <occitan@esperanto.org>
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
6 ;; Version: 2.0f
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Maintainer: FSF
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
8 ;; Keywords: languages, unix
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14148
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14148
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14148
diff changeset
25 ;; Boston, MA 02111-1307, USA.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
29 ;; Major mode for editing shell scripts. Bourne, C and rc shells as well
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
30 ;; as various derivatives are supported and easily derived from. Structured
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
31 ;; statements can be inserted with one command or abbrev. Completion is
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
32 ;; available for filenames, variables known from the script, the shell and
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
33 ;; the environment as well as commands.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
34
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
35 ;;; Known Bugs:
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
37 ;; - In Bourne the keyword `in' is not anchored to case, for, select ...
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
38 ;; - Variables in `"' strings aren't fontified because there's no way of
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
39 ;; syntactically distinguishing those from `'' strings.
8257
bbf6304598d9 "Comment out" autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents: 8121
diff changeset
40
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
41 ;; Indentation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
42 ;; ===========
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
43 ;; Indentation for rc and es modes is very limited, but for Bourne shells
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
44 ;; and its derivatives it is quite customizable.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
45 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
46 ;; The following description applies to sh and derived shells (bash,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
47 ;; zsh, ...).
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
48 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
49 ;; There are various customization variables which allow tailoring to
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
50 ;; a wide variety of styles. Most of these variables are named
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
51 ;; sh-indent-for-XXX and sh-indent-after-XXX. For example.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
52 ;; sh-indent-after-if controls the indenting of a line following
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
53 ;; an if statement, and sh-indent-for-fi controls the indentation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
54 ;; of the line containing the fi.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
55 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
56 ;; You can set each to a numeric value, but it is often more convenient
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
57 ;; to a symbol such as `+' which uses the value of variable `sh-basic-offset'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
58 ;; By changing this one variable you can increase or decrease how much
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
59 ;; indentation there is. Valid symbols:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
60 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
61 ;; + Indent right by sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
62 ;; - Indent left by sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
63 ;; ++ Indent right twice sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
64 ;; -- Indent left twice sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
65 ;; * Indent right half sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
66 ;; / Indent left half sh-basic-offset.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
67 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
68 ;; There are 4 commands to help set the indentation variables:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
69 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
70 ;; `sh-show-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
71 ;; This shows what variable controls the indentation of the current
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
72 ;; line and its value.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
73 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
74 ;; `sh-set-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
75 ;; This allows you to set the value of the variable controlling the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
76 ;; current line's indentation. You can enter a number or one of a
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
77 ;; number of special symbols to denote the value of sh-basic-offset,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
78 ;; or its negative, or half it, or twice it, etc. If you've used
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
79 ;; cc-mode this should be familiar. If you forget which symbols are
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
80 ;; valid simply press C-h at the prompt.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
81 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
82 ;; `sh-learn-line-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
83 ;; Simply make the line look the way you want it, then invoke this
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
84 ;; command. It will set the variable to the value that makes the line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
85 ;; indent like that. If called with a prefix argument then it will set
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
86 ;; the value to one of the symbols if applicable.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
87 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
88 ;; `sh-learn-buffer-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
89 ;; This is the deluxe function! It "learns" the whole buffer (use
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
90 ;; narrowing if you want it to process only part). It outputs to a
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
91 ;; buffer *indent* any conflicts it finds, and all the variables it has
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
92 ;; learned. This buffer is a sort of Occur mode buffer, allowing you to
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
93 ;; easily find where something was set. It is popped to automatically
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
94 ;; if there are any conflicts found or if `sh-popup-occur-buffer' is
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
95 ;; non-nil.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
96 ;; `sh-indent-comment' will be set if all comments follow the same
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
97 ;; pattern; if they don't it will be set to nil.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
98 ;; Whether `sh-basic-offset' is set is determined by variable
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
99 ;; `sh-learn-basic-offset'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
100 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
101 ;; Unfortunately, `sh-learn-buffer-indent' can take a long time to run
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
102 ;; (e.g. if there are large case statements). Perhaps it does not make
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
103 ;; sense to run it on large buffers: if lots of lines have different
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
104 ;; indentation styles it will produce a lot of diagnostics in the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
105 ;; *indent* buffer; if there is a consistent style then running
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
106 ;; `sh-learn-buffer-indent' on a small region of the buffer should
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
107 ;; suffice.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
108 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
109 ;; Saving indentation values
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
110 ;; -------------------------
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
111 ;; After you've learned the values in a buffer, how to you remember
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
112 ;; them? Originally I had hoped that `sh-learn-buffer-indent'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
113 ;; would make this unnecessary; simply learn the values when you visit
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
114 ;; the buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
115 ;; You can do this automatically like this:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
116 ; (add-hook 'sh-set-shell-hook 'sh-learn-buffer-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
117 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
118 ;; However... `sh-learn-buffer-indent' is extremely slow,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
119 ;; especially on large-ish buffer. Also, if there are conflicts the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
120 ;; "last one wins" which may not produce the desired setting.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
121 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
122 ;; So...There is a minimal way of being able to save indentation values and
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
123 ;; to reload them in another buffer or at another point in time.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
124 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
125 ;; Use `sh-name-style' to give a name to the indentation settings of
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
126 ;; the current buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
127 ;; Use `sh-load-style' to load indentation settings for the current
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
128 ;; buffer from a specific style.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
129 ;; Use `sh-save-styles-to-buffer' to write all the styles to a buffer
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
130 ;; in lisp code. You can then store it in a file and later use
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
131 ;; `load-file' to load it.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
132 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
133 ;; Indentation variables - buffer local or global?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
134 ;; ----------------------------------------------
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
135 ;; I think that often having them buffer-local makes sense,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
136 ;; especially if one is using `sh-learn-buffer-indent'. However, if
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
137 ;; a user sets values using customization, these changes won't appear
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
138 ;; to work if the variables are already local!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
139 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
140 ;; To get round this, there is a variable `sh-make-vars-local' and 2
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
141 ;; functions: `sh-make-vars-local' and `sh-reset-indent-vars-to-global-values'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
142 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
143 ;; If `sh-make-vars-local' is non-nil, then these variables become
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
144 ;; buffer local when the mode is established.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
145 ;; If this is nil, then the variables are global. At any time you
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
146 ;; can make them local with the command `sh-make-vars-local'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
147 ;; Conversely, to update with the global values you can use the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
148 ;; command `sh-reset-indent-vars-to-global-values'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
149 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
150 ;; This may be awkward, but the intent is to cover all cases.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
151 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
152 ;; Awkward things, pitfalls
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
153 ;; ------------------------
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
154 ;; Indentation for a sh script is complicated for a number of reasons:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
155 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
156 ;; 1. You can't format by simply looking at symbols, you need to look
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
157 ;; at keywords. [This is not the case for rc and es shells.]
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
158 ;; 2. The character ")" is used both as a matched pair "(" ... ")" and
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
159 ;; as a stand-alone symbol (in a case alternative). This makes
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
160 ;; things quite tricky!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
161 ;; 3. Here-documents in a script should be treated "as is", and when
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
162 ;; they terminate we want to revert to the indentation of the line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
163 ;; containing the "<<" symbol.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
164 ;; 4. A line may be continued using the "\".
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
165 ;; 5. The character "#" (outside a string) normally starts a comment,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
166 ;; but it doesn't in the sequence "$#"!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
167 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
168 ;; To try and address points 2 3 and 5 I used a feature that cperl mode
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
169 ;; uses, that of a text's syntax property. This, however, has 2
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
170 ;; disadvantages:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
171 ;; 1. We need to scan the buffer to find which ")" symbols belong to a
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
172 ;; case alternative, to find any here documents, and handle "$#".
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
173 ;; 2. Setting the text property makes the buffer modified. If the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
174 ;; buffer is read-only buffer we have to cheat and bypass the read-only
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
175 ;; status. This is for cases where the buffer started read-only buffer
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
176 ;; but the user issued `toggle-read-only'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
177 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
178 ;; Bugs
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
179 ;; ----
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
180 ;; - Here-documents are marked with text properties face and syntax
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
181 ;; table. This serves 2 purposes: stopping indentation while inside
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
182 ;; them, and moving over them when finding the previous line to
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
183 ;; indent to. However, if font-lock mode is active when there is
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
184 ;; any change inside the here-document font-lock clears that
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
185 ;; property. This causes several problems: lines after the here-doc
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
186 ;; will not be re-indentation properly, words in the here-doc region
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
187 ;; may be fontified, and indentation may occur within the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
188 ;; here-document.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
189 ;; I'm not sure how to fix this, perhaps using the point-entered
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
190 ;; property. Anyway, if you use font lock and change a
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
191 ;; here-document, I recommend using M-x sh-rescan-buffer after the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
192 ;; changes are made. Similarly, when using higlight-changes-mode,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
193 ;; changes inside a here-document may confuse shell indenting, but again
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
194 ;; using `sh-rescan-buffer' should fix them.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
195 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
196 ;; - 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
197 ;; independently, rather than saving state information.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
198 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
199 ;; - `sh-learn-buffer-indent' is extremely slow.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
200 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
201 ;; Richard Sharman <rsharman@pobox.com> June 1999.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
202
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 ;;; Code:
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 ;; page 1: variables and settings
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
206 ;; page 2: indentation stuff
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
207 ;; page 3: mode-command and utility functions
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
208 ;; page 4: statement syntax-commands for various shells
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
209 ;; page 5: various other commands
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
211 (require 'executable)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
213
17068
d1391b21626f (sh-mode-hook, sh-set-shell-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents: 16839
diff changeset
214
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
215 (defgroup sh nil
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
216 "Shell programming utilities"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
217 :group 'unix
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
218 :group 'languages)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
219
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
220 (defgroup sh-script nil
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
221 "Shell script mode"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
222 :group 'sh
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
223 :prefix "sh-")
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
224
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
225
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
226 (defcustom sh-ancestor-alist
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
227 '((ash . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
228 (bash . jsh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
229 (dtksh . ksh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
230 (es . rc)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
231 (itcsh . tcsh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
232 (jcsh . csh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
233 (jsh . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
234 (ksh . ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
235 (ksh88 . jsh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
236 (oash . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
237 (pdksh . ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
238 (posix . sh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
239 (tcsh . csh)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
240 (wksh . ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
241 (wsh . sh)
23501
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
242 (zsh . ksh88)
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
243 (rpm . sh))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
244 "*Alist showing the direct ancestor of various shells.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
245 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
246 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
247
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
248 csh C Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
249 jcsh C Shell with Job Control
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
250 tcsh Toronto C Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
251 itcsh ? Toronto C Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
252 rc Plan 9 Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
253 es Extensible Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
254 sh Bourne Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
255 ash ? Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
256 jsh Bourne Shell with Job Control
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
257 bash GNU Bourne Again Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
258 ksh88 Korn Shell '88
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
259 ksh Korn Shell '93
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
260 dtksh CDE Desktop Korn Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
261 pdksh Public Domain Korn Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
262 wksh Window Korn Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
263 zsh Z Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
264 oash SCO OA (curses) Shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
265 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
266 wsh ? Shell"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
267 :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
268 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
269
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
270
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
271 (defcustom sh-alias-alist
15950
c4ae4ea7fa7a (sh-alias-alist): Use gnu/linux, not lignux.
Richard M. Stallman <rms@gnu.org>
parents: 15677
diff changeset
272 (nconc (if (eq system-type 'gnu/linux)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
273 '((csh . tcsh)
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
274 (ksh . pdksh)))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
275 ;; for the time being
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
276 '((ksh . ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
277 (sh5 . sh)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
278 "*Alist for transforming shell names to what they really are.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
279 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
280 shell it really is."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
281 :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
282 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
283
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
284
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
285 (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
286 (or
16839
daaa2c5bb40a (sh-shell-file): Downcase and remove extension on shells in NT.
Richard M. Stallman <rms@gnu.org>
parents: 16810
diff changeset
287 ;; 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
288 ;; 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
289 ;; 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
290 (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
291 (let* ((shell (getenv "SHELL"))
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
292 (shell-base
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
293 (and shell (file-name-nondirectory shell))))
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
294 ;; 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
295 ;; so use the default instead.
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
296 (if (or (null shell)
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
297 (member (downcase shell-base)
21980
e73c0672d7b3 (sh-shell-file): Add cmdproxy to MS shells.
Richard M. Stallman <rms@gnu.org>
parents: 21925
diff changeset
298 '("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
299 "cmdproxy.exe")))
21925
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
300 "/bin/sh"
3e498c36ccce (sh-shell-file): If $SHELL evaluates to
Eli Zaretskii <eliz@gnu.org>
parents: 21669
diff changeset
301 (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
302 (getenv "SHELL")
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
303 "/bin/sh")
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
304 "*The executable file name for the shell being programmed."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
305 :type 'string
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
306 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
307
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
308
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
309 (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
310 ;; 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
311 '((bash)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
312 (csh . "-f")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
313 (pdksh)
14886
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
314 ;; 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
315 (ksh88)
14886
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
316 ;; -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
317 (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
318 ;; 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
319 ;; 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
320 (wksh)
96423e733197 (sh-shell-arg): Add no options for bash, ksh, or wksh.
Richard M. Stallman <rms@gnu.org>
parents: 14876
diff changeset
321 ;; -f means don't run .zshrc.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
322 (zsh . "-f"))
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
323 "*Single argument string for the magic number. See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
324 :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
325 (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
326 (string :tag "Arguments")
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
327 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
328 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
329 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
330 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
331
20395
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
332 (defcustom sh-imenu-generic-expression
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
333 (list
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
334 (cons 'sh
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
335 (concat
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
336 "\\(^\\s-*function\\s-+[A-Za-z_][A-Za-z_0-9]*\\)"
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
337 "\\|"
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
338 "\\(^\\s-*[A-Za-z_][A-Za-z_0-9]*\\s-*()\\)")))
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
339 "*Regular expression for recognizing shell function definitions.
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
340 See `sh-feature'."
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
341 :type '(repeat (cons (symbol :tag "Shell")
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
342 regexp))
21669
9861518505cb *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20900
diff changeset
343 :group 'sh-script
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
344 :version "20.4")
20395
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
345
14195
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
346 (defvar sh-shell-variables nil
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
347 "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
348 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
349 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
350 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
351
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
352 (defvar sh-shell-variables-initialized nil
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
353 "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
354
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
355 (defun sh-canonicalize-shell (shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
356 "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
357 (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
358 (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
359 (or (symbolp shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
360 (setq shell (intern shell)))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
361 (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
362 shell))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
363
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
364 (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
365 "The shell being programmed. This is set by \\[sh-set-shell].")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
366
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
367 ;;; I turned off this feature because it doesn't permit typing commands
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
368 ;;; in the usual way without help.
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
369 ;;;(defvar sh-abbrevs
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
370 ;;; '((csh eval sh-abbrevs shell
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
371 ;;; "switch" 'sh-case
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
372 ;;; "getopts" 'sh-while-getopts)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
373
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
374 ;;; (es eval sh-abbrevs shell
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
375 ;;; "function" 'sh-function)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
376
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
377 ;;; (ksh88 eval sh-abbrevs sh
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
378 ;;; "select" 'sh-select)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
379
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
380 ;;; (rc eval sh-abbrevs shell
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
381 ;;; "case" 'sh-case
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
382 ;;; "function" 'sh-function)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
383
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
384 ;;; (sh eval sh-abbrevs shell
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
385 ;;; "case" 'sh-case
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
386 ;;; "function" 'sh-function
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
387 ;;; "until" 'sh-until
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
388 ;;; "getopts" 'sh-while-getopts)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
389
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
390 ;;; ;; The next entry is only used for defining the others
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
391 ;;; (shell "for" sh-for
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
392 ;;; "loop" sh-indexed-loop
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
393 ;;; "if" sh-if
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
394 ;;; "tmpfile" sh-tmp-file
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
395 ;;; "while" sh-while)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
396
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
397 ;;; (zsh eval sh-abbrevs ksh88
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
398 ;;; "repeat" 'sh-repeat))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
399 ;;; "Abbrev-table used in Shell-Script mode. See `sh-feature'.
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
400 ;;;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
401 ;;;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
402
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (defvar sh-mode-syntax-table
16535
d5eeca7cdaf2 (sh-mode-syntax-table): Turn on comment syntax for #,
Richard M. Stallman <rms@gnu.org>
parents: 16533
diff changeset
406 '((sh eval sh-mode-syntax-table ()
d5eeca7cdaf2 (sh-mode-syntax-table): Turn on comment syntax for #,
Richard M. Stallman <rms@gnu.org>
parents: 16533
diff changeset
407 ?\# "<"
d5eeca7cdaf2 (sh-mode-syntax-table): Turn on comment syntax for #,
Richard M. Stallman <rms@gnu.org>
parents: 16533
diff changeset
408 ?\^l ">#"
d5eeca7cdaf2 (sh-mode-syntax-table): Turn on comment syntax for #,
Richard M. Stallman <rms@gnu.org>
parents: 16533
diff changeset
409 ?\n ">#"
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
410 ?\" "\"\""
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
411 ?\' "\"'"
16535
d5eeca7cdaf2 (sh-mode-syntax-table): Turn on comment syntax for #,
Richard M. Stallman <rms@gnu.org>
parents: 16533
diff changeset
412 ?\` "\"`"
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
413 ?! "_"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
414 ?% "_"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
415 ?: "_"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
416 ?. "_"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
417 ?^ "_"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
418 ?~ "_")
16535
d5eeca7cdaf2 (sh-mode-syntax-table): Turn on comment syntax for #,
Richard M. Stallman <rms@gnu.org>
parents: 16533
diff changeset
419 (csh eval identity sh)
d5eeca7cdaf2 (sh-mode-syntax-table): Turn on comment syntax for #,
Richard M. Stallman <rms@gnu.org>
parents: 16533
diff changeset
420 (rc eval identity sh))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
421 "Syntax-table used in Shell-Script mode. See `sh-feature'.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (defvar sh-mode-map
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
426 (let ((map (make-sparse-keymap))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
427 (menu-map (make-sparse-keymap "Insert")))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (define-key map "\C-c(" 'sh-function)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (define-key map "\C-c\C-w" 'sh-while)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (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
431 (define-key map "\C-c\C-t" 'sh-tmp-file)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (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
433 (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
434 (define-key map "\C-c\C-o" 'sh-while-getopts)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (define-key map "\C-c\C-l" 'sh-indexed-loop)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (define-key map "\C-c\C-i" 'sh-if)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (define-key map "\C-c\C-f" 'sh-for)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (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
439 (define-key map "\C-c?" 'sh-show-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
440 (define-key map "\C-c=" 'sh-set-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
441 (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
442 (define-key map "\C-c>" 'sh-learn-buffer-indent)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
443
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (define-key map "=" 'sh-assignment)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (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
446 (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
447 (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
448 (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
449 (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
450 (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
451 (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
452 (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
453 (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
454 (define-key map "\"" 'skeleton-pair-insert-maybe)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
455 (define-key map ")" 'sh-electric-rparen)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
456 (define-key map "<" 'sh-electric-less)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
457 (define-key map "#" 'sh-electric-hash)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
458
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
459 (substitute-key-definition 'complete-tag 'comint-dynamic-complete
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 map (current-global-map))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (substitute-key-definition 'newline-and-indent 'sh-newline-and-indent
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 map (current-global-map))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (substitute-key-definition 'delete-backward-char
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 'backward-delete-char-untabify
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 map (current-global-map))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (define-key map "\C-c:" 'sh-set-shell)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (substitute-key-definition 'beginning-of-defun
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 'sh-beginning-of-compound-command
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 map (current-global-map))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (substitute-key-definition 'backward-sentence 'sh-beginning-of-command
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 map (current-global-map))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (substitute-key-definition 'forward-sentence 'sh-end-of-command
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 map (current-global-map))
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
474 (define-key map [menu-bar insert] (cons "Insert" menu-map))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
475 (define-key menu-map [sh-while] '("While Loop" . sh-while))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
476 (define-key menu-map [sh-until] '("Until Loop" . sh-until))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
477 (define-key menu-map [sh-tmp-file] '("Temporary File" . sh-tmp-file))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
478 (define-key menu-map [sh-select] '("Select Statement" . sh-select))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
479 (define-key menu-map [sh-repeat] '("Repeat Loop" . sh-repeat))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
480 (define-key menu-map [sh-while-getopts]
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
481 '("Options Loop" . sh-while-getopts))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
482 (define-key menu-map [sh-indexed-loop]
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
483 '("Indexed Loop" . sh-indexed-loop))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
484 (define-key menu-map [sh-if] '("If Statement" . sh-if))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
485 (define-key menu-map [sh-for] '("For Loop" . sh-for))
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
486 (define-key menu-map [sh-case] '("Case Statement" . sh-case))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 map)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 "Keymap used in Shell-Script mode.")
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
492 (defcustom sh-dynamic-complete-functions
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
493 '(shell-dynamic-complete-environment-variable
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
494 shell-dynamic-complete-command
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
495 comint-dynamic-complete-filename)
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
496 "*Functions for doing TAB dynamic completion."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
497 :type '(repeat function)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
498 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
501 (defcustom sh-require-final-newline
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
502 '((csh . t)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
503 (pdksh . t)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
504 (rc eval . require-final-newline)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
505 (sh eval . require-final-newline))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
506 "*Value of `require-final-newline' in Shell-Script mode buffers.
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
507 See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
508 :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
509 (choice (const :tag "require" t)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
510 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
511 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
512 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
513 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
516 (defcustom sh-assignment-regexp
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
517 '((csh . "\\<\\([a-zA-Z0-9_]+\\)\\(\\[.+\\]\\)?[ \t]*[-+*/%^]?=")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
518 ;; actually spaces are only supported in let/(( ... ))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
519 (ksh88 . "\\<\\([a-zA-Z0-9_]+\\)\\(\\[.+\\]\\)?[ \t]*\\([-+*/%&|~^]\\|<<\\|>>\\)?=")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
520 (rc . "\\<\\([a-zA-Z0-9_*]+\\)[ \t]*=")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
521 (sh . "\\<\\([a-zA-Z0-9_]+\\)="))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
522 "*Regexp for the variable name and what may follow in an assignment.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
523 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
524 sign. See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
525 :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
526 (choice regexp
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
527 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
528 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
529 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
530 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
533 (defcustom sh-indentation 4
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
534 "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
535 :type 'integer
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
536 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
539 (defcustom sh-remember-variable-min 3
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
540 "*Don't remember variables less than this length for completing reads."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
541 :type 'integer
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
542 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
545 (defvar sh-header-marker nil
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
546 "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
547 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
548
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
549
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
550 (defcustom sh-beginning-of-command
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
551 "\\([;({`|&]\\|\\`\\|[^\\]\n\\)[ \t]*\\([/~a-zA-Z0-9:]\\)"
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 "*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
553 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
554 :type 'regexp
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
555 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
557
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
558 (defcustom sh-end-of-command
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
559 "\\([/~a-zA-Z0-9:]\\)[ \t]*\\([;#)}`|&]\\|$\\)"
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 "*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
561 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
562 :type 'regexp
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
563 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
567 (defvar sh-here-document-word "EOF"
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 "Word to delimit here documents.")
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
570 (defvar sh-test
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
571 '((sh "[ ]" . 3)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
572 (ksh88 "[[ ]]" . 4))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
573 "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
574
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
576 ;; 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
577 ;; 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
578 (defcustom sh-builtins
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
579 '((bash eval sh-append posix
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
580 "alias" "bg" "bind" "builtin" "declare" "dirs" "enable" "fc" "fg"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
581 "help" "history" "jobs" "kill" "let" "local" "popd" "pushd" "source"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
582 "suspend" "typeset" "unalias")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
583
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
584 ;; 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
585 (bourne eval sh-append shell
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
586 "eval" "export" "getopts" "newgrp" "pwd" "read" "readonly"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
587 "times" "ulimit")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
588
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
589 (csh eval sh-append shell
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
590 "alias" "chdir" "glob" "history" "limit" "nice" "nohup" "rehash"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
591 "setenv" "source" "time" "unalias" "unhash")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
592
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
593 (dtksh eval identity wksh)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
594
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
595 (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
596 "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
597
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
598 (jsh eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
599 "bg" "fg" "jobs" "kill" "stop" "suspend")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
600
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
601 (jcsh eval sh-append csh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
602 "bg" "fg" "jobs" "kill" "notify" "stop" "suspend")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
603
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
604 (ksh88 eval sh-append bourne
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
605 "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
606 "typeset" "unalias" "whence")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
607
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
608 (oash eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
609 "checkwin" "dateline" "error" "form" "menu" "newwin" "oadeinit"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
610 "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
611 "wclear" "werase" "win" "wmclose" "wmmessage" "wmopen" "wmove"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
612 "wmtitle" "wrefresh")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
613
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
614 (pdksh eval sh-append ksh88
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
615 "bind")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
616
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
617 (posix eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
618 "command")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
619
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
620 (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
621 "whatis")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
622
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
623 (sh eval sh-append bourne
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
624 "hash" "test" "type")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
625
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
626 ;; 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
627 (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
628
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
629 (wksh eval sh-append ksh88
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
630 "Xt[A-Z][A-Za-z]*")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
631
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
632 (zsh eval sh-append ksh88
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
633 "autoload" "bindkey" "builtin" "chdir" "compctl" "declare" "dirs"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
634 "disable" "disown" "echotc" "enable" "functions" "getln" "hash"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
635 "history" "integer" "limit" "local" "log" "popd" "pushd" "r"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
636 "readonly" "rehash" "sched" "setopt" "source" "suspend" "true"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
637 "ttyctl" "type" "unfunction" "unhash" "unlimit" "unsetopt" "vared"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
638 "which"))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
639 "*List of all shell builtins for completing read and fontification.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
640 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
641 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
642 :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
643 (choice (repeat string)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
644 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
645 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
646 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
647 :group 'sh-script)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
648
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
649
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
650
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
651 (defcustom sh-leading-keywords
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
652 '((csh "else")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
653
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
654 (es "true" "unwind-protect" "whatis")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
655
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
656 (rc "else")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
657
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
658 (sh "do" "elif" "else" "if" "then" "trap" "type" "until" "while"))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
659 "*List of keywords that may be immediately followed by a builtin or keyword.
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
660 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
661 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
662 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
663 :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
664 (choice (repeat string)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
665 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
666 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
667 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
668 :group 'sh-script)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
669
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
670
17407
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
671 (defcustom sh-other-keywords
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
672 '((bash eval sh-append bourne
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
673 "bye" "logout")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
674
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
675 ;; The next entry is only used for defining the others
16810
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
676 (bourne eval sh-append sh
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
677 "function")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
678
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
679 (csh eval sh-append shell
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
680 "breaksw" "default" "end" "endif" "endsw" "foreach" "goto"
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
681 "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
682
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
683 (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
684 "return" "throw" "while")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
685
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
686 (ksh88 eval sh-append bourne
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
687 "select")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
688
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
689 (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
690 "while")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
691
16810
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
692 (sh eval sh-append shell
20dc495230a0 (sh-shell-file): On MSDOS, collapse $SHELL to lower
Richard M. Stallman <rms@gnu.org>
parents: 16552
diff changeset
693 "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
694
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
695 ;; 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
696 (shell "break" "case" "continue" "exec" "exit")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
697
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
698 (zsh eval sh-append bash
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
699 "select"))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
700 "*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
701 See `sh-feature'."
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
702 :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
703 (choice (repeat string)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
704 (cons :format "Evaluate: %v"
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
705 (const :format "" eval)
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
706 sexp))))
ae0ba78d6c07 Add defgroup's; change use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 17356
diff changeset
707 :group 'sh-script)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
711 (defvar sh-variables
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
712 '((bash eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
713 "allow_null_glob_expansion" "auto_resume" "BASH" "BASH_VERSION"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
714 "cdable_vars" "ENV" "EUID" "FCEDIT" "FIGNORE" "glob_dot_filenames"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
715 "histchars" "HISTFILE" "HISTFILESIZE" "history_control" "HISTSIZE"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
716 "hostname_completion_file" "HOSTTYPE" "IGNOREEOF" "ignoreeof"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
717 "LINENO" "MAIL_WARNING" "noclobber" "nolinks" "notify"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
718 "no_exit_on_failed_exec" "NO_PROMPT_VARS" "OLDPWD" "OPTERR" "PPID"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
719 "PROMPT_COMMAND" "PS4" "pushd_silent" "PWD" "RANDOM" "REPLY"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
720 "SECONDS" "SHLVL" "TMOUT" "UID")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
721
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
722 (csh eval sh-append shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
723 "argv" "cdpath" "child" "echo" "histchars" "history" "home"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
724 "ignoreeof" "mail" "noclobber" "noglob" "nonomatch" "path" "prompt"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
725 "shell" "status" "time" "verbose")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
726
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
727 (es eval sh-append shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
728 "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
729 "pid" "prompt" "signals")
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 (jcsh eval sh-append csh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
732 "notify")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
733
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
734 (ksh88 eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
735 "ENV" "ERRNO" "FCEDIT" "FPATH" "HISTFILE" "HISTSIZE" "LINENO"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
736 "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
737 "TMOUT")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
738
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
739 (oash eval sh-append sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
740 "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
741
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
742 (rc eval sh-append shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
743 "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
744 "prompt" "status")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
745
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
746 (sh eval sh-append shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
747 "CDPATH" "IFS" "OPTARG" "OPTIND" "PS1" "PS2")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
748
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
749 ;; 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
750 (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
751 "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
752 "LINES" "LOGNAME" "MAIL" "MAILCHECK" "MAILPATH" "PAGER" "PATH"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
753 "SHELL" "TERM" "TERMCAP" "TERMINFO" "VISUAL")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
754
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
755 (tcsh eval sh-append csh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
756 "addsuffix" "ampm" "autocorrect" "autoexpand" "autolist"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
757 "autologout" "chase_symlinks" "correct" "dextract" "edit" "el"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
758 "fignore" "gid" "histlit" "HOST" "HOSTTYPE" "HPATH"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
759 "ignore_symlinks" "listjobs" "listlinks" "listmax" "matchbeep"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
760 "nobeep" "NOREBIND" "oid" "printexitvalue" "prompt2" "prompt3"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
761 "pushdsilent" "pushdtohome" "recexact" "recognize_only_executables"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
762 "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
763 "tperiod" "tty" "uid" "version" "visiblebell" "watch" "who"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
764 "wordchars")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
765
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
766 (zsh eval sh-append ksh88
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
767 "BAUD" "bindcmds" "cdpath" "DIRSTACKSIZE" "fignore" "FIGNORE" "fpath"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
768 "HISTCHARS" "hostcmds" "hosts" "HOSTS" "LISTMAX" "LITHISTSIZE"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
769 "LOGCHECK" "mailpath" "manpath" "NULLCMD" "optcmds" "path" "POSTEDIT"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
770 "prompt" "PROMPT" "PROMPT2" "PROMPT3" "PROMPT4" "psvar" "PSVAR"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
771 "READNULLCMD" "REPORTTIME" "RPROMPT" "RPS1" "SAVEHIST" "SPROMPT"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
772 "STTY" "TIMEFMT" "TMOUT" "TMPPREFIX" "varcmds" "watch" "WATCH"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
773 "WATCHFMT" "WORDCHARS" "ZDOTDIR"))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
774 "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
775 See `sh-feature'.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
779 (defvar sh-font-lock-keywords
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
780 '((csh eval sh-append shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
781 '("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
782 font-lock-variable-name-face))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
783
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
784 (es eval sh-append executable-font-lock-keywords
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
785 '("\\$#?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\)" 1
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
786 font-lock-variable-name-face))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
788 (rc eval identity es)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
790 (sh eval sh-append shell
20900
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
791 ;; Variable names.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
792 '("\\$\\({#?\\)?\\([A-Za-z_][A-Za-z0-9_]*\\|[-#?@!]\\)" 2
20900
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
793 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
794 ;; Function names.
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
795 '("^\\(\\sw+\\)[ \t]*(" 1 font-lock-function-name-face)
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
796 '("\\<\\(function\\)\\>[ \t]*\\(\\sw+\\)?"
bab0b53038ee (sh-font-lock-keywords): Fontify sh-style function names in declarations.
Richard M. Stallman <rms@gnu.org>
parents: 20886
diff changeset
797 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
799 ;; 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
800 (shell eval sh-append executable-font-lock-keywords
14849
e36c046e28b1 (sh-font-lock-keywords): Highlight \ only with non-alphanumeric char.
Richard M. Stallman <rms@gnu.org>
parents: 14418
diff changeset
801 '("\\\\[^A-Za-z0-9]" 0 font-lock-string-face)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
802 '("\\${?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\|[$*_]\\)" 1
23501
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
803 font-lock-variable-name-face))
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
804 (rpm eval sh-append rpm2
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
805 '("%{?\\(\\sw+\\)" 1 font-lock-keyword-face))
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
806 (rpm2 eval sh-append shell
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
807 '("^\\(\\sw+\\):" 1 font-lock-variable-name-face)))
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
808 "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
809
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
810 (defvar sh-font-lock-keywords-1
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
811 '((sh "[ \t]in\\>"))
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
812 "Subdued level highlighting for Shell Script modes.")
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
813
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
814 (defvar sh-font-lock-keywords-2 ()
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
815 "Gaudy level highlighting for Shell Script modes.")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
817 (defconst sh-font-lock-syntactic-keywords
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
818 ;; Mark a `#' character as having punctuation syntax in a variable reference.
20420
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
819 ;; Really we should do this properly. From Chet Ramey and Brian Fox:
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
820 ;; "A `#' begins a comment when it is unquoted and at the beginning of a
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
821 ;; word. In the shell, words are separated by metacharacters."
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
822 ;; To do this in a regexp would be slow as it would be anchored to the right.
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
823 ;; But I can't be bothered to write a function to do it properly and
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
824 ;; efficiently. So we only do it properly for `#' in variable references and
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
825 ;; do it efficiently by anchoring the regexp to the left.
6cb3b9732db5 Deal with `#'s in variable references.
Simon Marshall <simon@gnu.org>
parents: 20395
diff changeset
826 '(("\\${?[^}#\n\t ]*\\(##?\\)" 1 (1 . nil))))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
827
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
828 (defgroup sh-indentation nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
829 "Variables controlling indentation in shell scripts.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
830
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
831 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
832 `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
833 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
834 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
835 :group 'sh-script)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
836
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
837
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
838 (defcustom sh-set-shell-hook nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
839 "*Hook run by `sh-set-shell'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
840 :type 'hook
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
841 :group 'sh-script)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
842
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
843 (defcustom sh-mode-hook nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
844 "*Hook run by `sh-mode'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
845 :type 'hook
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
846 :group 'sh-script)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
847
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
848 (defcustom sh-learn-basic-offset nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
849 "*When `sh-guess-basic-offset' should learn `sh-basic-offset'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
850
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
851 nil mean: never.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
852 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
853 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
854 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
855 (const :tag "Never" nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
856 (const :tag "Only if sure" t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
857 (const :tag "If have a good guess" usually)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
858 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
859 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
860
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
861 (defcustom sh-popup-occur-buffer nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
862 "*Controls when `sh-learn-buffer-indent' poos the *indent* buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
863 If t it is always shown. If nil, it is shown only when there
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
864 are conflicts."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
865 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
866 (const :tag "Only when there are conflicts." nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
867 (const :tag "Always" t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
868 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
869 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
870
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
871 (defcustom sh-blink t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
872 "*If non-nil, `sh-show-indent' shows the line indentation is relative to.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
873 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
874 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
875 always the case."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
876 :type 'boolean
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
877 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
878
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
879 (defcustom sh-first-lines-indent 0
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
880 "*The indentation of the first non-blank non-comment line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
881 Usually 0 meaning first column.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
882 Can be set to a number, or to nil which means leave it as is."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
883 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
884 (const :tag "Leave as is" nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
885 (integer :tag "Column number"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
886 :menu-tag "Indent to this col (0 means first col)" )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
887 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
888 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
889
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
890
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
891 (defcustom sh-basic-offset 4
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
892 "*The default indentation incrementation.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
893 This value is used for the + and - symbols in an indentation variable."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
894 :type 'integer
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
895 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
896
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
897 (defcustom sh-indent-comment nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
898 "*How a comment line is to be indented.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
899 nil means leave it as it is;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
900 t means indent it as a normal line, aligning it to previous non-blank
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
901 non-comment line;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
902 a number means align to that column, e.g. 0 means fist column."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
903 :type '(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
904 (const :tag "Leave as is." nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
905 (const :tag "Indent as a normal line." t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
906 (integer :menu-tag "Indent to this col (0 means first col)."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
907 :tag "Indent to column number.") )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
908 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
909
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
910
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
911 (defvar sh-debug nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
912 "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
913
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
914
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
915 ;; 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
916 ;; (defun sh-debug (&rest args)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
917 ;; "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
918 ;; (if sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
919 ;; (apply 'message args)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
920 (defmacro sh-debug (&rest args))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
921
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
922 (setq sh-symbol-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
923 '(
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
924 (const :tag "+ " :value +
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
925 :menu-tag "+ Indent right by sh-basic-offset")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
926 (const :tag "- " :value -
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
927 :menu-tag "- Indent left by sh-basic-offset")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
928 (const :tag "++" :value ++
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
929 :menu-tag "++ Indent right twice sh-basic-offset")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
930 (const :tag "--" :value --
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
931 :menu-tag "-- Indent left twice sh-basic-offset")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
932 (const :tag "* " :value *
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
933 :menu-tag "* Indent right half sh-basic-offset")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
934 (const :tag "/ " :value /
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
935 :menu-tag "/ Indent left half sh-basic-offset")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
936 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
937
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
938 (defcustom sh-indent-for-else 0
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
939 "*How much to indent an else relative to an if. Usually 0."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
940 :type `(choice
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
941 (integer :menu-tag "A number (positive=>indent right)"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
942 :tag "A number")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
943 (const :tag "--") ;; separator!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
944 ,@ sh-symbol-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
945 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
946 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
947
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
948 (setq sh-number-or-symbol-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
949 (append (list '(
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
950 integer :menu-tag "A number (positive=>indent right)"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
951 :tag "A number")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
952 '(const :tag "--") ;; separator
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
953 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
954 sh-symbol-list))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
955
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
956 (defcustom sh-indent-for-fi 0
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
957 "*How much to indent a fi relative to an if. Usually 0."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
958 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
959 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
960
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
961 (defcustom sh-indent-for-done '0
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
962 "*How much to indent a done relative to its matching stmt. Usually 0."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
963 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
964 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
965
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
966 (defcustom sh-indent-after-else '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
967 "*How much to indent a statement after an else statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
968 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
969 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
970
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
971 (defcustom sh-indent-after-if '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
972 "*How much to indent a statement after an if statement.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
973 This includes lines after else and elif statements, too, but
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
974 does not affect then else elif or fi statements themselves."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
975 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
976 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
977
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
978 (defcustom sh-indent-for-then '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
979 "*How much to indent an then relative to an if."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
980 :type `(choice ,@ sh-number-or-symbol-list )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
981 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
982
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
983 (defcustom sh-indent-for-do '*
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
984 "*How much to indent a do statement.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
985 This is relative to the statement before the do, i.e. the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
986 while until or for statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
987 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
988 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
989
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
990 (defcustom sh-indent-after-do '*
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
991 "*How much to indent a line after a do statement.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
992 This is used when the do is the first word of the line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
993 This is relative to the statement before the do, e.g. a
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
994 while for repeat or select statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
995 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
996 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
997
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
998 (defcustom sh-indent-after-loop-construct '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
999 "*How much to indent a statement after a loop construct.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1000
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1001 This variable is used when the keyword \"do\" is on the same line as the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1002 loop statement (e.g. \"until\", \"while\" or \"for\").
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1003 If the do is on a line by itself, then `sh-indent-after-do' is used instead."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1004 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1005 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1006
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1007
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1008 (defcustom sh-indent-after-done 0
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1009 "*How much to indent a statement after a \"done\" keyword.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1010 Normally this is 0, which aligns the \"done\" to the matching
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1011 looping construct line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1012 Setting it non-zero allows you to have the \"do\" statement on a line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1013 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
1014 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1015 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1016
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1017 (defcustom sh-indent-for-case-label '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1018 "*How much to indent a case label statement.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1019 This is relative to the line containing the case statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1020 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1021 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1022
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1023 (defcustom sh-indent-for-case-alt '++
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1024 "*How much to indent statements after the case label.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1025 This is relative to the line containing the case statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1026 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1027 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1028
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1029
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1030 (defcustom sh-indent-for-continuation '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1031 "*How much to indent for a continuation statement."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1032 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1033 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1034
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1035 (defcustom sh-indent-after-open '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1036 "*How much to indent after a line with an opening parenthesis or brace.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1037 For an open paren after a function `sh-indent-after-function' is used."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1038 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1039 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1040
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1041 (defcustom sh-indent-after-function '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1042 "*How much to indent after a function line."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1043 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1044 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1045
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1046 ;; These 2 are for the rc shell:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1047
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1048 (defcustom sh-indent-after-switch '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1049 "*How much to indent a case statement relative to the switch statement.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1050 This is for the rc shell."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1051 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1052 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1053
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1054 (defcustom sh-indent-after-case '+
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1055 "*How much to indent a statement relative to the case statement.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1056 This is for the rc shell."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1057 :type `(choice ,@ sh-number-or-symbol-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1058 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1059
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1060 (defface sh-heredoc-face
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1061 '((((class color)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1062 (background dark))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1063 (:foreground "yellow" :bold t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1064 (((class color)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1065 (background light))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1066 (:foreground "tan" ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1067 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1068 (:bold t)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1069 "Face to show a here-document"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1070 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1071
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1072 (defface sh-st-face
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1073 '((((class color)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1074 (background dark))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1075 (:foreground "yellow" :bold t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1076 (((class color)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1077 (background light))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1078 (:foreground "tan" ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1079 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1080 (:bold t)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1081 "Face to show characters with special syntax properties."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1082 :group 'sh-indentation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1083
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1084
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1085 ;; 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
1086
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1087 ;; These are used for the syntax table stuff (derived from cperl-mode).
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1088 ;; Note: parse-sexp-lookup-properties must be set to t for it to work.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1089 (defconst sh-here-doc-syntax '(15)) ;; generic string
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1090 (defconst sh-st-punc '(1))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1091 (defconst sh-special-syntax sh-st-punc)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1092
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1093 (defun sh-mkword-regexpr (word)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1094 "Make a regexp which matches WORD as a word.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1095 This specifically excludes an occurance of WORD followed by
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1096 punctuation characters like '-'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1097 (concat word "\\([^-a-z0-9_]\\|$\\)"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1098
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1099 (defun sh-mkword-regexp (word)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1100 "Make a regexp which matches WORD as a word.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1101 This specifically excludes an occurance of WORD followed by
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1102 or preceded by punctuation characters like '-'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1103 (concat "\\(^\\|[^-a-z0-9_]\\)" word "\\([^-a-z0-9_]\\|$\\)"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1104
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1105 (setq sh-re-done (sh-mkword-regexpr "done"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1106
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1107
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1108 (defconst sh-kws-for-done
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1109 '(
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1110 (sh . ( "while" "until" "for" ) )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1111 (bash . ( "while" "until" "for" "select" ) )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1112 (ksh88 . ( "while" "until" "for" "select" ) )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1113 (zsh . ( "while" "until" "for" "repeat" "select" ) )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1114 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1115 "Which keywords can match the word `done' in this shell."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1116 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1117
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1118
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1119 (defconst sh-indent-supported
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1120 '(
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1121 (sh . t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1122 (csh . nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1123 (rc . t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1124 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1125 "Shell types that shell indenting can do something with."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1126 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1127
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1128 (defconst sh-electric-rparen-needed
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1129 '(
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1130 (sh . t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1131 "Non-nil if the shell type needs an electric handling of case alternatives."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1132 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1133
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1134 (defconst sh-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1135 '(
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1136 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
1137 sh-indent-after-do sh-indent-after-done
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1138 sh-indent-after-else
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1139 sh-indent-after-if
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1140 sh-indent-after-loop-construct
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1141 sh-indent-after-open
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1142 sh-indent-comment
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1143 sh-indent-for-case-alt
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1144 sh-indent-for-case-label
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1145 sh-indent-for-continuation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1146 sh-indent-for-do
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1147 sh-indent-for-done
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1148 sh-indent-for-else
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1149 sh-indent-for-fi
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1150 sh-indent-for-then
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1151 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1152 "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
1153 This list is used when switching between buffer-local and global
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1154 values of variables, and for the commands using indenation styles.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1155
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1156 (defvar sh-make-vars-local t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1157 "*Controls whether indentation variables are local to the buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1158 If non-nil, indentation variables are made local initially.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1159 If nil, you can later make the variables local by invoking
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1160 command `sh-make-vars-local'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1161 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
1162 frequently editing existing scripts with different styles.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1163
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1164
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1165 ;; mode-command and utility functions
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1166
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1167 ;;;###autoload
14195
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
1168 (put 'sh-mode 'mode-class 'special)
14221
cd28284abca4 (sh-mode): Add autoload cookie.
Erik Naggum <erik@naggum.no>
parents: 14211
diff changeset
1169
cd28284abca4 (sh-mode): Add autoload cookie.
Erik Naggum <erik@naggum.no>
parents: 14211
diff changeset
1170 ;;;###autoload
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171 (defun sh-mode ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1172 "Major mode for editing shell scripts.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1173 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
1174 as far as commands, arguments, variables, pipes, comments etc. are concerned.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1175 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
1176 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
1177
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1178 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
1179 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
1180 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
1181 shell-specific features.
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1182
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1183 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
1184 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
1185 following commands are available, based on the current shell's syntax:
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1186
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1187 \\[sh-case] case statement
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1188 \\[sh-for] for loop
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1189 \\[sh-function] function definition
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1190 \\[sh-if] if statement
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1191 \\[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
1192 \\[sh-while-getopts] while getopts loop
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1193 \\[sh-repeat] repeat loop
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1194 \\[sh-select] select loop
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1195 \\[sh-until] until loop
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1196 \\[sh-while] while loop
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1197
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1198 For sh and rc shells indentation commands are:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1199 \\[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
1200 \\[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
1201 \\[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
1202 would indent to the way it currently is.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1203 \\[sh-learn-buffer-indent] Set the indentation variables so the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1204 buffer indents as it currently is indendeted.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1205
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1206
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1207 \\[backward-delete-char-untabify] Delete backward one position, even if it was a tab.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1208 \\[sh-newline-and-indent] Delete unquoted space and indent new line same as this one.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1209 \\[sh-end-of-command] Go to end of successive commands.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1210 \\[sh-beginning-of-command] Go to beginning of successive commands.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1211 \\[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
1212 \\[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
1213
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1214 \\[sh-maybe-here-document] Without prefix, following an unquoted < inserts here document.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1215 {, (, [, ', \", `
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1216 Unless quoted with \\, insert the pairs {}, (), [], or '', \"\", ``.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1217
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1218 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
1219 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
1220 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
1221
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1222 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
1223 with your script for an edit-interpret-debug cycle."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 (interactive)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 (kill-all-local-variables)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 (use-local-map sh-mode-map)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1227 (make-local-variable 'indent-line-function)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1228 (make-local-variable 'indent-region-function)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1229 (make-local-variable 'skeleton-end-hook)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1230 (make-local-variable 'paragraph-start)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1231 (make-local-variable 'paragraph-separate)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1232 (make-local-variable 'comment-start)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1233 (make-local-variable 'comment-start-skip)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1234 (make-local-variable 'require-final-newline)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1235 (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
1236 (make-local-variable 'sh-shell-file)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1237 (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
1238 (make-local-variable 'skeleton-pair-alist)
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
1239 (make-local-variable 'skeleton-pair-filter)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1240 (make-local-variable 'comint-dynamic-complete-functions)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1241 (make-local-variable 'comint-prompt-regexp)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1242 (make-local-variable 'font-lock-defaults)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1243 (make-local-variable 'skeleton-filter)
12887
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
1244 (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
1245 (make-local-variable 'sh-shell-variables)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
1246 (make-local-variable 'sh-shell-variables-initialized)
20395
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
1247 (make-local-variable 'imenu-generic-expression)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1248 (make-local-variable 'sh-electric-rparen-needed-here)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1249 (make-local-variable 'sh-indent-supported-here)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1250 (setq major-mode 'sh-mode
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1251 mode-name "Shell-script"
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1252 ;; not very clever, but enables wrapping skeletons around regions
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1253 indent-region-function (lambda (b e)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1254 (save-excursion
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1255 (goto-char b)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1256 (skip-syntax-backward "-")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1257 (setq b (point))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1258 (goto-char e)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1259 (skip-syntax-backward "-")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1260 (indent-rigidly b (point) sh-indentation)))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1261 skeleton-end-hook (lambda ()
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1262 (or (eolp) (newline) (indent-relative)))
13705
4111cc3136d1 (sh-mode-map): Make the code more legible.
Karl Heuer <kwzh@gnu.org>
parents: 13510
diff changeset
1263 paragraph-start (concat page-delimiter "\\|$")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1264 paragraph-separate paragraph-start
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1265 comment-start "# "
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1266 comint-dynamic-complete-functions sh-dynamic-complete-functions
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1267 ;; we can't look if previous line ended with `\'
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1268 comint-prompt-regexp "^[ \t]*"
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1269 font-lock-defaults
18024
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
1270 '((sh-font-lock-keywords
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
1271 sh-font-lock-keywords-1 sh-font-lock-keywords-2)
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
1272 nil nil
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
1273 ((?/ . "w") (?~ . "w") (?. . "w") (?- . "w") (?_ . "w")) nil
58afe194f1bd Update for syntax-table text properties.
Simon Marshall <simon@gnu.org>
parents: 17531
diff changeset
1274 (font-lock-syntactic-keywords . sh-font-lock-syntactic-keywords))
12864
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
1275 skeleton-pair-alist '((?` _ ?`))
3b9dcd964c66 (sh-mode-map): Use new name skeleton-pair-insert-maybe.
Karl Heuer <kwzh@gnu.org>
parents: 12863
diff changeset
1276 skeleton-pair-filter 'sh-quoted-p
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1277 skeleton-further-elements '((< '(- (min sh-indentation
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1278 (current-column)))))
12887
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
1279 skeleton-filter 'sh-feature
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1280 skeleton-newline-indent-rigidly t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1281 sh-electric-rparen-needed-here nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1282 sh-indent-supported-here nil)
22783
1fb9133a2851 (sh-mode): parse-sexp-ignore-comments = t.
Richard M. Stallman <rms@gnu.org>
parents: 21980
diff changeset
1283 (make-local-variable 'parse-sexp-ignore-comments)
1fb9133a2851 (sh-mode): parse-sexp-ignore-comments = t.
Richard M. Stallman <rms@gnu.org>
parents: 21980
diff changeset
1284 (setq 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
1285 ;; 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
1286 ;; on the shell thus determined.
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1287 (let ((interpreter
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1288 (save-excursion
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1289 (goto-char (point-min))
23501
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
1290 (cond ((looking-at "#![ \t]?\\([^ \t\n]*/bin/env[ \t]\\)?\\([^ \t\n]+\\)")
24730
e1cb8de8ffb2 (sh-mode): Do not fail if buffer has no
Karl Heuer <kwzh@gnu.org>
parents: 23869
diff changeset
1291 (match-string 2))
e1cb8de8ffb2 (sh-mode): Do not fail if buffer has no
Karl Heuer <kwzh@gnu.org>
parents: 23869
diff changeset
1292 ((and buffer-file-name
e1cb8de8ffb2 (sh-mode): Do not fail if buffer has no
Karl Heuer <kwzh@gnu.org>
parents: 23869
diff changeset
1293 (string-match "\\.m?spec$" buffer-file-name))
23501
f12ae4499ae0 (sh-mode): Handle .spec and .mspec files.
Richard M. Stallman <rms@gnu.org>
parents: 23341
diff changeset
1294 "rpm")))))
16552
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1295 (if interpreter
17260
e32d514a22cc (sh-set-shell): If file has no #! line,
Richard M. Stallman <rms@gnu.org>
parents: 17213
diff changeset
1296 (sh-set-shell interpreter nil nil)
20385
e1ea41eba8be (sh-mode): Set `comment-start-skip' always.
Dave Love <fx@gnu.org>
parents: 19578
diff changeset
1297 (progn
e1ea41eba8be (sh-mode): Set `comment-start-skip' always.
Dave Love <fx@gnu.org>
parents: 19578
diff changeset
1298 ;; If we don't know the shell for this file, set the syntax
e1ea41eba8be (sh-mode): Set `comment-start-skip' always.
Dave Love <fx@gnu.org>
parents: 19578
diff changeset
1299 ;; table anyway, for the user's normal choice of shell.
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1300 (set-syntax-table (sh-feature sh-mode-syntax-table))
20385
e1ea41eba8be (sh-mode): Set `comment-start-skip' always.
Dave Love <fx@gnu.org>
parents: 19578
diff changeset
1301 ;; And avoid indent-new-comment-line (at least) losing.
e1ea41eba8be (sh-mode): Set `comment-start-skip' always.
Dave Love <fx@gnu.org>
parents: 19578
diff changeset
1302 (setq comment-start-skip "#+[\t ]*"))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1303 (run-hooks 'sh-mode-hook))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1304 ;;;###autoload
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1305 (defalias 'shell-script-mode 'sh-mode)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1306
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1307
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1308 (defun sh-font-lock-keywords (&optional keywords)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1309 "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
1310 This adds rules for comments and assignments."
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1311 (sh-feature sh-font-lock-keywords
23511
8b4cdcbaf071 (sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents: 23501
diff changeset
1312 (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
1313 (lambda (list)
8b4cdcbaf071 (sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents: 23501
diff changeset
1314 `((,(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
1315 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
1316 ,@keywords
8b4cdcbaf071 (sh-font-lock-keywords): Don't crash for an unrecognized shell.
Richard M. Stallman <rms@gnu.org>
parents: 23501
diff changeset
1317 ,@list)))))
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1318
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1319 (defun sh-font-lock-keywords-1 (&optional builtins)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1320 "Function to get better fontification including keywords."
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1321 (let ((keywords (concat "\\([;(){}`|&]\\|^\\)[ \t]*\\(\\(\\("
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1322 (mapconcat 'identity
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1323 (sh-feature sh-leading-keywords)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1324 "\\|")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1325 "\\)[ \t]+\\)?\\("
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1326 (mapconcat 'identity
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1327 (append (sh-feature sh-leading-keywords)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1328 (sh-feature sh-other-keywords))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1329 "\\|")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1330 "\\)")))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1331 (sh-font-lock-keywords
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1332 `(,@(if builtins
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1333 `((,(concat keywords "[ \t]+\\)?\\("
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1334 (mapconcat 'identity (sh-feature sh-builtins) "\\|")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1335 "\\)\\>")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1336 (2 font-lock-keyword-face nil t)
16478
fb944e4dc708 Use new face.
Simon Marshall <simon@gnu.org>
parents: 16468
diff changeset
1337 (6 font-lock-builtin-face))
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1338 ,@(sh-feature sh-font-lock-keywords-2)))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1339 (,(concat keywords "\\)\\>")
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1340 2 font-lock-keyword-face)
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1341 ,@(sh-feature sh-font-lock-keywords-1)))))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1342
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1343 (defun sh-font-lock-keywords-2 ()
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1344 "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
1345 (sh-font-lock-keywords-1 t))
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1346
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1347
14148
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1348 (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
1349 "Set this buffer's shell to SHELL (a string).
16552
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1350 Makes this script executable via `executable-set-magic', and sets up the
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1351 proper starting #!-line, if INSERT-FLAG is non-nil.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1352 Calls the value of `sh-set-shell-hook' if set."
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1353 (interactive (list (completing-read "Name or path of shell: "
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
1354 interpreter-mode-alist
14148
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1355 (lambda (x) (eq (cdr x) 'sh-mode)))
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1356 (eq executable-query 'function)
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1357 t))
23589
660727693bf6 (sh-canonicalize-shell): Fix regexp.
Andreas Schwab <schwab@suse.de>
parents: 23511
diff changeset
1358 (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
1359 (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
1360 (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
1361 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
1362 sh-shell))
16552
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1363 (if insert-flag
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1364 (setq sh-shell-file
fe3d32bca2c5 (sh-set-shell): Pass args no-query-flag
Richard M. Stallman <rms@gnu.org>
parents: 16535
diff changeset
1365 (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
1366 no-query-flag insert-flag)))
14148
fa30f7528502 (sh-mode): Don't move point.
Richard M. Stallman <rms@gnu.org>
parents: 14119
diff changeset
1367 (setq require-final-newline (sh-feature sh-require-final-newline)
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1368 ;;; local-abbrev-table (sh-feature sh-abbrevs)
17356
9f345ed0683e (sh-mode): Set font-lock-comment-start-regexp via font-lock-defaults.
Richard M. Stallman <rms@gnu.org>
parents: 17260
diff changeset
1369 ;; Packages should not need to set these variables directly. sm.
9f345ed0683e (sh-mode): Set font-lock-comment-start-regexp via font-lock-defaults.
Richard M. Stallman <rms@gnu.org>
parents: 17260
diff changeset
1370 ; font-lock-keywords nil ; force resetting
9f345ed0683e (sh-mode): Set font-lock-comment-start-regexp via font-lock-defaults.
Richard M. Stallman <rms@gnu.org>
parents: 17260
diff changeset
1371 ; font-lock-syntax-table nil
16535
d5eeca7cdaf2 (sh-mode-syntax-table): Turn on comment syntax for #,
Richard M. Stallman <rms@gnu.org>
parents: 16533
diff changeset
1372 comment-start-skip "#+[\t ]*"
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1373 mode-line-process (format "[%s]" sh-shell)
14195
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
1374 sh-shell-variables nil
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
1375 sh-shell-variables-initialized nil
20395
2bd6621697d5 (sh-imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 20385
diff changeset
1376 imenu-generic-expression (sh-feature sh-imenu-generic-expression)
23341
d29b6b51866f (sh-set-shell): Remove .exe suffix from shell name.
Richard M. Stallman <rms@gnu.org>
parents: 22783
diff changeset
1377 imenu-case-fold-search nil)
20886
7aa1fdcd551a (sh-set-shell): Use standard-syntax-table if none other is specified.
Richard M. Stallman <rms@gnu.org>
parents: 20771
diff changeset
1378 (set-syntax-table (or (sh-feature sh-mode-syntax-table)
7aa1fdcd551a (sh-set-shell): Use standard-syntax-table if none other is specified.
Richard M. Stallman <rms@gnu.org>
parents: 20771
diff changeset
1379 (standard-syntax-table)))
23341
d29b6b51866f (sh-set-shell): Remove .exe suffix from shell name.
Richard M. Stallman <rms@gnu.org>
parents: 22783
diff changeset
1380 (let ((vars (sh-feature sh-variables)))
d29b6b51866f (sh-set-shell): Remove .exe suffix from shell name.
Richard M. Stallman <rms@gnu.org>
parents: 22783
diff changeset
1381 (while vars
d29b6b51866f (sh-set-shell): Remove .exe suffix from shell name.
Richard M. Stallman <rms@gnu.org>
parents: 22783
diff changeset
1382 (sh-remember-variable (car vars))
d29b6b51866f (sh-set-shell): Remove .exe suffix from shell name.
Richard M. Stallman <rms@gnu.org>
parents: 22783
diff changeset
1383 (setq vars (cdr vars))))
17356
9f345ed0683e (sh-mode): Set font-lock-comment-start-regexp via font-lock-defaults.
Richard M. Stallman <rms@gnu.org>
parents: 17260
diff changeset
1384 ;; Packages should not need to toggle Font Lock mode. sm.
9f345ed0683e (sh-mode): Set font-lock-comment-start-regexp via font-lock-defaults.
Richard M. Stallman <rms@gnu.org>
parents: 17260
diff changeset
1385 ; (and (boundp 'font-lock-mode)
9f345ed0683e (sh-mode): Set font-lock-comment-start-regexp via font-lock-defaults.
Richard M. Stallman <rms@gnu.org>
parents: 17260
diff changeset
1386 ; font-lock-mode
9f345ed0683e (sh-mode): Set font-lock-comment-start-regexp via font-lock-defaults.
Richard M. Stallman <rms@gnu.org>
parents: 17260
diff changeset
1387 ; (font-lock-mode (font-lock-mode 0)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1388 (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
1389 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1390 (message "Setting up indent for shell type %s" sh-shell)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1391 (make-local-variable 'sh-kw-alist)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1392 (make-local-variable 'sh-regexp-for-done)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1393 (make-local-variable 'parse-sexp-lookup-properties)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1394 (setq sh-electric-rparen-needed-here
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1395 (sh-feature sh-electric-rparen-needed))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1396 (setq parse-sexp-lookup-properties t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1397 (sh-scan-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1398 (setq sh-kw-alist (sh-feature sh-kw))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1399 (let ((regexp (sh-feature sh-kws-for-done)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1400 (if regexp
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1401 (setq sh-regexp-for-done
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1402 (sh-mkword-regexpr (regexp-opt regexp t)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1403 (message "setting up indent stuff")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1404 ;; 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
1405 ;; 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
1406 (make-local-variable 'indent-line-function)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1407 (setq indent-line-function 'sh-indent-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1408 ;; This is very inefficient, but this at least makes indent-region work:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1409 (make-local-variable 'indent-region-function)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1410 (setq indent-region-function nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1411 (if sh-make-vars-local
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1412 (sh-make-vars-local))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1413 (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
1414 (message "No indentation for this shell type.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1415 (setq indent-line-function 'sh-basic-indent-line))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1416 (run-hooks 'sh-set-shell-hook))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1417
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1418
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1419
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1420 (defun sh-feature (list &optional function)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1421 "Index ALIST by the current shell.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1422 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
1423 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
1424
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1425 - 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
1426 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
1427 The ultimate default is always `sh'.
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1428
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1429 - If the value thus looked up is a list starting with `eval' its `cdr' is
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1430 first evaluated. If that is also a list and the first argument is a
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1431 symbol in ALIST it is not evaluated, but rather recursively looked up in
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1432 ALIST to allow the function called to define the value for one shell to be
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1433 derived from another shell. While calling the function, is the car of the
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1434 alist element is the current shell.
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1435 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
1436
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1437 Optional FUNCTION is applied to the determined value and the result is cached
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1438 in ALIST."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1439 (or (if (consp list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1440 (let ((l list))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1441 (while (and l (consp (car l)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1442 (setq l (cdr l)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1443 (if l list)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1444 (if function
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1445 (cdr (assoc (setq function (cons sh-shell function)) list)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1446 (let ((sh-shell sh-shell)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1447 elt val)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1448 (while (and sh-shell
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1449 (not (setq elt (assq sh-shell list))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1450 (setq sh-shell (cdr (assq sh-shell sh-ancestor-alist))))
24906
01882044b37a (sh-feature): If nothing is known about the given shell, use the
Richard M. Stallman <rms@gnu.org>
parents: 24899
diff changeset
1451 ;; If the shell is not known, treat it as sh.
01882044b37a (sh-feature): If nothing is known about the given shell, use the
Richard M. Stallman <rms@gnu.org>
parents: 24899
diff changeset
1452 (unless elt
01882044b37a (sh-feature): If nothing is known about the given shell, use the
Richard M. Stallman <rms@gnu.org>
parents: 24899
diff changeset
1453 (setq elt (assq 'sh list)))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1454 (if (and (consp (setq val (cdr elt)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1455 (eq (car val) 'eval))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1456 (setcdr elt
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1457 (setq val
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1458 (eval (if (consp (setq val (cdr val)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1459 (let ((sh-shell (car (cdr val)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1460 function)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1461 (if (assq sh-shell list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1462 (setcar (cdr val)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1463 (list 'quote
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1464 (sh-feature list))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1465 val)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1466 val)))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1467 (if function
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1468 (nconc list
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1469 (list (cons function
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1470 (setq sh-shell (car function)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1471 val (funcall (cdr function) val))))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1472 val)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1473
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1474
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1475
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1476 ;;; I commented this out because nobody calls it -- rms.
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1477 ;;;(defun sh-abbrevs (ancestor &rest list)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1478 ;;; "Iff it isn't, define the current shell as abbrev table and fill that.
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1479 ;;;Abbrev table will inherit all abbrevs from ANCESTOR, which is either an abbrev
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1480 ;;;table or a list of (NAME1 EXPANSION1 ...). In addition it will define abbrevs
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1481 ;;;according to the remaining arguments NAMEi EXPANSIONi ...
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1482 ;;;EXPANSION may be either a string or a skeleton command."
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1483 ;;; (or (if (boundp sh-shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1484 ;;; (symbol-value sh-shell))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1485 ;;; (progn
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1486 ;;; (if (listp ancestor)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1487 ;;; (nconc list ancestor))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1488 ;;; (define-abbrev-table sh-shell ())
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1489 ;;; (if (vectorp ancestor)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1490 ;;; (mapatoms (lambda (atom)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1491 ;;; (or (eq atom 0)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1492 ;;; (define-abbrev (symbol-value sh-shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1493 ;;; (symbol-name atom)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1494 ;;; (symbol-value atom)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1495 ;;; (symbol-function atom))))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1496 ;;; ancestor))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1497 ;;; (while list
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1498 ;;; (define-abbrev (symbol-value sh-shell)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1499 ;;; (car list)
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1500 ;;; (if (stringp (car (cdr list)))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1501 ;;; (car (cdr list))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1502 ;;; "")
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1503 ;;; (if (symbolp (car (cdr list)))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1504 ;;; (car (cdr list))))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1505 ;;; (setq list (cdr (cdr list)))))
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1506 ;;; (symbol-value sh-shell)))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1507
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1508
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1509 (defun sh-mode-syntax-table (table &rest list)
14005
dd4a20edf654 (sh-mode-syntax-table): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 13707
diff changeset
1510 "Copy TABLE and set syntax for successive CHARs according to strings S."
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1511 (setq table (copy-syntax-table table))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1512 (while list
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1513 (modify-syntax-entry (car list) (car (cdr list)) table)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1514 (setq list (cdr (cdr list))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1515 table)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1516
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1517
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1518 (defun sh-append (ancestor &rest list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1519 "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
1520 (nconc list ancestor))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1521
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1522
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1523 (defun sh-modify (skeleton &rest list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1524 "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
1525 (setq skeleton (copy-sequence skeleton))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1526 (while list
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1527 (setcar (or (nthcdr (car list) skeleton)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1528 (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
1529 (car (cdr list)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1530 (setq list (nthcdr 2 list)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1531 skeleton)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1532
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1533
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1534 (defun sh-basic-indent-line ()
19480
7f11f103a0ca (sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 18382
diff changeset
1535 "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
1536 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
1537 Lines containing only comments are considered empty."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1538 (interactive)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1539 (let ((previous (save-excursion
19480
7f11f103a0ca (sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 18382
diff changeset
1540 (while (and (progn (beginning-of-line)
7f11f103a0ca (sh-indent-line): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 18382
diff changeset
1541 (not (bobp)))
14211
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1542 (progn
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1543 (forward-line -1)
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1544 (back-to-indentation)
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1545 (or (eolp)
949aa01aca87 (sh-indent-line): Cope if no previous noncomment line.
Richard M. Stallman <rms@gnu.org>
parents: 14195
diff changeset
1546 (eq (following-char) ?#)))))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1547 (current-column)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1548 current)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1549 (save-excursion
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1550 (indent-to (if (eq this-command 'newline-and-indent)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1551 previous
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1552 (if (< (current-column)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1553 (setq current (progn (back-to-indentation)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1554 (current-column))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1555 (if (eolp) previous 0)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1556 (delete-region (point)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1557 (progn (beginning-of-line) (point)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1558 (if (eolp)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1559 (max previous (* (1+ (/ current sh-indentation))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1560 sh-indentation))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1561 (* (1+ (/ current sh-indentation)) sh-indentation))))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1562 (if (< (current-column) (current-indentation))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1563 (skip-chars-forward " \t"))))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1564
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1565
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1566 (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
1567 "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
1568 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
1569 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
1570
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1571 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
1572 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
1573 region, clear header."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1574 (interactive "r\nP")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1575 (if flag
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1576 (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
1577 (point-marker)))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1578 (if sh-header-marker
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1579 (save-excursion
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1580 (let (buffer-undo-list)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1581 (goto-char sh-header-marker)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1582 (append-to-buffer (current-buffer) start end)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1583 (shell-command-on-region (point-min)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1584 (setq end (+ sh-header-marker
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1585 (- end start)))
14119
2a05fc406f3a (sh-alias-alist): Don't map sh to bash.
Karl Heuer <kwzh@gnu.org>
parents: 14026
diff changeset
1586 sh-shell-file)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
1587 (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
1588 (shell-command-on-region start end (concat sh-shell-file " -")))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1589
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1590
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1591 (defun sh-remember-variable (var)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1592 "Make VARIABLE available for future completing reads in this buffer."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1593 (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
1594 (getenv var)
14195
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
1595 (assoc var sh-shell-variables)
df3c52ae5b14 (sh-shell-variables): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
1596 (setq sh-shell-variables (cons (cons var var) sh-shell-variables)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1597 var)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1598
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1599
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1600
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1601 (defun sh-quoted-p ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1602 "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
1603 (eq -1 (% (save-excursion (skip-chars-backward "\\\\")) 2)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1604
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1605 ;; Indentation stuff.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1606 (defun sh-must-be-shell-mode ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1607 "Signal an error if not in Shell-script mode."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1608 (unless (eq major-mode 'sh-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1609 (error "This buffer is not in Shell-script mode")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1610
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1611 (defun sh-must-support-indent ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1612 "*Signal an error if the shell type for this buffer is not supported.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1613 Also, the buffer must be in Shell-script mode."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1614 (sh-must-be-shell-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1615 (unless sh-indent-supported-here
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1616 (error "This buffer's shell type is not supported for this command")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1617
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1618 (defun sh-make-vars-local ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1619 "Make the indentation variables local to this buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1620 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
1621 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
1622
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1623 To revert all these variables to the global values, use
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1624 command `sh-reset-indent-vars-to-global-values'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1625 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1626 (sh-must-be-shell-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1627 (mapcar 'make-local-variable sh-var-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1628 (message "Indentation variable are now local."))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1629
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1630 (defun sh-reset-indent-vars-to-global-values ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1631 "Reset local indenatation variables to the global values.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1632 Then, if variable `sh-make-vars-local' is non-nil, make them local."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1633 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1634 (sh-must-be-shell-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1635 (mapcar 'kill-local-variable sh-var-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1636 (if sh-make-vars-local
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1637 (mapcar 'make-local-variable sh-var-list)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1638
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1639
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1640 (defvar sh-kw-alist nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1641 "A buffer-local, since it is shell-type dependent, list of keywords.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1642
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1643 (defvar sh-regexp-for-done nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1644 "A buffer-local regexp to match opening keyword for done.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1645
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1646 ;; 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
1647 ;; 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
1648 (defconst sh-special-keywords "then\\|do")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1649
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1650 ;; ( key-word first-on-this on-prev-line )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1651 ;; This is used to set `sh-kw-alist' which is a list of sublists each
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1652 ;; having 3 elements:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1653 ;; a keyword
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1654 ;; a rule to check when the keyword apepars on "this" line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1655 ;; a rule to check when the keyword apepars on "the previous" line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1656 ;; The keyword is usually a string and is the first word on a line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1657 ;; If this keyword appears on the line whose indenation is to be
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1658 ;; calculated, the rule in element 2 is called. If this returns
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1659 ;; non-zero, the resulting point (which may be changed by the rule)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1660 ;; is used as the default indentation.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1661 ;; If it returned false or the keyword was not found in the table,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1662 ;; then the keyword from the previous line is looked up and the rule
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1663 ;; in element 3 is called. In this case, however,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1664 ;; `sh-get-indent-info' does not stop but may keepp going and test
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1665 ;; other keywords against rules in element 3. This is because the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1666 ;; precending line could have, for example, an opening "if" and an
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1667 ;; opening "while" keyword and we need to add the indentation offsets
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1668 ;; for both.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1669 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1670 (defconst sh-kw
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1671 '(
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1672 (sh
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1673 ( "if"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1674 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1675 sh-handle-prev-if )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1676 ( "elif"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1677 sh-handle-this-else
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1678 sh-handle-prev-else )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1679 ( "else"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1680 sh-handle-this-else
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1681 sh-handle-prev-else )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1682 ( "fi"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1683 sh-handle-this-fi
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1684 sh-handle-prev-fi )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1685 ( "then"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1686 sh-handle-this-then
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1687 sh-handle-prev-then )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1688 ( "("
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1689 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1690 sh-handle-prev-open )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1691 ( "{"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1692 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1693 sh-handle-prev-open )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1694 ( "["
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1695 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1696 sh-handle-prev-open )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1697 ( "}"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1698 sh-handle-this-close
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1699 nil )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1700 ( ")"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1701 sh-handle-this-close
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1702 nil )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1703 ( "]"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1704 sh-handle-this-close
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1705 nil )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1706 ( "case"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1707 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1708 sh-handle-prev-case )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1709 ( "esac"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1710 sh-handle-this-esac
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1711 sh-handle-prev-esac )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1712 ( case-label
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1713 nil ;; ???
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1714 sh-handle-after-case-label )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1715 ( ";;"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1716 nil ;; ???
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1717 sh-handle-prev-case-alt-end ;; ??
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1718 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1719 ( "done"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1720 sh-handle-this-done
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1721 sh-handle-prev-done )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1722 ( "do"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1723 sh-handle-this-do
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1724 sh-handle-prev-do )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1725 ) ;; end of sh
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1726
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1727 ;; Note: we don't need specific stuff for bash and zsh shells;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1728 ;; the regexp `sh-regexp-for-done' handles the extra keywords
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1729 ;; these shells use.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1730 (rc
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1731 ( "{"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1732 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1733 sh-handle-prev-open )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1734 ( "}"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1735 sh-handle-this-close
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1736 nil )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1737 ( "case"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1738 sh-handle-this-rc-case
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1739 sh-handle-prev-rc-case )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1740 ) ;; end of rc
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1741 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1742
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1743
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1744 (defun sh-help-string-for-variable (var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1745 "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
1746 (let ((msg (documentation-property var 'variable-documentation))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1747 (msg2 ""))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1748 (unless (or
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1749 (eq var 'sh-first-lines-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1750 (eq var 'sh-indent-comment))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1751 (setq msg2
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1752 (format "\n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1753 You can enter a number (positive to increase indentenation,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1754 negative to decrease indentation, zero for no change to indentnation).
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1755
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1756 Or, you can enter one of the following symbols which are relative to
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1757 the value of variable `sh-basic-offset'
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1758 which in this buffer is currently %s.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1759
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1760 \t%s."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1761 sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1762 (mapconcat '(lambda (x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1763 (nth (1- (length x)) x) )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1764 sh-symbol-list "\n\t")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1765 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1766
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1767 (concat
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1768 ;; 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
1769 ;; (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
1770 msg msg2)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1771
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1772 (defun sh-read-variable (var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1773 "Read a new value for indentation variable VAR."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1774 (interactive "*variable? ") ;; to test
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1775 (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
1776 (quote ,var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1777 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1778 (setq val (read-from-minibuffer
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1779 (format "New value for %s (press %s for help): "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1780 var (single-key-description help-char))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1781 (format "%s" (symbol-value var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1782 nil t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1783 val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1784
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1785
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1786
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1787 (defun sh-in-comment-or-string (start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1788 "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
1789 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1790 (let (state)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1791 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1792 (setq state (parse-partial-sexp (point) start nil nil nil t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1793 (or (nth 3 state)(nth 4 state)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1794
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1795 (defun sh-goto-matching-if ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1796 "Go to the matching if for a fi.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1797 This handles nested if..fi pairs."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1798 (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
1799 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1800 (goto-char found))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1801
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1802
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1803 ;; 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
1804 ;; line whose indentation is being handled contain XXX;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1805 ;; those named sh-handle-prev-XXX are when XXX appears on the prevoius line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1806
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1807 (defun sh-handle-prev-if ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1808 (list '(+ sh-indent-after-if)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1809
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1810 (defun sh-handle-this-else ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1811 (if (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1812 ;; (list "aligned to if")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1813 (list "aligned to if" '(+ sh-indent-for-else))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1814 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1815 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1816
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1817 (defun sh-handle-prev-else ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1818 (if (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1819 (list '(+ sh-indent-after-if))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1820 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1821
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1822 (defun sh-handle-this-fi ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1823 (if (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1824 (list "aligned to if" '(+ sh-indent-for-fi))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1825 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1826 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1827
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1828 (defun sh-handle-prev-fi ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1829 ;; 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
1830 ;; 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
1831 ;; 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
1832 ;; 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
1833 ;; 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
1834 (sh-goto-matching-if)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1835 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1836
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1837 (defun sh-handle-this-then ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1838 (let ((p (sh-goto-matching-if)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1839 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1840 (list '(+ sh-indent-for-then))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1841 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1842
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1843 (defun sh-handle-prev-then ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1844 (let ((p (sh-goto-matching-if)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1845 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1846 (list '(+ sh-indent-after-if))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1847 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1848
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1849 (defun sh-handle-prev-open ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1850 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1851 (let ((x (sh-prev-stmt)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1852 (if (and x
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1853 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1854 (goto-char x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1855 (or
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1856 (looking-at "function\\b")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1857 (looking-at "\\s-*\\S-+\\s-*()")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1858 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1859 (list '(+ sh-indent-after-function))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1860 (list '(+ sh-indent-after-open)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1861 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1862
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1863 (defun sh-handle-this-close ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1864 (forward-char 1) ;; move over ")"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1865 (let ((p (sh-safe-backward-sexp)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1866 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1867 (list "aligned to opening paren")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1868 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1869 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1870
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1871 (defun sh-goto-matching-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1872 (let ((found (sh-find-prev-matching "\\bcase\\b" "\\besac\\b" 1)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1873 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1874 (goto-char found))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1875
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1876 (defun sh-handle-prev-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1877 ;; 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
1878 ;; we shouldn't -- and can't find prev-case
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1879 (if (looking-at ".*\\bcase\\b")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1880 (list '(+ sh-indent-for-case-label))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1881 (error "We don't see to be on a line with a case") ;; debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1882 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1883
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1884 (defun sh-handle-this-esac ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1885 (let ((p (sh-goto-matching-case)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1886 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1887 (list "aligned to matching case")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1888 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1889 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1890
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1891
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1892 (defun sh-handle-prev-esac ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1893 (let ((p (sh-goto-matching-case)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1894 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1895 (list "matching case")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1896 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1897 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1898
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1899 (defun sh-handle-after-case-label ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1900 (let ((p (sh-goto-matching-case)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1901 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1902 (list '( + sh-indent-for-case-alt ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1903 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1904 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1905
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1906 (defun sh-handle-prev-case-alt-end ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1907 (let ((p (sh-goto-matching-case)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1908 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1909 (list '( + sh-indent-for-case-label ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1910 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1911 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1912
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1913 (defun sh-safe-backward-sexp ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1914 "Try and do a `backward-sexp', but do not error.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1915 Return new point if successful, nil if an error occurred."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1916 (condition-case nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1917 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1918 (backward-sexp 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1919 (point) ;; return point if successful
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1920 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1921 (error
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1922 (sh-debug "oops!(0) %d" (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1923 nil ;; return nil if fail
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1924 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1925
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1926 (defun sh-safe-forward-sexp ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1927 "Try and do a `forward-sexp', but do not error.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1928 Return new point if successful, nil if an error occurred."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1929 (condition-case nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1930 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1931 (forward-sexp 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1932 (point) ;; return point if successful
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1933 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1934 (error
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1935 (sh-debug "oops!(1) %d" (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1936 nil ;; return nil if fail
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1937 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1938
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1939 (defun sh-goto-match-for-done ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1940 (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
1941 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1942 (goto-char found))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1943
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1944 (defun sh-handle-this-done ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1945 (if (sh-goto-match-for-done)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1946 (list "aligned to do stmt" '(+ sh-indent-for-done))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1947 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1948 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1949
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1950 (defun sh-handle-prev-done ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1951 (if (sh-goto-match-for-done)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1952 (list "previous done")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1953 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1954 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1955
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1956 (defun sh-handle-this-do ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1957 (let ( (p (sh-goto-match-for-done)) )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1958 (if p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1959 (list '(+ sh-indent-for-do))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1960 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1961 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1962
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1963 (defun sh-handle-prev-do ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1964 (let ( (p) )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1965 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1966 ((save-restriction
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1967 (narrow-to-region
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1968 (point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1969 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1970 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1971 (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1972 (sh-goto-match-for-done))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1973 (sh-debug "match for done found on THIS line")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1974 (list '(+ sh-indent-after-loop-construct)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1975 ((sh-goto-match-for-done)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1976 (sh-debug "match for done found on PREV line")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1977 (list '(+ sh-indent-after-do)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1978 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1979 (message "match for done NOT found")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1980 nil))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1981
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1982 ;; for rc:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1983 (defun sh-find-prev-switch ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1984 "Find the line for the switch keyword matching this line's case keyword."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1985 (re-search-backward "\\bswitch\\b" nil t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1987 (defun sh-handle-this-rc-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1988 (if (sh-find-prev-switch)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1989 (list '(+ sh-indent-after-switch))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1990 ;; (list '(+ sh-indent-for-case-label))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1991 nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1992
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1993 (defun sh-handle-prev-rc-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1994 (list '(+ sh-indent-after-case)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1995
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1996 (defun sh-check-rule (n thing)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1997 (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
1998 (val nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
1999 (if rule
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2000 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2001 (setq val (funcall rule))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2002 (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
2003 n thing (point) rule val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2004 val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2005
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2006
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2007 (defun sh-get-indent-info ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2008 "Return indent-info for this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2009 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
2010 Otherwise it contains one or more of the following sublists:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2011 \(t NUMBER\) NUMBER is the base location in the buffer that indendation is
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2012 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
2013 sublists. The indentation of the line in question is
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2014 derived from the indentation of this point, possibly
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2015 modified by subsequent sublists.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2016 \(+ VAR\)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2017 \(- 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
2018 the indentation calculated so far.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2019 \(= VAR\) Get the value of variable VAR and *replace* the
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2020 indentation with itss value. This only occurs for
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2021 special variables such as `sh-indent-comment'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2022 STRING This is ignored for the purposes of calculating
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2023 indentation, it is printed in certain cases to help show
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2024 what the indentation is based on."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2025 ;; See comments before `sh-kw'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2026 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2027 (let ((prev-kw nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2028 (prev-stmt nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2029 (have-result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2030 depth-bol depth-eol
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2031 this-kw
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2032 (state nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2033 state-bol
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2034 (depth-prev-bol nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2035 start
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2036 func val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2037 (result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2038 prev-lines-indent
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2039 (prev-list nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2040 (this-list nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2041 (align-point nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2042 prev-line-end x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2043 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2044 ;; Note: setting result to t means we are done and will return nil.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2045 ;;( This function never returns just t.)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2046 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2047 ((equal (get-text-property (point) 'syntax-table) sh-here-doc-syntax)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2048 (setq result t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2049 (setq have-result t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2050 ((looking-at "\\s-*#") ; was (equal this-kw "#")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2051 (if (bobp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2052 (setq result t);; return nil if 1st line!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2053 (setq result (list '(= sh-indent-comment)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2054 ;; we still need to get previous line in case
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2055 ;; sh-indent-comnent is t (indent as normal)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2056 (setq align-point (sh-prev-line nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2057 (setq have-result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2058 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2059 );; cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2060
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2061 (unless have-result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2062 ;; Continuation lines are handled specially
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2063 (if (sh-this-is-a-continuation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2064 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2065 ;; We assume the line being continued is already
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2066 ;; properly indented...
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2067 ;; (setq prev-line-end (sh-prev-line))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2068 (setq align-point (sh-prev-line nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2069 (setq result (list '(+ sh-indent-for-continuation)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2070 (setq have-result t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2071 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2072 (skip-chars-forward " \t")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2073 (setq this-kw (sh-get-kw)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2074
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2075 ;; 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
2076 ;; calculating indentation info for.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2077 (if this-kw
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2078 (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
2079 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2080 (setq align-point (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2081 (sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2082 "this - setting align-point to %d" align-point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2083 (setq result (append result val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2084 (setq have-result t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2085 ;; set prev-line to continue processing remainder
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2086 ;; of this line as a previous l ine
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2087 (setq prev-line-end (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2088 ))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2089
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2090 (unless have-result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2091 (setq prev-line-end (sh-prev-line 'end)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2092
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2093 (if prev-line-end
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2094 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2095 ;; We start off at beginning of this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2096 ;; Scan previous statements while this is <=
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2097 ;; start of previous line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2098 (setq start (point));; for debug only
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2099 (goto-char prev-line-end)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2100 (setq x t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2101 (while (and x (setq x (sh-prev-thing)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2102 (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
2103 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2104 ((and (equal x ")")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2105 (equal (get-text-property (1- (point)) 'syntax-table)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2106 sh-special-syntax))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2107 (sh-debug "Case label) here")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2108 (setq x 'case-label)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2109 (if (setq val (sh-check-rule 2 x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2110 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2111 (setq result (append result val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2112 (setq align-point (point))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2113 (forward-char -1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2114 (skip-chars-forward "[a-z0-9]*?")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2115 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2116 ((string-match "[])}]" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2117 (setq x (sh-safe-backward-sexp))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2118 (if x
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2119 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2120 (setq align-point (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2121 (setq result (append result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2122 (list "aligned to opening paren")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2123 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2124 ((string-match "[[({]" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2125 (sh-debug "Checking special thing: %s" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2126 (if (setq val (sh-check-rule 2 x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2127 (setq result (append result val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2128 (forward-char -1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2129 (setq align-point (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2130 ((string-match "[\"'`]" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2131 (sh-debug "Skipping back for %s" x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2132 ;; this was oops-2
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2133 (setq x (sh-safe-backward-sexp)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2134 ((stringp x)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2135 (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
2136 (if (setq val (sh-check-rule 2 x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2137 ;; (or (eq t (car val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2138 ;; (eq t (car (car val))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2139 (setq result (append result val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2140 ;; 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
2141 (setq align-point (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2142 (unless (bolp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2143 (forward-char -1)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2144 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2145 (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
2146 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2147 );; while
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2148 (sh-debug "result is %s" result)
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 (sh-debug "No prev line!")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2151 (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
2152 )
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 (if align-point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2155 ;; 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
2156 (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
2157 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2158 (sh-debug "result is now: %s" result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2159
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2160 (or result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2161 (if prev-line-end
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2162 (setq result (list (list t prev-line-end)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2163 (setq result (list (list '= 'sh-first-lines-indent)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2164 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2165
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2166 (if (eq result t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2167 (setq result nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2168 (sh-debug "result is: %s" result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2169 result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2170 );; let
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2171 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2172
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2173
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2174 (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
2175 "Return the variable controlling indentation for this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2176 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
2177 indicating the problem.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2178 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
2179 (let ((var nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2180 (result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2181 (reason nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2182 sym elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2183 (or info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2184 (setq info (sh-get-indent-info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2185 (if (null info)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2186 (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
2187 (while (and info (null result))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2188 (setq elt (car info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2189 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2190 ((stringp elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2191 (setq reason elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2192 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2193 ((not (listp elt))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2194 (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
2195 ;; so it is a list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2196 ((eq t (car elt))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2197 );; nothing
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2198 ((symbolp (setq sym (nth 1 elt)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2199 ;; 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
2200 ;; ignore other variables. Otherwise it is tricky to
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2201 ;; "learn" the comment indentation.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2202 (if (eq var 'sh-indent-comment)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2203 (setq result var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2204 (if var
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2205 (setq result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2206 "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
2207 (setq var sym))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2208 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2209 (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
2210 (setq info (cdr info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2211 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2212 (or result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2213 (setq result var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2214 (or result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2215 (setq result reason))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2216 (if (null result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2217 ;; e.g. just had (t POS)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2218 (setq result "line has default indentation"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2219 result))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2220
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2221
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2222
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2223 ;; Finding the previous line isn't trivial.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2224 ;; We must *always* go back one more and see if that is a continuation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2225 ;; line -- it is the PREVIOUS line which is continued, not the one
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2226 ;; we are going to!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2227 ;; 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
2228 ;; 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
2229 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2230 ;; What we do:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2231 ;; - go back a line, if empty repeat
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2232 ;; - (we are now at a previous non empty line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2233 ;; - save this
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2234 ;; - if this is in a here-document, go to the beginning of it
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2235 ;; and save that
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2236 ;; - go back one more physcial line and see if it is a continuation line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2237 ;; - if yes, save it and repeat
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2238 ;; - if no, go back to where we last saved.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2239 (defun sh-prev-line (&optional end)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2240 "Back to end of previous non-comment non-empty line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2241 Go to beginning of logical line unless END is non-nil, in which case
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2242 we go to the end of the previous line and do not check for continuations."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2243 (sh-must-be-shell-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2244 (let ((going t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2245 (last-contin-line nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2246 (result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2247 bol eol state)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2248 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2249 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2250 (while (and going
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2251 (not (bobp))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2252 (>= 0 (forward-line -1))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2253 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2254 (setq bol (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2255 (end-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2256 (setq eol (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2257 (save-restriction
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2258 (setq state (parse-partial-sexp bol eol nil nil nil t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2259 (if (nth 4 state)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2260 (setq eol (nth 8 state)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2261 (narrow-to-region bol eol)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2262 (goto-char bol)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2263 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2264 ((looking-at "\\s-*$"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2265 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2266 (if end
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2267 (setq result eol)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2268 (setq result bol))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2269 (setq going nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2270 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2271 (if (and result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2272 (equal (get-text-property (1- result) 'syntax-table)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2273 sh-here-doc-syntax))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2274 (let ((p1 (previous-single-property-change
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2275 (1- result) 'syntax-table)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2276 (if p1
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2277 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2278 (goto-char p1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2279 (forward-line -1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2280 (if end
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2281 (end-of-line))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2282 (setq result (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2283 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2284 (unless end
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2285 ;; we must check previous lines to see if they are continuation lines
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2286 ;; if so, we must return position of first of them
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2287 (while (and (sh-this-is-a-continuation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2288 (>= 0 (forward-line -1)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2289 (setq result (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2290 (if result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2291 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2292 (goto-char result)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2293 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2294 (skip-chars-forward " \t")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2295 (setq result (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2296 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2297 ) ;; save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2298 result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2299 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2300
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2301
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2302 (defun sh-prev-stmt ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2303 "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
2304 ;; This is used when we are trying to find a matching keyword.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2305 ;; Searching backward for the keyword would certainly be quicker, but
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2306 ;; 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
2307 ;; 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
2308 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2309 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2310 (let ((going t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2311 (start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2312 (found nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2313 (prev nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2314 (skip-chars-backward " \t;|&({[")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2315 (while (and (not found)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2316 (not (bobp))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2317 going)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2318 ;; Do a backward-sexp if possible, else backup bit by bit...
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2319 (if (sh-safe-backward-sexp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2320 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2321 (if (looking-at sh-special-keywords)
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 found prev))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2324 (setq prev (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2325 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2326 ;; backward-sexp failed
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2327 (if (zerop (skip-chars-backward " \t()[\]{};`'"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2328 (forward-char -1))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2329 (if (bolp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2330 (let ((back (sh-prev-line nil)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2331 (if back
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2332 (goto-char back)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2333 (setq going nil)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2334 (unless found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2335 (skip-chars-backward " \t")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2336 (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
2337 (eq (char-before) ?\;)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2338 (looking-at "\\s-*[|&]"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2339 (setq found (point)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2340 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2341 (goto-char found))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2342 (if found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2343 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2344 (skip-chars-forward " \t|&({[")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2345 (setq found (point))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2346 (if (>= (point) start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2347 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2348 (debug "We didn't move!")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2349 (setq found nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2350 (or found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2351 (sh-debug "Did not find prev stmt.")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2352 found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2353 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2354
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2355
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2356 (defun sh-get-word ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2357 "Get a shell word skipping whitespace from point."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2358 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2359 (skip-chars-forward "\t ")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2360 (let ((start (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2361 (while
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2362 (if (looking-at "[\"'`]")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2363 (sh-safe-forward-sexp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2364 ;; (> (skip-chars-forward "^ \t\n\"'`") 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2365 (> (skip-chars-forward "-_a-zA-Z\$0-9") 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2366 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2367 (buffer-substring start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2368 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2369
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2370 (defun sh-prev-thing ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2371 "Return the previous thing this logical line."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2372 ;; 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
2373 ;; the previous line(s) finding what keywords may be relevant for
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2374 ;; indenting. It moves over sexps if possible, and will stop
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2375 ;; 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
2376 ;; line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2377 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2378 ;; Added a kludge for ";;"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2379 ;; Possible return values:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2380 ;; nil - nothing
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2381 ;; a string - possibly a keyword
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2382 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2383 (if (bolp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2384 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2385 (let ((going t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2386 c n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2387 min-point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2388 (start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2389 (found nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2390 (save-restriction
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2391 (narrow-to-region
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2392 (if (sh-this-is-a-continuation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2393 (setq min-point (sh-prev-line nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2394 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2395 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2396 (setq min-point (point))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2397 (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2398 (skip-chars-backward " \t;")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2399 (unless (looking-at "\\s-*;;")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2400 (skip-chars-backward "^)}];\"'`({[")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2401 (setq c (char-before))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2402 (sh-debug "stopping at %d c is %s start=%d min-point=%d"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2403 (point) c start min-point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2404 (if (< (point) min-point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2405 (error "point %d < min-point %d" (point) min-point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2406 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2407 ((looking-at "\\s-*;;")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2408 ;; (message "Found ;; !")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2409 ";;")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2410 ((or (eq c ?\n)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2411 (eq c nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2412 (eq c ?\;))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2413 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2414 ;; skip forward over white space newline and \ at eol
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2415 (skip-chars-forward " \t\n\\\\")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2416 (sh-debug "Now at %d start=%d" (point) start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2417 (if (>= (point) start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2418 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2419 (sh-debug "point: %d >= start: %d" (point) start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2420 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2421 (sh-get-word))
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 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2424 ;; c -- return a string
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2425 (char-to-string c)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2426 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2427 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2428
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2429
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2430 (defun sh-this-is-a-continuation ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2431 "Return non-nil if current line is a continuation of previous line."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2432 (let ((result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2433 bol eol state)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2434 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2435 (if (and (zerop (forward-line -1))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2436 (looking-at ".*\\\\$"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2437 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2438 (setq bol (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2439 (end-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2440 (setq eol (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2441 (setq state (parse-partial-sexp bol eol nil nil nil t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2442 (unless (nth 4 state)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2443 (setq result t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2444 )))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2445
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2446 (defun sh-get-kw (&optional where and-move)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2447 "Return first word of line from WHERE.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2448 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
2449 (let ((start (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2450 (if where
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2451 (goto-char where))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2452 (prog1
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2453 (buffer-substring (point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2454 (progn (skip-chars-forward "^ \t\n;")(point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2455 (unless and-move
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2456 (goto-char start)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2457 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2458
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2459 (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
2460 "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
2461 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
2462 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
2463 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
2464 (let ((parse-sexp-ignore-comments t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2465 prev)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2466 (setq depth (or depth 1))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2467 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2468 (condition-case nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2469 (while (and
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2470 (/= 0 depth)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2471 (not (bobp))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2472 (setq prev (sh-prev-stmt)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2473 (goto-char prev)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2474 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2475 (if (looking-at "\\\\\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2476 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2477 (forward-char 2)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2478 (skip-chars-forward " \t")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2479 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2480 ((looking-at open)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2481 (setq depth (1- depth))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2482 (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
2483 ((looking-at close)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2484 (setq depth (1+ depth))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2485 (sh-debug "found close - depth = %d" depth))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2486 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2487 ))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2488 (error nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2489 (if (eq depth 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2490 prev ;; (point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2491 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2492 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2493
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2494
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2495 (defun sh-var-value (var &optional ignore-error)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2496 "Return the value of variable VAR, interpreting symbols.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2497 It can also return t or nil.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2498 If an illegal value is found, throw an error unless Optional argument
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2499 IGNORE-ERROR is non-nil."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2500 (let ((val (symbol-value var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2501 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2502 ((numberp val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2503 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2504 ((eq val t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2505 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2506 ((null val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2507 val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2508 ((eq val '+)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2509 sh-basic-offset)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2510 ((eq val '-)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2511 (- sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2512 ((eq val '++)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2513 (* 2 sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2514 ((eq val '--)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2515 (* 2 (- sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2516 ((eq val '*)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2517 (/ sh-basic-offset 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2518 ((eq val '/)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2519 (/ (- sh-basic-offset) 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2520 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2521 (if ignore-error
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2522 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2523 (message "Don't konw how to handle %s's value of %s" var val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2524 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2525 (error "Don't know how to handle %s's value of %s" var val))
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
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2528 (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
2529 "Set variable VAR to VALUE.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2530 Unless optional argument NO-SYMBOL is non-nil, then if VALUE is
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2531 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
2532 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2533 (no-symbol
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2534 (set var value))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2535 ((= value sh-basic-offset)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2536 (set var '+))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2537 ((= value (- sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2538 (set var '-))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2539 ((eq value (* 2 sh-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2540 (set var '++))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2541 ((eq value (* 2 (- sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2542 (set var '--))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2543 ((eq value (/ sh-basic-offset 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2544 (set var '*))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2545 ((eq value (/ (- sh-basic-offset) 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2546 (set var '/))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2547 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2548 (set var value)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2549 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2550
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2551
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2552 (defun sh-calculate-indent (&optional info)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2553 "Return the indentation for the current line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2554 If INFO is supplied it is used, else it is calculated from current line."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2555 (let (
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2556 (ofs 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2557 (base-value 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2558 elt a b var val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2559 (or info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2560 (setq info (sh-get-indent-info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2561 (if (null info)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2562 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2563 (while info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2564 (sh-debug "info: %s ofs=%s" info ofs)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2565 (setq elt (car info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2566 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2567 ((stringp elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2568 ;; do nothing?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2569 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2570 ((listp elt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2571 (setq a (car (car info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2572 (setq b (nth 1 (car info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2573 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2574 ((eq a t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2575 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2576 (goto-char b)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2577 (setq val (current-indentation)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2578 (setq base-value val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2579 ((symbolp b)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2580 (setq val (sh-var-value b))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2581 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2582 ((eq a '=)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2583 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2584 ((null val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2585 ;; no indentation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2586 ;; set info to nil so we stop immediately
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2587 (setq base-value nil ofs nil info nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2588 ((eq val t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2589 ;; indent as normal line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2590 (setq ofs 0))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2591 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2592 ;; The following assume the (t POS) come first!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2593 (setq ofs val base-value 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2594 (setq info nil) ;; ? stop now
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2595 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2596 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2597 ((eq a '+)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2598 (setq ofs (+ ofs val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2599 ((eq a '-)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2600 (setq ofs (- ofs val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2601 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2602 (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
2603 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2604 (error "sh-calculate-indent invalid elt: a=%s b=%s" a b)))
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 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2607 (error "sh-calculate-indent invalid elt %s" elt))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2608 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2609 (sh-debug "a=%s b=%s val=%s base-value=%s ofs=%s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2610 a b val base-value ofs)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2611 (setq info (cdr info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2612 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2613 ;; return value:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2614 (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
2615
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2616 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2617 ((or (null base-value)(null ofs))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2618 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2619 ((and (numberp base-value)(numberp ofs))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2620 (sh-debug "base (%d) + ofs (%d) = %d"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2621 base-value ofs (+ base-value ofs))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2622 (+ base-value ofs)) ;; return value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2623 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2624 (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
2625 base-value ofs)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2626 nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2627 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2628
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2629
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2630 (defun sh-indent-line ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2631 "Indent the current line."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2632 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2633 (sh-must-be-shell-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2634 (let ((indent (sh-calculate-indent)) shift-amt beg end
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2635 (pos (- (point-max) (point))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2636 (if indent
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2637 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2638 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2639 (setq beg (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2640 (skip-chars-forward " \t")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2641 (setq shift-amt (- indent (current-column)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2642 (if (zerop shift-amt)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2643 nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2644 (delete-region beg (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2645 (indent-to indent))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2646 ;; If initial point was within line's indentation,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2647 ;; position after the indentation. Else stay at same point in text.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2648 (if (> (- (point-max) pos) (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2649 (goto-char (- (point-max) pos)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2650 ))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2651
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2652
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2653 (defun sh-blink (blinkpos &optional msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2654 "Move cursor momentarily to BLINKPOS and display MSG."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2655 ;; 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
2656 (if (numberp blinkpos)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2657 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2658 (goto-char blinkpos)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2659 (message msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2660 (sit-for blink-matching-delay))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2661 (message msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2662 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2663
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2664 (defun sh-show-indent (arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2665 "Show the how the currently line would be indented.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2666 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
2667 this line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2668 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
2669 a pop up window describes this variable.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2670 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
2671 we are indenting relative to, if applicable."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2672 (interactive "P")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2673 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2674 (let* ((info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2675 (var (sh-get-indent-var-for-line info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2676 val msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2677 (curr-indent (current-indentation))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2678 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2679 (if (stringp var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2680 (message (setq msg var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2681 (setq val (sh-calculate-indent info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2682
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2683 (if (eq curr-indent val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2684 (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
2685 (setq msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2686 (if val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2687 (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
2688 var (symbol-value var) curr-indent val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2689 (format "%s (%s) would leave line as is"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2690 var (symbol-value var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2691 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2692 (if (and arg var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2693 (describe-variable var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2694 (if sh-blink
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2695 (let ((info (sh-get-indent-info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2696 (if (and info (listp (car info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2697 (eq (car (car info)) t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2698 (sh-blink (nth 1 (car info)) msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2699 (message msg)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2700 (message msg))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2701 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2702
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2703 (defun sh-set-indent ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2704 "Set the indentation for the current line.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2705 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
2706 for a new value for it."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2707 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2708 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2709 (let* ((info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2710 (var (sh-get-indent-var-for-line info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2711 val val0 new-val old-val indent-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2712 (if (stringp var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2713 (message (format "Cannot set indent - %s" var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2714 (setq old-val (symbol-value var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2715 (setq val (sh-read-variable var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2716 (condition-case nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2717 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2718 (set var val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2719 (setq indent-val (sh-calculate-indent info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2720 (if indent-val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2721 (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
2722 var (symbol-value var) indent-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2723 (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
2724 var (symbol-value var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2725 ;; I'm not sure about this, indenting it now?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2726 ;; No. Because it would give the impression that an undo would
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2727 ;; restore thing, but the value has been altered.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2728 ;; (sh-indent-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2729 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2730 (error
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2731 (set var old-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2732 (message "Bad value for %s, restoring to previous value %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2733 var old-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2734 (sit-for 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2735 nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2736 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2737
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2738
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2739 (defun sh-learn-line-indent (arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2740 "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
2741
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2742 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
2743 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
2744 presently is.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2745
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2746 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
2747 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
2748 (interactive "*P")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2749 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2750 ;; 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
2751 ;; 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
2752 ;; would just be confusing.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2753 (if (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2754 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2755 (looking-at "\\s-*$"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2756 (message "sh-learn-line-indent ignores empty lines.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2757 (let* ((info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2758 (var (sh-get-indent-var-for-line info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2759 ival sval diff new-val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2760 (no-symbol arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2761 (curr-indent (current-indentation)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2762 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2763 ((stringp var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2764 (message (format "Cannot learn line - %s" var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2765 ((eq var 'sh-indent-comment)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2766 ;; This is arbitrary...
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2767 ;; - if curr-indent is 0, set to curr-indent
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2768 ;; - else if it has the indentation of a "normal" line,
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2769 ;; then set to t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2770 ;; - else set to curr-indent.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2771 (setq sh-indent-comment
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2772 (if (= curr-indent 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2773 0
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2774 (let* ((sh-indent-comment t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2775 (val2 (sh-calculate-indent info)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2776 (if (= val2 curr-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2777 t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2778 curr-indent))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2779 (message "%s set to %s" var (symbol-value var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2780 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2781 ((numberp (setq sval (sh-var-value var)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2782 (setq ival (sh-calculate-indent info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2783 (setq diff (- curr-indent ival))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2784
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2785 (sh-debug "curr-indent: %d ival: %d diff: %d var:%s sval %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2786 curr-indent ival diff var sval)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2787 (setq new-val (+ sval diff))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2788 ;;; 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
2789 ;;; 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
2790 ;;; or vice-versa.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2791 ;;; (if (= 0 diff)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2792 ;;; (message "No change needed!")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2793 (sh-set-var-value var new-val no-symbol)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2794 (message "%s set to %s" var (symbol-value var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2795 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2796 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2797 (debug)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2798 (message "Cannot change %s" var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2799 ))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2800
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2801
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2802
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2803 (defun sh-mark-init (buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2804 "Initialize a BUFFER to be used by `sh-mark-line'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2805 (let ((main-buffer (current-buffer)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2806 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2807 (set-buffer (get-buffer-create buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2808 (erase-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2809 (occur-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2810 (setq occur-buffer main-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2811 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2812
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2813
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2814 (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
2815 "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
2816 Buffer BUFFER is in `occur-mode'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2817 If ADD-LINENUM is non-nil the message is preceded by the line number.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2818 If OCCUR-POINT is non-nil then the line is marked as a new occurence
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2819 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
2820 (let ((m1 (make-marker))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2821 (main-buffer (current-buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2822 start
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2823 (line "") )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2824 (if point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2825 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2826 (set-marker m1 point (current-buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2827 (if add-linenum
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2828 (setq line (format "%d: " (1+ (count-lines 1 point)))))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2829 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2830 (if (get-buffer buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2831 (set-buffer (get-buffer buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2832 (set-buffer (get-buffer-create buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2833 (occur-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2834 (setq occur-buffer main-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2835 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2836 (goto-char (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2837 (setq start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2838 (insert line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2839 (if occur-point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2840 (setq occur-point (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2841 (insert message)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2842 (if point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2843 (put-text-property start (point) 'mouse-face 'highlight))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2844 (insert "\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2845 (if point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2846 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2847 (put-text-property start (point) 'occur m1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2848 (if occur-point
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2849 (put-text-property occur-point (1+ occur-point)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2850 'occur-point t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2851 ))
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
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2854
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2855
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2856 ;; Is this really worth having?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2857 (defvar sh-learned-buffer-hook nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2858 "*An abnormal hook, called with an alist of leared variables.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2859 ;;; Example of how to use sh-learned-buffer-hook
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2860 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2861 ;; (defun what-i-learned (list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2862 ;; (let ((p list))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2863 ;; (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2864 ;; (set-buffer "*scratch*")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2865 ;; (goto-char (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2866 ;; (insert "(setq\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2867 ;; (while p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2868 ;; (insert (format " %s %s \n"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2869 ;; (nth 0 (car p)) (nth 1 (car p))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2870 ;; (setq p (cdr p)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2871 ;; (insert ")\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2872 ;; )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2873 ;;
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2874 ;; (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
2875
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2876
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2877 ;; Originally this was sh-learn-region-indent (beg end)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2878 ;; However, in practise this was awkward so I changed it to
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2879 ;; use the whole buffer. Use narrowing if needbe.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2880 (defun sh-learn-buffer-indent (&optional arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2881 "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
2882
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2883 Output in buffer \"*indent*\" shows any lines which have conflicting
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2884 values of a variable, and the final value of all variables learnt.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2885 This buffer is popped to automatically if there are any discrepencies.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2886
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2887 If no prefix ARG is given, then variables are set to numbers.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2888 If a prefix arg is given, then variables are set to symbols when
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2889 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
2890 basic indent.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2891 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
2892 is set to the prefix's numerical value.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2893 Otherwise, sh-basic-offset may or may not be changed, according
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2894 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
2895
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2896 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
2897 function completes. The function is abnormal because it is called
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2898 with an alist of variables learnt. This feature may be changed or
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2899 removed in the future.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2900
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2901 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
2902 (interactive "P")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2903 (sh-must-support-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2904 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2905 (goto-char (point-min))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2906 (let ((learned-var-list nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2907 (out-buffer "*indent*")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2908 (num-diffs 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2909 last-pos
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2910 previous-set-info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2911 (max 17)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2912 vec
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2913 msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2914 (comment-col nil) ;; number if all same, t if seen diff values
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2915 (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
2916 initial-msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2917 (specified-basic-offset (and arg (numberp arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2918 (> arg 0)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2919 (linenum 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2920 suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2921 (setq vec (make-vector max 0))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2922 (sh-mark-init out-buffer)
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 (if specified-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2925 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2926 (setq sh-basic-offset arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2927 (setq initial-msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2928 (format "Using specified sh-basic-offset of %d"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2929 sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2930 (setq initial-msg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2931 (format "Initial value of sh-basic-offset: %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2932 sh-basic-offset)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2933
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2934 (while (< (point) (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2935 (setq linenum (1+ linenum))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2936 ;; (if (zerop (% linenum 10))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2937 (message "line %d" linenum)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2938 ;; )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2939 (unless (looking-at "\\s-*$") ;; ignore empty lines!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2940 (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
2941 (info (sh-get-indent-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2942 (var (sh-get-indent-var-for-line info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2943 sval ival diff new-val
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2944 (curr-indent (current-indentation)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2945 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2946 ((null var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2947 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2948 ((stringp var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2949 nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2950 ((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
2951 ;; 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
2952 (setq ival (sh-calculate-indent))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2953 (setq diff (- curr-indent ival))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2954 (setq new-val (+ sval diff))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2955 (sh-set-var-value var new-val 'no-symbol)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2956 (unless (looking-at "\\s-*#");; don't learn from comments
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2957 (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
2958 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2959 ;; it was already there, is it same value ?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2960 (unless (eq (symbol-value var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2961 (nth 1 previous-set-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2962 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2963 (format "Variable %s was set to %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2964 var (symbol-value var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2965 (point) out-buffer t t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2966 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2967 (format " but was previously set to %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2968 (nth 1 previous-set-info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2969 (nth 2 previous-set-info) out-buffer t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2970 (setq num-diffs (1+ num-diffs))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2971 ;; (delete previous-set-info learned-var-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2972 (setcdr previous-set-info
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2973 (list (symbol-value var) (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2974 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2975 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2976 (setq learned-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2977 (append (list (list var (symbol-value var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2978 (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2979 learned-var-list)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2980 (if (numberp new-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2981 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2982 (sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2983 "This line's indent value: %d" new-val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2984 (if (< new-val 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2985 (setq new-val (- new-val)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2986 (if (< new-val max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2987 (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
2988 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2989 ((eq var 'sh-indent-comment)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2990 (unless (= curr-indent (sh-calculate-indent info))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2991 ;; this is not the default indentation
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2992 (setq comments-always-default nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2993 (if comment-col;; then we have see one before
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2994 (or (eq comment-col curr-indent)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2995 (setq comment-col t));; seen a different one
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2996 (setq comment-col curr-indent))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2997 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2998 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
2999 (sh-debug "Cannot learn this line!!!")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3000 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3001 (sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3002 "at %s learned-var-list is %s" (point) learned-var-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3003 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3004 (forward-line 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3005 ) ;; while
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3006 (if sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3007 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3008 (setq msg (format
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3009 "comment-col = %s comments-always-default = %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3010 comment-col comments-always-default))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3011 ;; (message msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3012 (sh-mark-line msg nil out-buffer)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3013 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3014 ((eq comment-col 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3015 (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
3016 (comments-always-default
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3017 (setq msg "\nComments follow default indentation.\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3018 (setq comment-col t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3019 ((numberp comment-col)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3020 (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
3021 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3022 (setq msg "\nComments seem to be mixed, leaving them as is.\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3023 (setq comment-col nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3024 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3025 (sh-debug msg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3026 (sh-mark-line msg nil out-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3027
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3028 (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
3029
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3030 (setq suggested (sh-guess-basic-offset vec))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3031
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3032 (if (and suggested (not specified-basic-offset))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3033 (let ((new-value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3034 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3035 ;; 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
3036 ((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
3037 suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3038 ;; 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
3039 (sh-learn-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3040 (if (numberp suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3041 suggested
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3042 (if (= (length suggested) 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3043 (car suggested))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3044 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3045 nil))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3046 (if new-value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3047 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3048 (setq learned-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3049 (append (list (list 'sh-basic-offset
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3050 (setq sh-basic-offset new-value)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3051 (point-max)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3052 learned-var-list))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3053 ;; 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
3054 ;; it will appear in the "Learned variable settings".
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3055 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3056 (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
3057 nil out-buffer))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3058 (sh-mark-line
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3059 (if (listp suggested)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3060 (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
3061 (mapconcat 'int-to-string suggested " "))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3062 (format "Suggested sh-basic-offset: %d" suggested))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3063 nil out-buffer))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3064
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3065
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3066 (setq learned-var-list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3067 (append (list (list 'sh-indent-comment comment-col (point-max)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3068 learned-var-list))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3069 (setq sh-indent-comment comment-col)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3070 (let ((name (buffer-name))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3071 (lines (if (and (eq (point-min) 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3072 (eq (point-max) (1+ (buffer-size))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3073 ""
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3074 (format "lines %d to %d of "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3075 (1+ (count-lines 1 (point-min)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3076 (1+ (count-lines 1 (point-max))))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3077 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3078 (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
3079 (if arg
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3080 ;; Set learned variables to symbolic rather than numeric
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3081 ;; values where possible.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3082 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3083 (let ((p (reverse learned-var-list))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3084 var val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3085 (while p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3086 (setq var (car (car p)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3087 (setq val (nth 1 (car p)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3088 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3089 ((eq var 'sh-basic-offset)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3090 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3091 ((numberp val)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3092 (sh-set-var-value var val))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3093 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3094 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3095 (setq p (cdr p))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3096 ))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3097 (let ((p (reverse learned-var-list))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3098 var)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3099 (while p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3100 (setq var (car (car p)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3101 (sh-mark-line (format " %s %s" var (symbol-value var))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3102 (nth 2 (car p)) out-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3103 (setq p (cdr p))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3104 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3105 (set-buffer out-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3106 (goto-char (point-min))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3107 (insert
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3108 (format "Indentation values for buffer %s.\n" name)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3109 (format "%d indentation variable%s different values%s\n\n"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3110 num-diffs
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3111 (if (= num-diffs 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3112 " has" "s have")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3113 (if (zerop num-diffs)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3114 "." ":"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3115 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3116 ;; Are abnormal hooks considered bad form?
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3117 (run-hook-with-args 'sh-learned-buffer-hook learned-var-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3118 (if (or sh-popup-occur-buffer (> num-diffs 0))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3119 (pop-to-buffer out-buffer))
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
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3122 (defun sh-guess-basic-offset (vec)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3123 "See if we can determine a reasonbable value for `sh-basic-offset'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3124 This is experimental, heuristic and arbitrary!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3125 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
3126 `sh-learn-buffer-indent'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3127 Return values:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3128 number - there appears to be a good single value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3129 list of numbers - no obvious one, here is a list of one or more
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3130 reasonable choices
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3131 nil - we couldn't find a reasonable one."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3132 (let* ((max (1- (length vec)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3133 (i 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3134 (totals (make-vector max 0))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3135 (return nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3136 j)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3137 (while (< i max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3138 (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
3139 (setq j (/ i 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3140 (if (zerop (% i 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3141 (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
3142 (if (< (* i 2) max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3143 (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
3144 (setq i (1+ i))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3145 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3146 (let ((x nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3147 (result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3148 tot sum p)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3149 (setq i 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3150 (while (< i max)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3151 (if (/= (aref totals i) 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3152 (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
3153 (setq i (1+ i)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3154
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3155 (setq x (sort x '(lambda (a b)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3156 (> (cdr a)(cdr b)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3157 (setq tot (apply '+ (append totals nil)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3158 (sh-debug (format "vec: %s\ntotals: %s\ntot: %d"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3159 vec totals tot))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3160 (cond
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3161 ((zerop (length x))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3162 (message "no values!")) ;; we return nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3163 ((= (length x) 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3164 (message "only value is %d" (car (car x)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3165 (setq result (car (car x)))) ;; return single value
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3166 ((> (cdr (car x)) (/ tot 2))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3167 ;; 1st is > 50%
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3168 (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
3169 (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
3170 ((>= (cdr (car x)) (* 2 (cdr (car (cdr x)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3171 ;; 1st is >= 2 * 2nd
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3172 (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
3173 (setq result (car (car x))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3174 ((>= (+ (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
3175 ;; 1st & 2nd together >= 50% - return a list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3176 (setq p x sum 0 result nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3177 (while (and p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3178 (<= (setq sum (+ sum (cdr (car p)))) (/ tot 2)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3179 (setq result (append result (list (car (car p)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3180 (setq p (cdr p)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3181 (message "Possible choices for sh-basic-offset: %s"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3182 (mapconcat 'int-to-string result " ")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3183 (t
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3184 (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
3185 (car (car x)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3186 ;; result is nil here
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3187 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3188 result
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3189 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3190
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3191
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3192 (defun sh-do-nothing (a b c)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3193 ;; checkdoc-params: (a b c)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3194 "A dummy function to prevent font-lock from re-fontifying a change.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3195 Otherwise, we fontify something and font-lock overwrites it."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3196 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3197
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3198 (defun sh-set-char-syntax (where new-prop)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3199 "Set the character's syntax table property at WHERE to be NEW-PROP."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3200 (or where
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3201 (setq where (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3202 (let ((font-lock-fontify-region-function 'sh-do-nothing))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3203 (put-text-property where (1+ where) 'syntax-table new-prop)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3204 (add-text-properties where (1+ where)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3205 '(face sh-st-face rear-nonsticky t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3206 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3207
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3208
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3209 (defun sh-check-paren-in-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3210 "Make syntax class of case label's right parenthesis not close parenthesis.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3211 If this parenthesis is a case alternative, set its syntax class to a word."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3212 (let ((start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3213 state prev-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3214 ;; First test if this is a possible candidate, the first "(" or ")"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3215 ;; on the line; then, if go, check prev line is ;; or case.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3216 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3217 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3218 ;; stop at comment or when depth becomes -1
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3219 (setq state (parse-partial-sexp (point) start -1 nil nil t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3220 (if (and
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3221 (= (car state) -1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3222 (= (point) start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3223 (setq prev-line (sh-prev-line nil)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3224 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3225 (goto-char prev-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3226 (beginning-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3227 ;; (setq case-stmt-start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3228 ;; (if (looking-at "\\(^\\s-*case[^-a-z0-9_]\\|[^#]*;;\\s-*$\\)")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3229 (if (sh-search-word "\\(case\\|;;\\)" start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3230 (sh-set-char-syntax (1- start) sh-special-syntax)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3231 ))))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3232
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3233 (defun sh-electric-rparen ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3234 "Insert a right parethese, and check if it is a case alternative.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3235 If so, its syntax class is set to word, and its text proerty
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3236 is set to have face `sh-st-face'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3237 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3238 (insert ")")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3239 (if sh-electric-rparen-needed-here
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3240 (sh-check-paren-in-case)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3241
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3242 (defun sh-electric-hash ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3243 "Insert a hash, but check it is preceded by \"$\".
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3244 If so, it is given a syntax type of comment.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3245 Its text proerty has face `sh-st-face'."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3246 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3247 (let ((pos (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3248 (insert "#")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3249 (if (eq (char-before pos) ?$)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3250 (sh-set-char-syntax pos sh-st-punc))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3251
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3252 (defun sh-electric-less (arg)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3253 "Insert a \"<\" and see if this is the start of a here-document.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3254 If so, the syntax class is set so that it will not be automatically
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3255 reindented.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3256 Argument ARG if non-nil disables this test."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3257 (interactive "*P")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3258 (let ((p1 (point)) p2 p3)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3259 (sh-maybe-here-document arg) ;; call the original fn in sh-script.el.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3260 (setq p2 (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3261 (if (/= (+ p1 (prefix-numeric-value arg)) p2)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3262 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3263 (forward-line 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3264 (end-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3265 (setq p3 (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3266 (sh-set-here-doc-region p2 p3))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3267 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3268
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3269 (defun sh-set-here-doc-region (start end)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3270 "Mark a here-document from START to END so that it will not be reindented."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3271 (interactive "r")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3272 ;; Make the whole thing have syntax type word...
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3273 ;; That way sexp movement doens't worry about any parentheses.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3274 ;; A disadvantage of this is we can't use forward-word within a
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3275 ;; here-doc, which is annoying.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3276 (let ((font-lock-fontify-region-function 'sh-do-nothing))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3277 (put-text-property start end 'syntax-table sh-here-doc-syntax)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3278 (put-text-property start end 'face 'sh-heredoc-face)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3279 (put-text-property (1- end) end 'rear-nonsticky t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3280 (put-text-property start (1+ start) 'front-sticky t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3281 ))
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 (defun sh-remove-our-text-properties ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3284 "Remove text properties relating to right parentheses and here documents."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3285 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3286 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3287 (goto-char (point-min))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3288 (while (not (eobp))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3289 (let ((plist (text-properties-at (point)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3290 (next-change
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3291 (or (next-single-property-change (point) 'syntax-table
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3292 (current-buffer) )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3293 (point-max))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3294 ;; Process text from point to NEXT-CHANGE...
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3295 (if (get-text-property (point) 'syntax-table)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3296 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3297 (sh-debug "-- removing props from %d to %d --"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3298 (point) next-change)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3299 (remove-text-properties (point) next-change
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3300 '(syntax-table nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3301 (remove-text-properties (point) next-change '(face nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3302 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3303 (goto-char next-change)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3304 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3305
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3306 (defun sh-search-word (word &optional limit)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3307 "Search forward for regexp WORD occuring as a word not in string nor comment.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3308 If found, returns non nil with the match available in \(match-string 2\).
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3309 Yes 2, not 1, since we build a regexp to guard against false matches
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3310 such as matching \"a-case\" when we are searching for \"case\".
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3311 If not found, it returns nil.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3312 The search maybe limited by optional argument LIMIT."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3313 (interactive "sSearch for: ")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3314 (let ((found nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3315 ;; Cannot use \\b here since it matches "-" and "_"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3316 (regexp (sh-mkword-regexp word))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3317 start state where)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3318 (setq start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3319 (while (and (setq start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3320 (not found)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3321 (re-search-forward regexp limit t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3322 ;; Found str; check it is not in a comment or string.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3323 (setq state
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3324 ;; Stop on comment:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3325 (parse-partial-sexp start (point) nil nil nil 'syntax_table))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3326 (if (setq where (nth 8 state))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3327 ;; in comment or string
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3328 (if (= where -1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3329 (setq found (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3330 (if (eq (char-after where) ?#)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3331 (end-of-line)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3332 (goto-char where)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3333 (unless (sh-safe-forward-sexp)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3334 ;; If the above fails we must either give up or
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3335 ;; move forward and try again.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3336 (forward-line 1))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3337 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3338 ;; not in comment or string, so accept it
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3339 (setq found (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3340 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3341 found
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3342 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3343
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3344 (defun sh-scan-case ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3345 "Scan a case statement for right parens belonging to case alternatives.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3346 Mark each as having syntax `sh-special-syntax'.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3347 Called from scan-buff. If ok, return non-nil."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3348 (let (end
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3349 state
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3350 (depth 1) ;; we are called at a "case"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3351 (start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3352 (return t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3353 ;; We enter here at a case statement
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3354 ;; First, find limits of the case.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3355 (while (and (> depth 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3356 (sh-search-word "\\(case\\|esac\\)"))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3357 (if (equal (match-string 2) "case")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3358 (setq depth (1+ depth))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3359 (setq depth (1- depth))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3360 ;; (message "end of search for esac at %d depth=%d" (point) depth)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3361 (setq end (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3362 (goto-char start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3363 ;; if we found the esac, then fix all appropriate ')'s in the region
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3364 (if (zerop depth)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3365 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3366 (while (< (point) end)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3367 ;; search for targetdepth of -1 meaning extra right paren
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3368 (setq state (parse-partial-sexp (point) end -1 nil nil nil))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3369 (if (and (= (car state) -1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3370 (= (char-before) ?\)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3371 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3372 ;; (message "At %d state is %s" (point) state)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3373 ;; (message "Fixing %d" (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3374 (sh-set-char-syntax (1- (point)) sh-special-syntax)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3375 ;; we could advance to the next ";;" perhaps
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3376 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3377 ;; (message "? Not found at %d" (point)) ; ok, could be "]"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3378 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3379 (goto-char end))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3380 (message "No matching esac for case at %d" start)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3381 (setq return nil)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3382 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3383 return
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3384 ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3385
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3386
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3387 (defun sh-scan-buffer ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3388 "Scan a sh buffer for case statements and here-documents.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3389
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3390 For each case alternative found, mark its \")\" with a text property
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3391 so that its syntax class is no longer a close parenthesis character.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3392
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3393 Each here-document is also marked so that it is effectively immune
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3394 from indenation changes."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3395 ;; Do not call this interactively, call `sh-rescan-buffer' instead.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3396 (sh-must-be-shell-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3397 (let ((n 0)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3398 (initial-buffer-modified-p (buffer-modified-p))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3399 start end where label ws)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3400 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3401 (goto-char (point-min))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3402 ;; 1. Scan for ")" in case statements.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3403 (while (and ;; (re-search-forward "^[^#]*\\bcase\\b" nil t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3404 (sh-search-word "\\(case\\|esac\\)")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3405 ;; (progn (message "Found a case at %d" (point)) t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3406 (sh-scan-case)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3407 ;; 2. Scan for here docs
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3408 (goto-char (point-min))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3409 ;; while (re-search-forward "<<\\(-?\\)\\(\\s-*\\)\\(.*\\)$" nil t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3410 (while (re-search-forward "<<\\(-?\\)" nil t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3411 (unless (sh-in-comment-or-string (match-beginning 0))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3412 ;; (setq label (match-string 3))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3413 (setq label (sh-get-word))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3414 (if (string= (match-string 1) "-")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3415 ;; if <<- then we allow whitespace
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3416 (setq ws "\\s-*")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3417 ;; otherwise we don't
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3418 (setq ws ""))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3419 (while (string-match "['\"\\]" label)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3420 (setq label (replace-match "" nil nil label)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3421 (if (setq n (string-match "\\s-+$" label))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3422 (setq label (substring label 0 n)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3423 (forward-line 1)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3424 ;; the line containing the << could be continued...
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3425 (while (sh-this-is-a-continuation)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3426 (forward-line 1))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3427 (setq start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3428 (if (re-search-forward (concat "^" ws (regexp-quote label)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3429 "\\s-*$")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3430 nil t)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3431 (sh-set-here-doc-region start (point))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3432 (sh-debug "missing here-doc delimiter `%s'" label))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3433 ;; 3. Scan for $# -- make the "#" a punctuation not a comment
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3434 (goto-char (point-min))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3435 (let (state)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3436 (while (and (not (eobp))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3437 (setq state (parse-partial-sexp
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3438 (1+ (point))(point-max) nil nil nil t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3439 (nth 4 state))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3440 (goto-char (nth 8 state))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3441 (sh-debug "At %d %s" (point) (eq (char-before) ?$))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3442 (if (eq (char-before) ?$)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3443 (sh-set-char-syntax (point) sh-st-punc) ;; not a comment!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3444 (end-of-line) ;; if this *was* a comment, ignore rest of line!
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3445 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3446 ;; 4. Hide these changes from making a previously unmodified
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3447 ;; buffer into a modified buffer.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3448 (if sh-debug
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3449 (if initial-buffer-modified-p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3450 (message "buffer was initially modified")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3451 (message
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3452 "buffer not initially modified - so clearing modified flag")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3453 (set-buffer-modified-p initial-buffer-modified-p)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3454 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3455
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3456 (defun sh-rescan-buffer ()
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3457 "Rescan the buffer for case alternative parentheses and here documents."
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3458 (interactive)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3459 (if (eq major-mode 'sh-mode)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3460 (let ((inhibit-read-only t))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3461 (sh-remove-our-text-properties)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3462 (message "Re-scanning buffer...")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3463 (sh-scan-buffer)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3464 (message "Re-scanning buffer...done")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3465 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3466
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3467 ;; ========================================================================
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3468
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3469 ;; Styles -- a quick and dirty way of saving the indenation settings.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3470
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3471 (defvar sh-styles-alist nil
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3472 "A list of all known shell indentation styles.")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3473
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3474 (defun sh-name-style (name &optional confirm-overwrite)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3475 "Name the current indentation settings as a style called NAME.
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3476 If this name exists, the command will prompt whether it should be
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3477 overwritten if
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3478 - - it was called interactively with a prefix argument, or
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3479 - - 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
3480 ;; (interactive "sName for this style: ")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3481 (interactive
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3482 (list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3483 (read-from-minibuffer "Name for this style? " )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3484 (not current-prefix-arg)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3485 (let ((slist (list name))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3486 (p sh-var-list)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3487 var style)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3488 (while p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3489 (setq var (car p))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3490 (setq slist (append slist (list (cons var (symbol-value var)))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3491 (setq p (cdr p)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3492 (if (setq style (assoc name sh-styles-alist))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3493 (if (or (not confirm-overwrite)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3494 (y-or-n-p "This style exists. Overwrite it? "))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3495 (progn
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3496 (message "Updating style %s" name)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3497 (setcdr style (cdr slist)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3498 (message "Not changing style %s" name))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3499 (message "Creating new style %s" name)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3500 (setq sh-styles-alist (append sh-styles-alist
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3501 (list slist)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3502 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3503
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3504 (defun sh-load-style (name)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3505 "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
3506 (interactive (list (completing-read
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3507 "Which style to use for this buffer? "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3508 sh-styles-alist nil t)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3509 (let ((sl (assoc name sh-styles-alist)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3510 (if (null sl)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3511 (error "sh-load-style - style %s not known" name)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3512 (setq sl (cdr sl))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3513 (while sl
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3514 (set (car (car sl)) (cdr (car sl)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3515 (setq sl (cdr sl))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3516 ))))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3517
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3518 (defun sh-save-styles-to-buffer (buff)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3519 "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
3520 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
3521 (interactive (list
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3522 (read-from-minibuffer "Buffer to save styles in? " "*scratch*")))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3523 ;; This is an attempt to sort of pretty print it...
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3524 (save-excursion
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3525 (set-buffer (get-buffer-create buff))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3526 (goto-char (point-max))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3527 (insert "\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3528 (let ((p sh-styles-alist) q)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3529 (insert "(setq sh-styles-alist '(\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3530 (while p
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3531 (setq q (car p))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3532 (insert " ( " (prin1-to-string (car q)) "\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3533 (setq q (cdr q))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3534 (while q
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3535 (insert " "(prin1-to-string (car q)) "\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3536 (setq q (cdr q)))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3537 (insert " )\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3538 (setq p (cdr p))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3539 )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3540 (insert "))\n")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3541 )))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3542
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3543
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3544
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3545
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3546 ;; statement syntax-commands for various shells
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3547
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3548 ;; 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
3549 ;; appropriate for your favorite shell.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3550
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3551 (define-skeleton sh-case
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3552 "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
3553 (csh "expression: "
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3554 "switch( " str " )" \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3555 > "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
3556 > _ \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3557 "breaksw" \n
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3558 ( "other pattern, %s: "
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3559 < "case " str ?: \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3560 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3561 "breaksw" \n)
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3562 < "default:" \n
17531
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3563 > _ \n
b891e41b4011 (sh-case): Make this a simple define-skeleton
Richard M. Stallman <rms@gnu.org>
parents: 17501
diff changeset
3564 resume:
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3565 < < "endsw")
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3566 (es)
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3567 (rc "expression: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3568 > "switch( " str " ) {" \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3569 > "case " (read-string "pattern: ") \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3570 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3571 ( "other pattern, %s: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3572 "case " str > \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3573 > _ \n)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3574 "case *" > \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3575 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3576 resume:
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3577 ?} > )
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3578 (sh "expression: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3579 > "case " str " in" \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3580 > (read-string "pattern: ")
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3581 '(sh-electric-rparen)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3582 \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3583 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3584 ";;" \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3585 ( "other pattern, %s: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3586 > str '(sh-electric-rparen) \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3587 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3588 ";;" \n)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3589 > "*" '(sh-electric-rparen) \n
20771
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3590 > _ \n
c6d9f48bd2f8 (sh-case): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
3591 resume:
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3592 "esac" > ))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3593
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3594 (define-skeleton sh-for
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3595 "Insert a for loop. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3596 (csh eval sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3597 1 ""
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3598 2 "foreach "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3599 4 " ( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3600 6 " )"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3601 15 '<
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3602 16 "end"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3603 )
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3604 (es eval sh-modify rc
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3605 4 " = ")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3606 (rc eval sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3607 2 "for( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3608 6 " ) {"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3609 15 ?} )
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3610 (sh "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3611 > "for " str " in " _ "; do" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3612 > _ | ?$ & (sh-remember-variable str) \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3613 "done" > ))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3614
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3615
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3616
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3617 (define-skeleton sh-indexed-loop
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3618 "Insert an indexed loop from 1 to n. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3619 (bash eval identity posix)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3620 (csh "Index variable: "
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3621 "@ " str " = 1" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3622 "while( $" str " <= " (read-string "upper limit: ") " )" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3623 > _ ?$ str \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3624 "@ " str "++" \n
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3625 < "end")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3626 (es eval sh-modify rc
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3627 4 " =")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3628 (ksh88 "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3629 > "integer " str "=0" \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3630 > "while (( ( " str " += 1 ) <= "
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3631 (read-string "upper limit: ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3632 " )); do" \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3633 > _ ?$ (sh-remember-variable str) > \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3634 "done" > )
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3635 (posix "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3636 > str "=1" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3637 "while [ $" str " -le "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3638 (read-string "upper limit: ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3639 " ]; do" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3640 > _ ?$ str \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3641 str ?= (sh-add (sh-remember-variable str) 1) \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3642 "done" > )
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3643 (rc "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3644 > "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
3645 (read-string "upper limit: ")
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3646 "; i++ ) print i }'`}) {" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3647 > _ ?$ (sh-remember-variable str) \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3648 ?} >)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3649 (sh "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3650 > "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
3651 (read-string "upper limit: ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3652 "; i++ ) print i }'`; do" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3653 > _ ?$ (sh-remember-variable str) \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3654 "done" > ))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3655
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3656
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3657 (defun sh-shell-initialize-variables ()
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3658 "Scan the buffer for variable assignments.
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3659 Add these variables to `sh-shell-variables'."
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3660 (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
3661 (save-excursion
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3662 (goto-char (point-min))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3663 (setq sh-shell-variables-initialized t)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3664 (while (search-forward "=" nil t)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3665 (sh-assignment 0)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3666 (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
3667 (buffer-name)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3668
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3669 (defvar sh-add-buffer)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3670
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3671 (defun sh-add-completer (string predicate code)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3672 "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
3673 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
3674 so it takes three arguments:
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3675 STRING, the current buffer contents;
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3676 PREDICATE, the predicate for filtering possible matches;
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3677 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
3678 CODE can be nil, t or `lambda'.
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3679 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
3680 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
3681 `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
3682 (let ((sh-shell-variables
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3683 (save-excursion
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3684 (set-buffer sh-add-buffer)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3685 (or sh-shell-variables-initialized
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3686 (sh-shell-initialize-variables))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3687 (nconc (mapcar (lambda (var)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3688 (let ((name
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3689 (substring var 0 (string-match "=" var))))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3690 (cons name name)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3691 process-environment)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3692 sh-shell-variables))))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3693 (cond ((null code)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3694 (try-completion string sh-shell-variables predicate))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3695 ((eq code t)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3696 (all-completions string sh-shell-variables predicate))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3697 ((eq code 'lambda)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3698 (assoc string sh-shell-variables)))))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3699
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3700 (defun sh-add (var delta)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3701 "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
3702 (interactive
14418
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3703 (let ((sh-add-buffer (current-buffer)))
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3704 (list (completing-read "Variable: " 'sh-add-completer)
7f58ca0014ef (sh-shell-variables-initialized): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14221
diff changeset
3705 (prefix-numeric-value current-prefix-arg))))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3706 (insert (sh-feature '((bash . "$[ ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3707 (ksh88 . "$(( ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3708 (posix . "$(( ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3709 (rc . "`{expr $")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3710 (sh . "`expr $")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3711 (zsh . "$[ ")))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3712 (sh-remember-variable var)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3713 (if (< delta 0) " - " " + ")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3714 (number-to-string (abs delta))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3715 (sh-feature '((bash . " ]")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3716 (ksh88 . " ))")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3717 (posix . " ))")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3718 (rc . "}")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3719 (sh . "`")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3720 (zsh . " ]")))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3721
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3722
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3723
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3724 (define-skeleton sh-function
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3725 "Insert a function definition. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3726 (bash eval sh-modify ksh88
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3727 3 "() {")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3728 (ksh88 "name: "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3729 "function " str " {" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3730 > _ \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3731 < "}")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3732 (rc eval sh-modify ksh88
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3733 1 "fn ")
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3734 (sh ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3735 "() {" \n
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3736 > _ \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3737 < "}"))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3738
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3739
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3740
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3741 (define-skeleton sh-if
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3742 "Insert an if statement. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3743 (csh "condition: "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3744 "if( " str " ) then" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3745 > _ \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3746 ( "other condition, %s: "
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3747 < "else if( " str " ) then" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3748 > _ \n)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3749 < "else" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3750 > _ \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3751 resume:
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3752 < "endif")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3753 (es "condition: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3754 > "if { " str " } {" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3755 > _ \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3756 ( "other condition, %s: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3757 "} { " str " } {" > \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3758 > _ \n)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3759 "} {" > \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3760 > _ \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3761 resume:
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3762 ?} > )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3763 (rc "condition: "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3764 > "if( " str " ) {" \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3765 > _ \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3766 ( "other condition, %s: "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3767 "} else if( " str " ) {" > \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3768 > _ \n)
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3769 "} else {" > \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3770 > _ \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3771 resume:
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3772 ?} >
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3773 )
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3774 (sh "condition: "
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3775 '(setq input (sh-feature sh-test))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3776 > "if " str "; then" \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3777 > _ \n
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3778 ( "other condition, %s: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3779 > "elif " str "; then" > \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3780 > \n)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3781 "else" > \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3782 > \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3783 resume:
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3784 "fi" > ))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3785
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3786
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3787
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3788 (define-skeleton sh-repeat
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3789 "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
3790 (es nil
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3791 > "forever {" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3792 > _ \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3793 ?} > )
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3794 (zsh "factor: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3795 > "repeat " str "; do" > \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3796 > \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3797 "done" > ))
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3798
17501
478f9bb8575c Remove all menu-enable properties except for sh-case.
Richard M. Stallman <rms@gnu.org>
parents: 17480
diff changeset
3799 ;;;(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
3800
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3801
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3802
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3803 (define-skeleton sh-select
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3804 "Insert a select statement. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3805 (ksh88 "Index variable: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3806 > "select " str " in " _ "; do" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3807 > ?$ str \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3808 "done" > )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3809 (bash eval sh-append ksh88)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3810 )
17501
478f9bb8575c Remove all menu-enable properties except for sh-case.
Richard M. Stallman <rms@gnu.org>
parents: 17480
diff changeset
3811 ;;;(put 'sh-select 'menu-enable '(sh-feature sh-select))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3812
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3813
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3814
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3815 (define-skeleton sh-tmp-file
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3816 "Insert code to setup temporary file handling. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3817 (bash eval identity ksh88)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3818 (csh (file-name-nondirectory (buffer-file-name))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3819 "set tmp = /tmp/" str ".$$" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3820 "onintr exit" \n _
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3821 (and (goto-char (point-max))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3822 (not (bolp))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3823 ?\n)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3824 "exit:\n"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3825 "rm $tmp* >&/dev/null" >)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3826 (es (file-name-nondirectory (buffer-file-name))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3827 > "local( signals = $signals sighup sigint; tmp = /tmp/" str
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3828 ".$pid ) {" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3829 > "catch @ e {" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3830 > "rm $tmp^* >[2]/dev/null" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3831 "throw $e" \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3832 "} {" > \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3833 _ \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3834 ?} > \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3835 ?} > )
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3836 (ksh88 eval sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3837 7 "EXIT")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3838 (rc (file-name-nondirectory (buffer-file-name))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3839 > "tmp = /tmp/" str ".$pid" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3840 "fn sigexit { rm $tmp^* >[2]/dev/null }")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3841 (sh (file-name-nondirectory (buffer-file-name))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3842 > "TMP=${TMPDIR:-/tmp}/" str ".$$" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3843 "trap \"rm $TMP* 2>/dev/null\" " ?0))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3844
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3845
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3846
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3847 (define-skeleton sh-until
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3848 "Insert an until loop. See `sh-feature'."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3849 (sh "condition: "
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3850 '(setq input (sh-feature sh-test))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3851 > "until " str "; do" \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3852 > _ \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3853 "done" > ))
17501
478f9bb8575c Remove all menu-enable properties except for sh-case.
Richard M. Stallman <rms@gnu.org>
parents: 17480
diff changeset
3854 ;;;(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
3855
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3856
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3857
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3858 (define-skeleton sh-while
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3859 "Insert a while loop. See `sh-feature'."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3860 (csh eval sh-modify sh
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3861 2 ""
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3862 3 "while( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3863 5 " )"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3864 10 '<
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3865 11 "end" )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3866 (es eval sh-modify sh
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3867 3 "while { "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3868 5 " } {"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3869 10 ?} )
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3870 (rc eval sh-modify sh
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3871 3 "while( "
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3872 5 " ) {"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3873 10 ?} )
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3874 (sh "condition: "
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3875 '(setq input (sh-feature sh-test))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3876 > "while " str "; do" \n
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3877 > _ \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3878 "done" > ))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3879
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3880
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3881
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3882 (define-skeleton sh-while-getopts
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3883 "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
3884 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
3885 option followed by a colon `:' if the option accepts an argument."
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3886 (bash eval sh-modify sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3887 18 "${0##*/}")
12863
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3888 (csh nil
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3889 "while( 1 )" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3890 > "switch( \"$1\" )" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3891 '(setq input '("- x" . 2))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3892 > >
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3893 ( "option, %s: "
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3894 < "case " '(eval str)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3895 '(if (string-match " +" str)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3896 (setq v1 (substring str (match-end 0))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3897 str (substring str 0 (match-beginning 0)))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3898 (setq v1 nil))
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3899 str ?: \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3900 > "set " v1 & " = $2" | -4 & _ \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3901 (if v1 "shift") & \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3902 "breaksw" \n)
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3903 < "case --:" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3904 > "shift" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3905 < "default:" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3906 > "break" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3907 resume:
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3908 < < "endsw" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3909 "shift" \n
bcf5d042f057 (sh-test): New variable.
Karl Heuer <kwzh@gnu.org>
parents: 12812
diff changeset
3910 < "end")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3911 (ksh88 eval sh-modify sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3912 16 "print"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3913 18 "${0##*/}"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3914 36 "OPTIND-1")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3915 (posix eval sh-modify sh
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3916 18 "$(basename $0)")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3917 (sh "optstring: "
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3918 > "while getopts :" str " OPT; do" \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3919 > "case $OPT in" \n
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3920 '(setq v1 (append (vconcat str) nil))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3921 ( (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
3922 (if (eq (nth 1 v1) ?:)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3923 (setq v1 (nthcdr 2 v1)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3924 v2 "\"$OPTARG\"")
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3925 (setq v1 (cdr v1)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3926 v2 nil)))
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3927 > str "|+" str '(sh-electric-rparen) \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3928 > _ v2 \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3929 > ";;" \n)
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3930 > "*" '(sh-electric-rparen) \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3931 > "echo" " \"usage: " "`basename $0`"
15027
30c4f64f3579 (sh-while-getopts): Punctuate help message better.
Richard M. Stallman <rms@gnu.org>
parents: 14892
diff changeset
3932 " [+-" '(setq v1 (point)) str
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3933 '(save-excursion
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3934 (while (search-backward ":" v1 t)
15027
30c4f64f3579 (sh-while-getopts): Punctuate help message better.
Richard M. Stallman <rms@gnu.org>
parents: 14892
diff changeset
3935 (replace-match " ARG] [+-" t t)))
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3936 (if (eq (preceding-char) ?-) -5)
15027
30c4f64f3579 (sh-while-getopts): Punctuate help message better.
Richard M. Stallman <rms@gnu.org>
parents: 14892
diff changeset
3937 "] [--] ARGS...\"" \n
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3938 "exit 2" > \n
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3939 "esac" >
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3940 \n "done"
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
3941 > \n
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3942 "shift " (sh-add "OPTIND" -1)))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3943
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3944
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3945
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3946 (defun sh-assignment (arg)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3947 "Remember preceding identifier for future completion and do self-insert."
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3948 (interactive "p")
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3949 (self-insert-command arg)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3950 (if (<= arg 1)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3951 (sh-remember-variable
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3952 (save-excursion
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3953 (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
3954 (prog1 (point)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3955 (beginning-of-line 1))
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3956 t)
13391
550ecb2269b0 (sh-shells): Eliminated variable redundant with
Karl Heuer <kwzh@gnu.org>
parents: 13389
diff changeset
3957 (match-string 1))))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3958
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3959
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3960
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3961 (defun sh-maybe-here-document (arg)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3962 "Inserts self. Without prefix, following unquoted `<' inserts here document.
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3963 The document is bounded by `sh-here-document-word'."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3964 (interactive "*P")
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3965 (self-insert-command (prefix-numeric-value arg))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3966 (or arg
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3967 (not (eq (char-after (- (point) 2)) last-command-char))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3968 (save-excursion
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3969 (backward-char 2)
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3970 (sh-quoted-p))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3971 (progn
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3972 (insert sh-here-document-word)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3973 (or (eolp) (looking-at "[ \t]") (insert ? ))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3974 (end-of-line 1)
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3975 (while
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3976 (sh-quoted-p)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3977 (end-of-line 2))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3978 (newline)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3979 (save-excursion (insert ?\n sh-here-document-word)))))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3980
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3981
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3982 ;; various other commands
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3983
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3984 (autoload 'comint-dynamic-complete "comint"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3985 "Dynamically perform completion at point." t)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3986
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3987 (autoload 'shell-dynamic-complete-command "shell"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3988 "Dynamically complete the command at point." t)
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3989
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3990 (autoload 'comint-dynamic-complete-filename "comint"
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3991 "Dynamically complete the filename at point." t)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3992
12505
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3993 (autoload 'shell-dynamic-complete-environment-variable "shell"
0f970ed476cb restructured, largely rewritten without the bugs and
Karl Heuer <kwzh@gnu.org>
parents: 12034
diff changeset
3994 "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
3995
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3996
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3997
12887
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3998 (defun sh-newline-and-indent ()
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
3999 "Strip unquoted whitespace, insert newline, and indent like current line."
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
4000 (interactive "*")
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
4001 (indent-to (prog1 (current-indentation)
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
4002 (delete-region (point)
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
4003 (progn
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
4004 (or (zerop (skip-chars-backward " \t"))
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
4005 (if (sh-quoted-p)
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
4006 (forward-char)))
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
4007 (point)))
cbed067bf52d (sh-newline-and-indent): Don't interpret prefix arg
Karl Heuer <kwzh@gnu.org>
parents: 12864
diff changeset
4008 (newline))))
6463
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4009
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4010 (defun sh-beginning-of-command ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4011 "Move point to successive beginnings of commands."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4012 (interactive)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4013 (if (re-search-backward sh-beginning-of-command nil t)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4014 (goto-char (match-beginning 2))))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4015
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4016 (defun sh-end-of-command ()
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4017 "Move point to successive ends of commands."
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4018 (interactive)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4019 (if (re-search-forward sh-end-of-command nil t)
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4020 (goto-char (match-end 1))))
380e8fcde9a2 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4021
13707
9356c7d7dcd6 Provide sh-script.
Karl Heuer <kwzh@gnu.org>
parents: 13705
diff changeset
4022 (provide 'sh-script)
18382
0e4943a370e2 Whitespace change.
Richard M. Stallman <rms@gnu.org>
parents: 18024
diff changeset
4023
25986
29aeb35781cd Added support for indenting existing scripts.
Gerd Moellmann <gerd@gnu.org>
parents: 25554
diff changeset
4024 ;;; sh-script.el ends here