Mercurial > emacs
changeset 81380:db32b7ba9c76
Remove unneeded * from docstrings. Use [:alpha:] & [:alnum:] where applicable.
(sh-quoted-subshell): Rewrite to handle nested mixes of `...` and $(...).
(sh-apply-quoted-subshell): Remove.
(sh-font-lock-syntactic-keywords): Adjust call to sh-quoted-subshell.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 13 Jun 2007 18:25:46 +0000 |
parents | fa58a242b75e |
children | bf9ea781e3e0 |
files | lisp/ChangeLog lisp/progmodes/sh-script.el |
diffstat | 2 files changed, 97 insertions(+), 108 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/ChangeLog Wed Jun 13 18:00:34 2007 +0000 +++ b/lisp/ChangeLog Wed Jun 13 18:25:46 2007 +0000 @@ -1,5 +1,12 @@ 2007-06-13 Stefan Monnier <monnier@iro.umontreal.ca> + * progmodes/sh-script.el: Remove unneeded * from docstrings. + Use [:alpha:] and [:alnum:] where applicable. + (sh-quoted-subshell): Rewrite to correctly + handle nested mixes of `...` and $(...). + (sh-apply-quoted-subshell): Remove. + (sh-font-lock-syntactic-keywords): Adjust call to sh-quoted-subshell. + * vc-arch.el (vc-arch-command): Remove bzr. It's a different program. 2007-06-12 Tom Tromey <tromey@redhat.com>
--- a/lisp/progmodes/sh-script.el Wed Jun 13 18:00:34 2007 +0000 +++ b/lisp/progmodes/sh-script.el Wed Jun 13 18:25:46 2007 +0000 @@ -235,7 +235,7 @@ (wsh . sh) (zsh . ksh88) (rpm . sh)) - "*Alist showing the direct ancestor of various shells. + "Alist showing the direct ancestor of various shells. This is the basis for `sh-feature'. See also `sh-alias-alist'. By default we have the following three hierarchies: @@ -270,7 +270,7 @@ '((ksh . ksh88) (bash2 . bash) (sh5 . sh))) - "*Alist for transforming shell names to what they really are. + "Alist for transforming shell names to what they really are. Use this where the name of the executable doesn't correspond to the type of shell it really is." :type '(repeat (cons symbol symbol)) @@ -296,7 +296,7 @@ (file-name-sans-extension (downcase shell))))) (getenv "SHELL") "/bin/sh") - "*The executable file name for the shell being programmed." + "The executable file name for the shell being programmed." :type 'string :group 'sh-script) @@ -315,7 +315,7 @@ (wksh) ;; -f means don't run .zshrc. (zsh . "-f")) - "*Single argument string for the magic number. See `sh-feature'." + "Single argument string for the magic number. See `sh-feature'." :type '(repeat (cons (symbol :tag "Shell") (choice (const :tag "No Arguments" nil) (string :tag "Arguments") @@ -324,8 +324,8 @@ (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. + . ((nil "^\\s-*\\(function\\s-+\\)?\\([[:alpha:]_][[:alnum:]_]+\\)\\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" @@ -501,7 +501,7 @@ '(shell-dynamic-complete-environment-variable shell-dynamic-complete-command comint-dynamic-complete-filename) - "*Functions for doing TAB dynamic completion." + "Functions for doing TAB dynamic completion." :type '(repeat function) :group 'sh-script) @@ -509,7 +509,7 @@ (defcustom sh-require-final-newline '((csh . t) (pdksh . t)) - "*Value of `require-final-newline' in Shell-Script mode buffers. + "Value of `require-final-newline' in Shell-Script mode buffers. \(SHELL . t) means use the value of `mode-require-final-newline' for SHELL. See `sh-feature'." :type '(repeat (cons (symbol :tag "Shell") @@ -519,12 +519,12 @@ (defcustom sh-assignment-regexp - '((csh . "\\<\\([a-zA-Z0-9_]+\\)\\(\\[.+\\]\\)?[ \t]*[-+*/%^]?=") + '((csh . "\\<\\([[:alnum:]_]+\\)\\(\\[.+\\]\\)?[ \t]*[-+*/%^]?=") ;; actually spaces are only supported in let/(( ... )) - (ksh88 . "\\<\\([a-zA-Z0-9_]+\\)\\(\\[.+\\]\\)?[ \t]*\\([-+*/%&|~^]\\|<<\\|>>\\)?=") - (rc . "\\<\\([a-zA-Z0-9_*]+\\)[ \t]*=") - (sh . "\\<\\([a-zA-Z0-9_]+\\)=")) - "*Regexp for the variable name and what may follow in an assignment. + (ksh88 . "\\<\\([[:alnum:]_]+\\)\\(\\[.+\\]\\)?[ \t]*\\([-+*/%&|~^]\\|<<\\|>>\\)?=") + (rc . "\\<\\([[:alnum:]_*]+\\)[ \t]*=") + (sh . "\\<\\([[:alnum:]_]+\\)=")) + "Regexp for the variable name and what may follow in an assignment. First grouping matches the variable name. This is upto and including the `=' sign. See `sh-feature'." :type '(repeat (cons (symbol :tag "Shell") @@ -540,7 +540,7 @@ (defcustom sh-remember-variable-min 3 - "*Don't remember variables less than this length for completing reads." + "Don't remember variables less than this length for completing reads." :type 'integer :group 'sh-script) @@ -551,16 +551,16 @@ (defcustom sh-beginning-of-command - "\\([;({`|&]\\|\\`\\|[^\\]\n\\)[ \t]*\\([/~a-zA-Z0-9:]\\)" - "*Regexp to determine the beginning of a shell command. + "\\([;({`|&]\\|\\`\\|[^\\]\n\\)[ \t]*\\([/~[:alnum:]:]\\)" + "Regexp to determine the beginning of a shell command. The actual command starts at the beginning of the second \\(grouping\\)." :type 'regexp :group 'sh-script) (defcustom sh-end-of-command - "\\([/~a-zA-Z0-9:]\\)[ \t]*\\([;#)}`|&]\\|$\\)" - "*Regexp to determine the end of a shell command. + "\\([/~[:alnum:]:]\\)[ \t]*\\([;#)}`|&]\\|$\\)" + "Regexp to determine the end of a shell command. The actual command ends at the end of the first \\(grouping\\)." :type 'regexp :group 'sh-script) @@ -647,6 +647,7 @@ (shell "cd" "echo" "eval" "set" "shift" "umask" "unset" "wait") (wksh sh-append ksh88 + ;; FIXME: This looks too much like a regexp. --Stef "Xt[A-Z][A-Za-z]*") (zsh sh-append ksh88 @@ -656,7 +657,7 @@ "readonly" "rehash" "sched" "setopt" "source" "suspend" "true" "ttyctl" "type" "unfunction" "unhash" "unlimit" "unsetopt" "vared" "which")) - "*List of all shell builtins for completing read and fontification. + "List of all shell builtins for completing read and fontification. Note that on some systems not all builtins are available or some are implemented as aliases. See `sh-feature'." :type '(repeat (cons (symbol :tag "Shell") @@ -677,7 +678,7 @@ (rc "else") (sh "!" "do" "elif" "else" "if" "then" "trap" "type" "until" "while")) - "*List of keywords that may be immediately followed by a builtin or keyword. + "List of keywords that may be immediately followed by a builtin or keyword. Given some confusion between keywords and builtins depending on shell and system, the distinction here has been based on whether they influence the flow of control or syntax. See `sh-feature'." @@ -716,7 +717,7 @@ (zsh sh-append bash "select")) - "*List of keywords not in `sh-leading-keywords'. + "List of keywords not in `sh-leading-keywords'. See `sh-feature'." :type '(repeat (cons (symbol :tag "Shell") (choice (repeat string) @@ -837,18 +838,18 @@ (defvar sh-font-lock-keywords-var '((csh sh-append shell - ("\\${?[#?]?\\([A-Za-z_][A-Za-z0-9_]*\\|0\\)" 1 + ("\\${?[#?]?\\([[:alpha:]_][[:alnum:]_]*\\|0\\)" 1 font-lock-variable-name-face)) (es sh-append executable-font-lock-keywords - ("\\$#?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\)" 1 + ("\\$#?\\([[:alpha:]_][[:alnum:]_]*\\|[0-9]+\\)" 1 font-lock-variable-name-face)) (rc sh-append es) (bash sh-append shell ("\\$(\\(\\sw+\\)" (1 'sh-quoted-exec t) )) (sh sh-append shell ;; Variable names. - ("\\$\\({#?\\)?\\([A-Za-z_][A-Za-z0-9_]*\\|[-#?@!]\\)" 2 + ("\\$\\({#?\\)?\\([[:alpha:]_][[:alnum:]_]*\\|[-#?@!]\\)" 2 font-lock-variable-name-face) ;; Function names. ("^\\(\\sw+\\)[ \t]*(" 1 font-lock-function-name-face) @@ -861,8 +862,8 @@ (shell ;; Using font-lock-string-face here confuses sh-get-indent-info. ("\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\)$" 3 'sh-escaped-newline) - ("\\\\[^A-Za-z0-9]" 0 font-lock-string-face) - ("\\${?\\([A-Za-z_][A-Za-z0-9_]*\\|[0-9]+\\|[$*_]\\)" 1 + ("\\\\[^[:alnum:]]" 0 font-lock-string-face) + ("\\${?\\([[:alpha:]_][[:alnum:]_]*\\|[0-9]+\\|[$*_]\\)" 1 font-lock-variable-name-face)) (rpm sh-append rpm2 ("%{?\\(\\sw+\\)" 1 font-lock-keyword-face)) @@ -991,46 +992,38 @@ (eq ?\" (nth 3 (syntax-ppss)))) ;; bingo we have a $( or a ` inside a "" (let ((char (char-after (point))) - (continue t) - (pos (point)) - (data nil) ;; value to put into match-data (and return) - (last nil) ;; last char seen - (bq (equal (match-string 1) "`")) ;; ` state flip-flop - (seen nil) ;; list of important positions - (nest 1)) ;; subshell nesting level - (while (and continue char (<= pos limit)) - ;; unescaped " inside a $( ... ) construct. - ;; state machine time... - ;; \ => ignore next char; - ;; ` => increase or decrease nesting level based on bq flag - ;; ) [where nesting > 0] => decrease nesting - ;; ( [where nesting > 0] => increase nesting - ;; ( [preceeded by $ ] => increase nesting - ;; " [nesting <= 0 ] => terminate, we're done. - ;; " [nesting > 0 ] => remember this, it's not a proper " - ;; FIXME: don't count parens that appear within quotes. - (cond - ((eq ?\\ last) nil) - ((eq ?\` char) (setq nest (+ nest (if bq -1 1)) bq (not bq))) - ((and (> nest 0) (eq ?\) char)) (setq nest (1- nest))) - ((and (eq ?$ last) (eq ?\( char)) (setq nest (1+ nest))) - ((and (> nest 0) (eq ?\( char)) (setq nest (1+ nest))) - ((eq char ?\") - (if (>= 0 nest) (setq continue nil) (push pos seen)))) - ;;(message "POS: %d [%d]" pos nest) - (setq last char - pos (1+ pos) - char (char-after pos)) ) - ;; FIXME: why construct a costly match data to pass to - ;; sh-apply-quoted-subshell rather than apply the highlight - ;; directly here? -- Stef - (when seen - ;;(message "SEEN: %S" seen) - (setq data (list (current-buffer))) - (dolist(P seen) - (setq data (cons P (cons (1+ P) data)))) - (store-match-data data)) - data) )) + ;; `state' can be: double-quote, backquote, code. + (state (if (eq (char-before) ?`) 'backquote 'code)) + ;; Stacked states in the context. + (states '(double-quote))) + (while (and state (progn (skip-chars-forward "^'\\\"`$()" limit) + (< (point) limit))) + ;; unescape " inside a $( ... ) construct. + (case (char-after) + (?\' (skip-chars-forward "^'" limit)) + (?\\ (forward-char 1)) + (?\" (case state + (double-quote (setq state (pop states))) + (t (push state states) (setq state 'double-quote))) + (if state (put-text-property (point) (1+ (point)) + 'syntax-table '(1)))) + (?\` (case state + (backquote (setq state (pop states))) + (t (push state states) (setq state 'backquote)))) + (?\$ (if (not (eq (char-after (1+ (point))) ?\()) + nil + (case state + (t (push state states) (setq state 'code))))) + (?\( (case state + (double-quote nil) + (t (push state states) (setq state 'code)))) + (?\) (case state + (double-quote nil) + (t (setq state (pop states))))) + (t (error "Internal error in sh-quoted-subshell"))) + (forward-char 1))) + t)) + (defun sh-is-quoted-p (pos) (and (eq (char-before pos) ?\\) @@ -1075,17 +1068,6 @@ (goto-char limit) nil) -(defun sh-apply-quoted-subshell () - "Apply the `sh-st-punc' syntax to all the matches in `match-data'. -This is used to flag quote characters in subshell constructs inside strings -\(which should therefore not be treated as normal quote characters\)" - (let ((m (match-data)) a b) - (while m - (setq a (car m) - b (cadr m) - m (cddr m)) - (put-text-property a b 'syntax-table sh-st-punc))) sh-st-punc) - (defconst sh-font-lock-syntactic-keywords ;; A `#' begins a comment when it is unquoted and at the beginning of a ;; word. In the shell, words are separated by metacharacters. @@ -1112,8 +1094,7 @@ (")" 0 (sh-font-lock-paren (match-beginning 0))) ;; highlight (possibly nested) subshells inside "" quoted regions correctly. ;; This should be at the very end because it uses syntax-ppss. - (sh-quoted-subshell - (1 (sh-apply-quoted-subshell) t t)))) + (sh-quoted-subshell))) (defun sh-font-lock-syntactic-face-function (state) (let ((q (nth 3 state))) @@ -1134,17 +1115,17 @@ (defcustom sh-set-shell-hook nil - "*Hook run by `sh-set-shell'." + "Hook run by `sh-set-shell'." :type 'hook :group 'sh-script) (defcustom sh-mode-hook nil - "*Hook run by `sh-mode'." + "Hook run by `sh-mode'." :type 'hook :group 'sh-script) (defcustom sh-learn-basic-offset nil - "*When `sh-guess-basic-offset' should learn `sh-basic-offset'. + "When `sh-guess-basic-offset' should learn `sh-basic-offset'. nil mean: never. t means: only if there seems to be an obvious value. @@ -1156,7 +1137,7 @@ :group 'sh-indentation) (defcustom sh-popup-occur-buffer nil - "*Controls when `sh-learn-buffer-indent' pops the `*indent*' buffer. + "Controls when `sh-learn-buffer-indent' pops the `*indent*' buffer. If t it is always shown. If nil, it is shown only when there are conflicts." :type '(choice @@ -1165,7 +1146,7 @@ :group 'sh-indentation) (defcustom sh-blink t - "*If non-nil, `sh-show-indent' shows the line indentation is relative to. + "If non-nil, `sh-show-indent' shows the line indentation is relative to. The position on the line is not necessarily meaningful. In some cases the line will be the matching keyword, but this is not always the case." @@ -1173,7 +1154,7 @@ :group 'sh-indentation) (defcustom sh-first-lines-indent 0 - "*The indentation of the first non-blank non-comment line. + "The indentation of the first non-blank non-comment line. Usually 0 meaning first column. Can be set to a number, or to nil which means leave it as is." :type '(choice @@ -1184,13 +1165,13 @@ (defcustom sh-basic-offset 4 - "*The default indentation increment. + "The default indentation increment. This value is used for the `+' and `-' symbols in an indentation variable." :type 'integer :group 'sh-indentation) (defcustom sh-indent-comment nil - "*How a comment line is to be indented. + "How a comment line is to be indented. nil means leave it as it is; t means indent it as a normal line, aligning it to previous non-blank non-comment line; @@ -1229,7 +1210,7 @@ :menu-tag "/ Indent left half sh-basic-offset"))) (defcustom sh-indent-for-else 0 - "*How much to indent an `else' relative to its `if'. Usually 0." + "How much to indent an `else' relative to its `if'. Usually 0." :type `(choice (integer :menu-tag "A number (positive=>indent right)" :tag "A number") @@ -1245,41 +1226,41 @@ sh-symbol-list)) (defcustom sh-indent-for-fi 0 - "*How much to indent a `fi' relative to its `if'. Usually 0." + "How much to indent a `fi' relative to its `if'. Usually 0." :type `(choice ,@ sh-number-or-symbol-list ) :group 'sh-indentation) (defcustom sh-indent-for-done 0 - "*How much to indent a `done' relative to its matching stmt. Usually 0." + "How much to indent a `done' relative to its matching stmt. Usually 0." :type `(choice ,@ sh-number-or-symbol-list ) :group 'sh-indentation) (defcustom sh-indent-after-else '+ - "*How much to indent a statement after an `else' statement." + "How much to indent a statement after an `else' statement." :type `(choice ,@ sh-number-or-symbol-list ) :group 'sh-indentation) (defcustom sh-indent-after-if '+ - "*How much to indent a statement after an `if' statement. + "How much to indent a statement after an `if' statement. This includes lines after `else' and `elif' statements, too, but does not affect the `else', `elif' or `fi' statements themselves." :type `(choice ,@ sh-number-or-symbol-list ) :group 'sh-indentation) (defcustom sh-indent-for-then 0 - "*How much to indent a `then' relative to its `if'." + "How much to indent a `then' relative to its `if'." :type `(choice ,@ sh-number-or-symbol-list ) :group 'sh-indentation) (defcustom sh-indent-for-do 0 - "*How much to indent a `do' statement. + "How much to indent a `do' statement. This is relative to the statement before the `do', typically a `while', `until', `for', `repeat' or `select' statement." :type `(choice ,@ sh-number-or-symbol-list) :group 'sh-indentation) (defcustom sh-indent-after-do '+ - "*How much to indent a line after a `do' statement. + "How much to indent a line after a `do' statement. This is used when the `do' is the first word of the line. This is relative to the statement before the `do', typically a `while', `until', `for', `repeat' or `select' statement." @@ -1287,7 +1268,7 @@ :group 'sh-indentation) (defcustom sh-indent-after-loop-construct '+ - "*How much to indent a statement after a loop construct. + "How much to indent a statement after a loop construct. This variable is used when the keyword `do' is on the same line as the loop statement (e.g., `until', `while' or `for'). @@ -1297,7 +1278,7 @@ (defcustom sh-indent-after-done 0 - "*How much to indent a statement after a `done' keyword. + "How much to indent a statement after a `done' keyword. Normally this is 0, which aligns the `done' to the matching looping construct line. Setting it non-zero allows you to have the `do' statement on a line @@ -1306,55 +1287,55 @@ :group 'sh-indentation) (defcustom sh-indent-for-case-label '+ - "*How much to indent a case label statement. + "How much to indent a case label statement. This is relative to the line containing the `case' statement." :type `(choice ,@ sh-number-or-symbol-list) :group 'sh-indentation) (defcustom sh-indent-for-case-alt '++ - "*How much to indent statements after the case label. + "How much to indent statements after the case label. This is relative to the line containing the `case' statement." :type `(choice ,@ sh-number-or-symbol-list) :group 'sh-indentation) (defcustom sh-indent-for-continuation '+ - "*How much to indent for a continuation statement." + "How much to indent for a continuation statement." :type `(choice ,@ sh-number-or-symbol-list) :group 'sh-indentation) (defcustom sh-indent-after-open '+ - "*How much to indent after a line with an opening parenthesis or brace. + "How much to indent after a line with an opening parenthesis or brace. For an open paren after a function, `sh-indent-after-function' is used." :type `(choice ,@ sh-number-or-symbol-list) :group 'sh-indentation) (defcustom sh-indent-after-function '+ - "*How much to indent after a function line." + "How much to indent after a function line." :type `(choice ,@ sh-number-or-symbol-list) :group 'sh-indentation) ;; These 2 are for the rc shell: (defcustom sh-indent-after-switch '+ - "*How much to indent a `case' statement relative to the `switch' statement. + "How much to indent a `case' statement relative to the `switch' statement. This is for the rc shell." :type `(choice ,@ sh-number-or-symbol-list) :group 'sh-indentation) (defcustom sh-indent-after-case '+ - "*How much to indent a statement relative to the `case' statement. + "How much to indent a statement relative to the `case' statement. This is for the rc shell." :type `(choice ,@ sh-number-or-symbol-list) :group 'sh-indentation) (defcustom sh-backslash-column 48 - "*Column in which `sh-backslash-region' inserts backslashes." + "Column in which `sh-backslash-region' inserts backslashes." :type 'integer :group 'sh) (defcustom sh-backslash-align t - "*If non-nil, `sh-backslash-region' will align backslashes." + "If non-nil, `sh-backslash-region' will align backslashes." :type 'boolean :group 'sh) @@ -1364,7 +1345,7 @@ "Make a regexp which matches WORD as a word. This specifically excludes an occurrence of WORD followed by punctuation characters like '-'." - (concat word "\\([^-a-z0-9_]\\|$\\)")) + (concat word "\\([^-[:alnum:]_]\\|$\\)")) (defconst sh-re-done (sh-mkword-regexpr "done")) @@ -2251,6 +2232,7 @@ (setq align-point (point)))) (or (bobp) (forward-char -1)) + ;; FIXME: This charset looks too much like a regexp. --Stef (skip-chars-forward "[a-z0-9]*?") ) ((string-match "[])}]" x) @@ -2459,7 +2441,7 @@ (if (looking-at "[\"'`]") (sh-safe-forward-sexp) ;; (> (skip-chars-forward "^ \t\n\"'`") 0) - (> (skip-chars-forward "-_a-zA-Z$0-9") 0) + (> (skip-chars-forward "-_$[:alnum:]") 0) )) (buffer-substring start (point)) ))