diff options
| author | Daniel Colascione | 2014-05-20 18:55:54 -0700 |
|---|---|---|
| committer | Daniel Colascione | 2014-05-20 18:55:54 -0700 |
| commit | e619d93c227597bccc8b3d76ee8518fb20098bb1 (patch) | |
| tree | c0749f1051f1096ea8b27ffe99c7a3c185725c7e | |
| parent | 8ea51e4f0819f249424cbbbec12bf4c6d750513a (diff) | |
| parent | 708374c7bc07fd778126e43daea2651ca66a893c (diff) | |
| download | emacs-e619d93c227597bccc8b3d76ee8518fb20098bb1.tar.gz emacs-e619d93c227597bccc8b3d76ee8518fb20098bb1.zip | |
File-local-variable support for sh-script; add mksh support
* lisp/files.el (interpreter-mode-alist): Add mksh.
* lisp/progmodes/sh-script.el (sh-ancestor-alist): Add mksh, a pdksh
derivative.
(sh-alias-alist): Alias /system/bin/sh (Android's system shell) to
mksh. Improve custom spec; allow regular expressions.
(sh-shell): Delegate name splitting to `sh-canonicalize-shell'.
(sh-after-hack-local-variables): New function.
(sh-mode): Use it; respect file-local `sh-shell' variable.
(sh-set-shell): Use `sh-canonicalize-shell' instead of open-coding
the normalization.
(sh-canonicalize-shell): Rewrite to support regexes.
| -rw-r--r-- | lisp/ChangeLog | 15 | ||||
| -rw-r--r-- | lisp/files.el | 1 | ||||
| -rw-r--r-- | lisp/progmodes/sh-script.el | 57 |
3 files changed, 55 insertions, 18 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5a720aa19ec..a27456241a3 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,18 @@ | |||
| 1 | 2014-05-21 Daniel Colascione <dancol@dancol.org> | ||
| 2 | |||
| 3 | * files.el (interpreter-mode-alist): Add mksh. | ||
| 4 | |||
| 5 | * progmodes/sh-script.el (sh-ancestor-alist): Add mksh, a pdksh | ||
| 6 | derivative. | ||
| 7 | (sh-alias-alist): Alias /system/bin/sh (Android's system shell) to | ||
| 8 | mksh. Improve custom spec; allow regular expressions. | ||
| 9 | (sh-shell): Delegate name splitting to `sh-canonicalize-shell'. | ||
| 10 | (sh-after-hack-local-variables): New function. | ||
| 11 | (sh-mode): Use it; respect file-local `sh-shell' variable. (bug#17333) | ||
| 12 | (sh-set-shell): Use `sh-canonicalize-shell' instead of open-coding | ||
| 13 | the normalization. | ||
| 14 | (sh-canonicalize-shell): Rewrite to support regexes. | ||
| 15 | |||
| 1 | 2014-05-21 Leo Liu <sdl.web@gmail.com> | 16 | 2014-05-21 Leo Liu <sdl.web@gmail.com> |
| 2 | 17 | ||
| 3 | * emacs-lisp/cl-lib.el (cl-endp): Fix last change. | 18 | * emacs-lisp/cl-lib.el (cl-endp): Fix last change. |
diff --git a/lisp/files.el b/lisp/files.el index 666316a2353..c153a11b243 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -2501,6 +2501,7 @@ and `magic-mode-alist', which determines modes based on file contents.") | |||
| 2501 | ("[acjkwz]sh" . sh-mode) | 2501 | ("[acjkwz]sh" . sh-mode) |
| 2502 | ("r?bash2?" . sh-mode) | 2502 | ("r?bash2?" . sh-mode) |
| 2503 | ("dash" . sh-mode) | 2503 | ("dash" . sh-mode) |
| 2504 | ("mksh" . sh-mode) | ||
| 2504 | ("\\(dt\\|pd\\|w\\)ksh" . sh-mode) | 2505 | ("\\(dt\\|pd\\|w\\)ksh" . sh-mode) |
| 2505 | ("es" . sh-mode) | 2506 | ("es" . sh-mode) |
| 2506 | ("i?tcsh" . sh-mode) | 2507 | ("i?tcsh" . sh-mode) |
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index 3ff4f57b887..6d7179c0447 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el | |||
| @@ -237,6 +237,7 @@ | |||
| 237 | (ksh88 . jsh) | 237 | (ksh88 . jsh) |
| 238 | (oash . sh) | 238 | (oash . sh) |
| 239 | (pdksh . ksh88) | 239 | (pdksh . ksh88) |
| 240 | (mksh . pdksh) | ||
| 240 | (posix . sh) | 241 | (posix . sh) |
| 241 | (tcsh . csh) | 242 | (tcsh . csh) |
| 242 | (wksh . ksh88) | 243 | (wksh . ksh88) |
| @@ -262,6 +263,7 @@ sh Bourne Shell | |||
| 262 | ksh Korn Shell '93 | 263 | ksh Korn Shell '93 |
| 263 | dtksh CDE Desktop Korn Shell | 264 | dtksh CDE Desktop Korn Shell |
| 264 | pdksh Public Domain Korn Shell | 265 | pdksh Public Domain Korn Shell |
| 266 | mksh MirOS BSD Korn Shell | ||
| 265 | wksh Window Korn Shell | 267 | wksh Window Korn Shell |
| 266 | zsh Z Shell | 268 | zsh Z Shell |
| 267 | oash SCO OA (curses) Shell | 269 | oash SCO OA (curses) Shell |
| @@ -271,7 +273,6 @@ sh Bourne Shell | |||
| 271 | :version "24.4" ; added dash | 273 | :version "24.4" ; added dash |
| 272 | :group 'sh-script) | 274 | :group 'sh-script) |
| 273 | 275 | ||
| 274 | |||
| 275 | (defcustom sh-alias-alist | 276 | (defcustom sh-alias-alist |
| 276 | (append (if (eq system-type 'gnu/linux) | 277 | (append (if (eq system-type 'gnu/linux) |
| 277 | '((csh . tcsh) | 278 | '((csh . tcsh) |
| @@ -279,11 +280,20 @@ sh Bourne Shell | |||
| 279 | ;; for the time being | 280 | ;; for the time being |
| 280 | '((ksh . ksh88) | 281 | '((ksh . ksh88) |
| 281 | (bash2 . bash) | 282 | (bash2 . bash) |
| 282 | (sh5 . sh))) | 283 | (sh5 . sh) |
| 284 | ;; Android's system shell | ||
| 285 | ("^/system/bin/sh$" . mksh))) | ||
| 283 | "Alist for transforming shell names to what they really are. | 286 | "Alist for transforming shell names to what they really are. |
| 284 | Use this where the name of the executable doesn't correspond to the type of | 287 | Use this where the name of the executable doesn't correspond to |
| 285 | shell it really is." | 288 | the type of shell it really is. Keys are regular expressions |
| 286 | :type '(repeat (cons symbol symbol)) | 289 | matched against the full path of the interpreter. (For backward |
| 290 | compatibility, keys may also be symbols, which are matched | ||
| 291 | against the interpreter's basename. The values are symbols | ||
| 292 | naming the shell." | ||
| 293 | :type '(repeat (cons (radio | ||
| 294 | (regexp :tag "Regular expression") | ||
| 295 | (symbol :tag "Basename")) | ||
| 296 | (symbol :tag "Shell"))) | ||
| 287 | :group 'sh-script) | 297 | :group 'sh-script) |
| 288 | 298 | ||
| 289 | 299 | ||
| @@ -387,15 +397,20 @@ the car and cdr are the same symbol.") | |||
| 387 | "Non-nil if `sh-shell-variables' is initialized.") | 397 | "Non-nil if `sh-shell-variables' is initialized.") |
| 388 | 398 | ||
| 389 | (defun sh-canonicalize-shell (shell) | 399 | (defun sh-canonicalize-shell (shell) |
| 390 | "Convert a shell name SHELL to the one we should handle it as." | 400 | "Convert a shell name SHELL to the one we should handle it as. |
| 391 | (if (string-match "\\.exe\\'" shell) | 401 | SHELL is a full path to the shell interpreter; return a shell |
| 392 | (setq shell (substring shell 0 (match-beginning 0)))) | 402 | name symbol." |
| 393 | (or (symbolp shell) | 403 | (cl-loop |
| 394 | (setq shell (intern shell))) | 404 | with shell = (cond ((string-match "\\.exe\\'" shell) |
| 395 | (or (cdr (assq shell sh-alias-alist)) | 405 | (substring shell 0 (match-beginning 0))) |
| 396 | shell)) | 406 | (t shell)) |
| 397 | 407 | with shell-base = (intern (file-name-nondirectory shell)) | |
| 398 | (defvar sh-shell (sh-canonicalize-shell (file-name-nondirectory sh-shell-file)) | 408 | for (key . value) in sh-alias-alist |
| 409 | if (and (stringp key) (string-match key shell)) return value | ||
| 410 | if (eq key shell-base) return value | ||
| 411 | finally return shell-base)) | ||
| 412 | |||
| 413 | (defvar sh-shell (sh-canonicalize-shell sh-shell-file) | ||
| 399 | "The shell being programmed. This is set by \\[sh-set-shell].") | 414 | "The shell being programmed. This is set by \\[sh-set-shell].") |
| 400 | ;;;###autoload(put 'sh-shell 'safe-local-variable 'symbolp) | 415 | ;;;###autoload(put 'sh-shell 'safe-local-variable 'symbolp) |
| 401 | 416 | ||
| @@ -1533,6 +1548,12 @@ When the region is active, send the region instead." | |||
| 1533 | 1548 | ||
| 1534 | ;; mode-command and utility functions | 1549 | ;; mode-command and utility functions |
| 1535 | 1550 | ||
| 1551 | (defun sh-after-hack-local-variables () | ||
| 1552 | (when (assq 'sh-shell file-local-variables-alist) | ||
| 1553 | (sh-set-shell (if (symbolp sh-shell) | ||
| 1554 | (symbol-name sh-shell) | ||
| 1555 | sh-shell)))) | ||
| 1556 | |||
| 1536 | ;;;###autoload | 1557 | ;;;###autoload |
| 1537 | (define-derived-mode sh-mode prog-mode "Shell-script" | 1558 | (define-derived-mode sh-mode prog-mode "Shell-script" |
| 1538 | "Major mode for editing shell scripts. | 1559 | "Major mode for editing shell scripts. |
| @@ -1643,7 +1664,9 @@ with your script for an edit-interpret-debug cycle." | |||
| 1643 | ((string-match "[.]csh\\>" buffer-file-name) "csh") | 1664 | ((string-match "[.]csh\\>" buffer-file-name) "csh") |
| 1644 | ((equal (file-name-nondirectory buffer-file-name) ".profile") "sh") | 1665 | ((equal (file-name-nondirectory buffer-file-name) ".profile") "sh") |
| 1645 | (t sh-shell-file)) | 1666 | (t sh-shell-file)) |
| 1646 | nil nil)) | 1667 | nil nil) |
| 1668 | (add-hook 'hack-local-variables-hook | ||
| 1669 | #'sh-after-hack-local-variables nil t)) | ||
| 1647 | 1670 | ||
| 1648 | ;;;###autoload | 1671 | ;;;###autoload |
| 1649 | (defalias 'shell-script-mode 'sh-mode) | 1672 | (defalias 'shell-script-mode 'sh-mode) |
| @@ -2253,9 +2276,7 @@ Calls the value of `sh-set-shell-hook' if set." | |||
| 2253 | t)) | 2276 | t)) |
| 2254 | (if (string-match "\\.exe\\'" shell) | 2277 | (if (string-match "\\.exe\\'" shell) |
| 2255 | (setq shell (substring shell 0 (match-beginning 0)))) | 2278 | (setq shell (substring shell 0 (match-beginning 0)))) |
| 2256 | (setq sh-shell (intern (file-name-nondirectory shell)) | 2279 | (setq sh-shell (sh-canonicalize-shell shell)) |
| 2257 | sh-shell (or (cdr (assq sh-shell sh-alias-alist)) | ||
| 2258 | sh-shell)) | ||
| 2259 | (if insert-flag | 2280 | (if insert-flag |
| 2260 | (setq sh-shell-file | 2281 | (setq sh-shell-file |
| 2261 | (executable-set-magic shell (sh-feature sh-shell-arg) | 2282 | (executable-set-magic shell (sh-feature sh-shell-arg) |