chiark / gitweb /
el/dot-emacs.el: Shell-mode hacking for non-Bourne shells.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 28 Dec 2011 17:10:11 +0000 (17:10 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 28 Dec 2011 17:10:11 +0000 (17:10 +0000)
This is surprisingly grim.  The rc support botches fontification of
backquotes surprisingly badly.  And it's really hard to force the use of
a particular shell for a given file because local variables get set
after the mode is chosen.

el/dot-emacs.el

index 76cda19859ff235c07e448fd2d73716446fd66f0..f28b288fd2461201264daac1b121ad22144ddf6b 100644 (file)
@@ -2203,6 +2203,42 @@ (defun mdw-setup-sh-script-mode ()
 
 (setq sh-shell-file "/bin/sh")
 
+;; Awful hacking to override the shell detection for particular scripts.
+(defmacro define-custom-shell-mode (name shell)
+  `(defun ,name ()
+     (interactive)
+     (set (make-local-variable 'sh-shell-file) ,shell)
+     (sh-mode)))
+(define-custom-shell-mode bash-mode "/bin/bash")
+(define-custom-shell-mode rc-mode "/usr/bin/rc")
+(put 'sh-shell-file 'permanent-local t)
+
+;; Hack the rc syntax table.  Backquotes aren't paired in rc.
+(eval-after-load "sh-script"
+  '(or (assq 'rc sh-mode-syntax-table-input)
+       (let ((frag '(nil
+                    ?# "<"
+                    ?\n ">#"
+                    ?\" "\"\""
+                    ?\' "\"\'"
+                    ?$ "'"
+                    ?\` "."
+                    ?! "_"
+                    ?% "_"
+                    ?. "_"
+                    ?^ "_"
+                    ?~ "_"
+                    ?, "_"
+                    ?= "."
+                    ?< "."
+                    ?> "."))
+            (assoc (assq 'rc sh-mode-syntax-table-input)))
+        (if assoc
+            (rplacd assoc frag)
+          (setq sh-mode-syntax-table-input
+                (cons (cons 'rc frag)
+                      sh-mode-syntax-table-input))))))
+
 ;;;--------------------------------------------------------------------------
 ;;; Emacs shell mode.