Jérôme,
I was just trying to apply your patch to the latest version in CVS in
preparation for committing it, however the following chunks were rejected. Do
you have any idea why?
Malcolm
***************
*** 40,64 ****
;; - Variables in `"' strings aren't fontified because there's no way
of
;; syntactically distinguishing those from `'' strings.
;;; Code:
;; page 1: variables and settings
- ;; page 2: mode-command and utility functions
- ;; page 3: statement syntax-commands for various shells
- ;; page 4: various other commands
-
(require 'executable)
- (require 'skeleton)
- (defcustom sh-mode-hook nil
- "*Hook run by `sh-mode'."
-:type 'hook
-:group 'sh)
- (defcustom sh-set-shell-hook nil
- "*Hook run by `sh-set-shell'."
-:type 'hook
-:group 'sh)
(defgroup sh nil
"Shell programming utilities"
--- 41,206 ----
;; - Variables in `"' strings aren't fontified because there's no way
of
;; syntactically distinguishing those from `'' strings.
+ ;; Indentation
+ ;; ===========
+ ;; Indentation for rc and es modes is very limited, but for Bourne shells
+ ;; and its derivatives it is quite customizable.
+ ;;
+ ;; The following description applies to sh and derived shells (bash,
+ ;; zsh, ...).
+ ;;
+ ;; There are various customization variables which allow tailoring to
+ ;; a wide variety of styles. Most of these variables are named
+ ;; sh-indent-for-XXX and sh-indent-after-XXX. For example.
+ ;; sh-indent-after-if controls the indenting of a line following
+ ;; an if statement, and sh-indent-for-fi controls the indentation
+ ;; of the line containing the fi.
+ ;;
+ ;; You can set each to a numeric value, but it is often more convenient
+ ;; to a symbol such as `+' which uses the value of variable `sh-basic-offset'.
+ ;; By changing this one variable you can increase or decrease how much
+ ;; indentation there is. Valid symbols:
+ ;;
+ ;; + Indent right by sh-basic-offset
+ ;; - Indent left by sh-basic-offset
+ ;; ++ Indent right twice sh-basic-offset
+ ;; -- Indent left twice sh-basic-offset
+ ;; * Indent right half sh-basic-offset
+ ;; / Indent left half sh-basic-offset.
+ ;;
+ ;; There are 4 commands to help set the indentation variables:
+ ;;
+ ;; `sh-show-indent'
+ ;; This shows what variable controls the indentation of the current
+ ;; line and its value.
+ ;;
+ ;; `sh-set-indent'
+ ;; This allows you to set the value of the variable controlling the
+ ;; current line's indentation. You can enter a number or one of a
+ ;; number of special symbols to denote the value of sh-basic-offset,
+ ;; or its negative, or half it, or twice it, etc. If you've used
+ ;; cc-mode this should be familiar. If you forget which symbols are
+ ;; valid simply press C-h at the prompt.
+ ;;
+ ;; `sh-learn-line-indent'
+ ;; Simply make the line look the way you want it, then invoke this
+ ;; command. It will set the variable to the value that makes the line
+ ;; indent like that. If called with a prefix argument then it will set
+ ;; the value to one of the symbols if applicable.
+ ;;
+ ;; `sh-learn-buffer-indent'
+ ;; This is the deluxe function! It "learns" the whole buffer (use
+ ;; narrowing if you want it to process only part). It outputs to a
+ ;; buffer *indent* any conflicts it finds, and all the variables it has
+ ;; learned. This buffer is a sort of Occur mode buffer, allowing you to
+ ;; easily find where something was set. It is popped to automatically
+ ;; if there are any conflicts found or if `sh-popup-occur-buffer' is
+ ;; non-nil.
+ ;; `sh-indent-comment' will be set if all comments follow the same
+ ;; pattern; if they don't it will be set to nil.
+ ;; Whether `sh-basic-offset' is set is determined by variable
+ ;; `sh-learn-basic-offset'.
+ ;;
+ ;; Unfortunately, `sh-learn-buffer-indent' can take a long time to run
+ ;; (e.g. if there are large case statements). Perhaps it does not make
+ ;; sense to run it on large buffers: if lots of lines have different
+ ;; indentation styles it will produce a lot of diagnostics in the
+ ;; *indent* buffer; if there is a consistent style then running
+ ;; `sh-learn-buffer-indent' on a small region of the buffer should
+ ;; suffice.
+ ;;
+ ;; Saving indentation values
+ ;; -------------------------
+ ;; After you've learned the values in a buffer, how to you remember
+ ;; them? Originally I had hoped that `sh-learn-buffer-indent'
+ ;; would make this unnecessary; simply learn the values when you visit
+ ;; the buffer.
+ ;; You can do this automatically like this:
+ ;; (add-hook 'sh-set-shell-hook 'sh-learn-buffer-indent)
+ ;;
+ ;; However... `sh-learn-buffer-indent' is extremely slow,
+ ;; especially on large-ish buffer. Also, if there are conflicts the
+ ;; "last one wins" which may not produce the desired setting.
+ ;;
+ ;; So...There is a minimal way of being able to save indentation values and
+ ;; to reload them in another buffer or at another point in time.
+ ;;
+ ;; Use `sh-name-style' to give a name to the indentation settings of
+ ;; the current buffer.
+ ;; Use `sh-load-style' to load indentation settings for the current
+ ;; buffer from a specific style.
+ ;; Use `sh-save-styles-to-buffer' to write all the styles to a buffer
+ ;; in lisp code. You can then store it in a file and later use
+ ;; `load-file' to load it.
+ ;;
+ ;; Indentation variables - buffer local or global?
+ ;; ----------------------------------------------
+ ;; I think that often having them buffer-local makes sense,
+ ;; especially if one is using `sh-learn-buffer-indent'. However, if
+ ;; a user sets values using customization, these changes won't appear
+ ;; to work if the variables are already local!
+ ;;
+ ;; To get round this, there is a variable `sh-make-vars-local' and 2
+ ;; functions: `sh-make-vars-local' and `sh-reset-indent-vars-to-global-values'.
+ ;;
+ ;; If `sh-make-vars-local' is non-nil, then these variables become
+ ;; buffer local when the mode is established.
+ ;; If this is nil, then the variables are global. At any time you
+ ;; can make them local with the command `sh-make-vars-local'.
+ ;; Conversely, to update with the global values you can use the
+ ;; command `sh-reset-indent-vars-to-global-values'.
+ ;;
+ ;; This may be awkward, but the intent is to cover all cases.
+ ;;
+ ;; Awkward things, pitfalls
+ ;; ------------------------
+ ;; Indentation for a sh script is complicated for a number of reasons:
+ ;;
+ ;; 1. You can't format by simply looking at symbols, you need to look
+ ;; at keywords. [This is not the case for rc and es shells.]
+ ;; 2. The character ")" is used both as a matched pair "(" ...
")" and
+ ;; as a stand-alone symbol (in a case alternative). This makes
+ ;; things quite tricky!
+ ;; 3. Here-documents in a script should be treated "as is", and when
+ ;; they terminate we want to revert to the indentation of the line
+ ;; containing the "<<" symbol.
+ ;; 4. A line may be continued using the "\".
+ ;; 5. The character "#" (outside a string) normally starts a comment,
+ ;; but it doesn't in the sequence "$#"!
+ ;;
+ ;; To try and address points 2 3 and 5 I used a feature that cperl mode
+ ;; uses, that of a text's syntax property. This, however, has 2
+ ;; disadvantages:
+ ;; 1. We need to scan the buffer to find which ")" symbols belong to a
+ ;; case alternative, to find any here documents, and handle "$#".
+ ;; 2. Setting the text property makes the buffer modified. If the
+ ;; buffer is read-only buffer we have to cheat and bypass the read-only
+ ;; status. This is for cases where the buffer started read-only buffer
+ ;; but the user issued `toggle-read-only'.
+ ;;
+ ;; Bugs
+ ;; ----
+ ;; - Indenting many lines is slow. It currently does each line
+ ;; independently, rather than saving state information.
+ ;;
+ ;; - `sh-learn-buffer-indent' is extremely slow.
+ ;;
+ ;; Richard Sharman <rsharman(a)pobox.com> June 1999.
+
;;; Code:
;; page 1: variables and settings
+ ;; page 2: indentation stuff
+ ;; page 3: mode-command and utility functions
+ ;; page 4: statement syntax-commands for various shells
+ ;; page 5: various other commands
+
+ (eval-when-compile
+ (require 'skeleton)
+ (require 'comint))
(require 'executable)
(defgroup sh nil
"Shell programming utilities"
***************
*** 226,243 ****
:group 'sh-script)
(defcustom sh-imenu-generic-expression
- (list
- (cons 'sh
- (concat
- "\\(^\\s-*function\\s-+[A-Za-z_][A-Za-z_0-9]*\\)"
- "\\|"
- "\\(^\\s-*[A-Za-z_][A-Za-z_0-9]*\\s-*()\\)")))
- "*Regular expression for recognizing shell function definitions.
- See `sh-feature'."
-:type '(repeat (cons (symbol :tag "Shell")
- regexp))
:group 'sh-script
-:version "20.3")
(defvar sh-shell-variables nil
"Alist of shell variable names that should be included in completion.
--- 366,383 ----
:group 'sh-script)
(defcustom sh-imenu-generic-expression
+ `((sh
+ . ((nil "^\\s-*\\(function\\s-+\\)?\\([A-Za-z_][A-Za-z_0-9]+\\)\\s-*()"
2))))
+ "*Alist of regular expressions for recognizing shell function definitions.
+ See `sh-feature' and `imenu-generic-expression'."
+:type '(alist :key-type (symbol :tag "Shell")
+:value-type (alist :key-type (choice :tag "Title"
+ string
+ (const :tag "None" nil))
+:value-type
+ (repeat :tag "Regexp, index..." sexp)))
:group 'sh-script
+:version "20.4")
(defvar sh-shell-variables nil
"Alist of shell variable names that should be included in completion.
--
Malcolm Purvis <malcolmp(a)xemacs.org>