el/dot-emacs.el: Don't highlight bad whitespace in read-only buffers.
[profile] / el / dot-emacs.el
index 32188f9..1b0e350 100644 (file)
@@ -52,6 +52,11 @@ This may be at the expense of cool features.")
           (debug 0))
   `',(make-regexp list))
 
+(defun mdw-wrong ()
+  "This is not the key sequence you're looking for."
+  (interactive)
+  (error "wrong button"))
+
 ;; Some error trapping.
 ;;
 ;; If individual bits of this file go tits-up, we don't particularly want
@@ -805,6 +810,8 @@ case."
       (whitespace-mode arg))
     (setq show-trailing-whitespace whitespace-mode)))
 
+(defvar mdw-do-misc-mode-hacking nil)
+
 (defun mdw-misc-mode-config ()
   (and mdw-auto-indent
        (cond ((eq major-mode 'lisp-mode)
@@ -814,14 +821,13 @@ case."
              nil)
             (t
              (local-set-key "\C-m" 'newline-and-indent))))
+  (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
   (local-set-key [C-return] 'newline)
   (make-local-variable 'page-delimiter)
   (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
   (setq comment-column 40)
   (auto-fill-mode 1)
   (setq fill-column 77)
-  (setq show-trailing-whitespace t)
-  (mdw-whitespace-mode 1)
   (and (fboundp 'gtags-mode)
        (gtags-mode))
   (if (fboundp 'hs-minor-mode)
@@ -830,8 +836,17 @@ case."
   (reveal-mode t)
   (trap (turn-on-font-lock)))
 
-(defun mdw-post-config-mode-hack ()
-  (mdw-whitespace-mode 1))
+(defun mdw-post-local-vars-misc-mode-config ()
+  (when (and mdw-do-misc-mode-hacking
+            (not buffer-read-only))
+    (setq show-trailing-whitespace t)
+    (mdw-whitespace-mode 1)))
+(add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
+
+(defadvice toggle-read-only (after mdw-angry-fruit-salad activate)
+  (when mdw-do-misc-mode-hacking
+    (setq show-trailing-whitespace (not buffer-read-only))
+    (mdw-whitespace-mode (if buffer-read-only 0 1))))
 
 (eval-after-load 'gtags
   '(progn
@@ -1456,9 +1471,7 @@ doesn't match any of the regular expressions in
 
           ;; And anything else is punctuation.
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face))))
-
-    (mdw-post-config-mode-hack)))
+                '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; AP calc mode.
@@ -1510,9 +1523,7 @@ doesn't match any of the regular expressions in
 
           ;; And anything else is punctuation.
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Java programming configuration.
@@ -1578,9 +1589,7 @@ doesn't match any of the regular expressions in
 
           ;; And anything else is punctuation.
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Javascript programming configuration.
@@ -1638,9 +1647,7 @@ doesn't match any of the regular expressions in
 
           ;; And anything else is punctuation.
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Scala programming configuration.
@@ -1713,9 +1720,7 @@ doesn't match any of the regular expressions in
                         "\\|" "\\\\" "." "\\)"
                         "\\('\\)")
                 '(1 "\"")
-                '(4 "\"")))))
-
-  (mdw-post-config-mode-hack))
+                '(4 "\""))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; C# programming configuration.
@@ -1786,9 +1791,7 @@ doesn't match any of the regular expressions in
 
           ;; And anything else is punctuation.
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                '(0 mdw-punct-face))))))
 
 (define-derived-mode csharp-mode java-mode "C#"
   "Major mode for editing C# code.")
@@ -1903,9 +1906,7 @@ doesn't match any of the regular expressions in
                      '(0 mdw-number-face))
 
                (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                     '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                     '(0 mdw-punct-face))))))
 
 (defun mdw-fontify-inferior-fsharp ()
   (mdw-fontify-fsharp)
@@ -1974,9 +1975,83 @@ doesn't match any of the regular expressions in
 
           ;; And anything else is punctuation.
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
+                '(0 mdw-punct-face))))))
+
+;;;--------------------------------------------------------------------------
+;;; Rust programming configuration.
+
+(setq-default rust-indent-offset 2)
+
+(defun mdw-self-insert-and-indent (count)
+  (interactive "p")
+  (self-insert-command count)
+  (indent-according-to-mode))
+
+(defun mdw-fontify-rust ()
+
+  ;; Hack syntax categories.
+  (modify-syntax-entry ?= ".")
+
+  ;; Fontify keywords and things.
+  (make-local-variable 'font-lock-keywords)
+  (let ((rust-keywords
+        (mdw-regexps "abstract" "alignof" "as"
+                     "become" "box" "break"
+                     "const" "continue" "create"
+                     "do"
+                     "else" "enum" "extern"
+                     "false" "final" "fn" "for"
+                     "if" "impl" "in"
+                     "let" "loop"
+                     "macro" "match" "mod" "move" "mut"
+                     "offsetof" "override"
+                     "priv" "pub" "pure"
+                     "ref" "return"
+                     "self" "sizeof" "static" "struct" "super"
+                     "true" "trait" "type" "typeof"
+                     "unsafe" "unsized" "use"
+                     "virtual"
+                     "where" "while"
+                     "yield"))
+       (rust-builtins
+        (mdw-regexps "array" "pointer" "slice" "tuple"
+                     "bool" "true" "false"
+                     "f32" "f64"
+                     "i8" "i16" "i32" "i64" "isize"
+                     "u8" "u16" "u32" "u64" "usize"
+                     "char" "str")))
+    (setq font-lock-keywords
+         (list
+
+          ;; Handle the keywords defined above.
+          (list (concat "\\<\\(" rust-keywords "\\)\\>")
+                '(0 font-lock-keyword-face))
+          (list (concat "\\<\\(" rust-builtins "\\)\\>")
+                '(0 font-lock-variable-name-face))
+
+          ;; Handle numbers too.
+          (list (concat "\\<\\("
+                              "[0-9][0-9_]*"
+                              "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
+                              "\\|" "\\.[0-9_]+"
+                              "\\)"
+                              "\\(f32\\|f64\\)?"
+                        "\\|" "\\(" "[0-9][0-9_]*"
+                              "\\|" "0x[0-9a-fA-F_]+"
+                              "\\|" "0o[0-7_]+"
+                              "\\|" "0b[01_]+"
+                              "\\)"
+                              "\\([ui]\\(8\\|16\\|32\\|64\\|s\\|size\\)\\)?"
+                        "\\)\\>")
+                '(0 mdw-number-face))
+
+          ;; And anything else is punctuation.
+          (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
                 '(0 mdw-punct-face)))))
 
-  (mdw-post-config-mode-hack))
+  ;; Hack key bindings.
+  (local-set-key [?{] 'mdw-self-insert-and-indent)
+  (local-set-key [?}] 'mdw-self-insert-and-indent))
 
 ;;;--------------------------------------------------------------------------
 ;;; Awk programming configuration.
@@ -2034,9 +2109,7 @@ doesn't match any of the regular expressions in
 
           ;; And anything else is punctuation.
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Perl programming style.
@@ -2057,16 +2130,29 @@ doesn't match any of the regular expressions in
   ;; Miscellaneous fiddling.
   (modify-syntax-entry ?$ "\\")
   (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
+  (modify-syntax-entry ?: "." font-lock-syntax-table)
   (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
 
   ;; Now define fontification things.
   (make-local-variable 'font-lock-keywords)
   (let ((perl-keywords
-        (mdw-regexps "and" "break" "cmp" "continue" "do" "else" "elsif" "eq"
-                     "for" "foreach" "ge" "given" "gt" "goto" "if"
-                     "last" "le" "lt" "local" "my" "ne" "next" "or"
-                     "our" "package" "redo" "require" "return" "sub"
-                     "undef" "unless" "until" "use" "when" "while")))
+        (mdw-regexps "and"
+                     "break"
+                     "cmp" "continue"
+                     "default" "do"
+                     "else" "elsif" "eq"
+                     "for" "foreach"
+                     "ge" "given" "gt" "goto"
+                     "if"
+                     "last" "le" "local" "lt"
+                     "my"
+                     "ne" "next"
+                     "or" "our"
+                     "package"
+                     "redo" "require" "return"
+                     "sub"
+                     "undef" "unless" "until" "use"
+                     "when" "while")))
 
     (setq font-lock-keywords
          (list
@@ -2083,9 +2169,7 @@ doesn't match any of the regular expressions in
 
           ;; And anything else is punctuation.
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                '(0 mdw-punct-face))))))
 
 (defun perl-number-tests (&optional arg)
   "Assign consecutive numbers to lines containing `#t'.  With ARG,
@@ -2128,9 +2212,7 @@ strip numbers instead."
 
         ;; And anything else is punctuation.
         (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-              '(0 mdw-punct-face))))
-
-  (mdw-post-config-mode-hack))
+              '(0 mdw-punct-face)))))
 
 ;; Define Python fontification styles.
 
@@ -2204,9 +2286,7 @@ strip numbers instead."
 
           ;; And anything else is punctuation.
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Assembler mode.
@@ -2214,20 +2294,17 @@ strip numbers instead."
 (defun mdw-fontify-asm ()
   (modify-syntax-entry ?' "\"")
   (modify-syntax-entry ?. "w")
-  (modify-syntax-entry ?; "."
-                      )
-  (modify-syntax-entry asm-comment-char "<b")
   (modify-syntax-entry ?\n ">")
   (setf fill-prefix nil)
   (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
 
-(define-derived-mode x86-asm-mode asm-mode "x86 assembler"
-  "Assembler mode variant which uses `#' as the comment character."
-  (set (make-variable-buffer-local 'asm-comment-char) ?#))
-
-(define-derived-mode arm-asm-mode asm-mode "ARM assembler"
-  "Assembler mode variant which uses `@' as the comment character."
-  (set (make-variable-buffer-local 'asm-comment-char) ?@))
+(defun mdw-asm-set-comment ()
+  (modify-syntax-entry ?; "."
+                      )
+  (modify-syntax-entry asm-comment-char "<b")
+  (setq comment-start (string asm-comment-char ? )))
+(add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
+(put 'asm-comment-char 'safe-local-variable 'characterp)
 
 ;;;--------------------------------------------------------------------------
 ;;; TCL configuration.
@@ -2243,8 +2320,7 @@ strip numbers instead."
                       "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
               '(0 mdw-number-face))
         (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-              '(0 mdw-punct-face))))
-  (mdw-post-config-mode-hack))
+              '(0 mdw-punct-face)))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Dylan programming configuration.
@@ -2310,9 +2386,7 @@ strip numbers instead."
                              "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
                              "\\_<[-+*/=<>:&|]+\\_>"
                              "\\)")
-                     '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                     '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Algol 68 configuration.
@@ -2354,9 +2428,7 @@ strip numbers instead."
                              "\\>")
                      '(0 mdw-number-face))
                (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
-                     '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                     '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; REXX configuration.
@@ -2429,9 +2501,7 @@ strip numbers instead."
 
           ;; And everything else is punctuation.
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Standard ML programming style.
@@ -2481,9 +2551,7 @@ strip numbers instead."
 
           ;; And anything else is punctuation.
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Haskell configuration.
@@ -2561,9 +2629,7 @@ strip numbers instead."
                         "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
                 '(0 mdw-number-face))
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Erlang configuration.
@@ -2596,9 +2662,7 @@ strip numbers instead."
           (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
                 '(0 mdw-number-face))
           (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                '(0 mdw-punct-face)))))
-
-  (mdw-post-config-mode-hack))
+                '(0 mdw-punct-face))))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Texinfo configuration.
@@ -2632,9 +2696,7 @@ strip numbers instead."
 
         ;; Fontify TeX special characters as punctuation.
         (list "[{}]+"
-              '(0 mdw-punct-face))))
-
-  (mdw-post-config-mode-hack))
+              '(0 mdw-punct-face)))))
 
 ;;;--------------------------------------------------------------------------
 ;;; TeX and LaTeX configuration.
@@ -2700,9 +2762,7 @@ strip numbers instead."
 
         ;; Fontify TeX special characters as punctuation.
         (list "[$^_{}#&]"
-              '(0 mdw-punct-face))))
-
-  (mdw-post-config-mode-hack))
+              '(0 mdw-punct-face)))))
 
 ;;;--------------------------------------------------------------------------
 ;;; SGML hacking.
@@ -3062,8 +3122,7 @@ that character only to be normal punctuation.")
                       "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
               '(0 mdw-number-face))
         (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-              '(0 mdw-punct-face))))
-  (mdw-post-config-mode-hack))
+              '(0 mdw-punct-face)))))
 
 ;; Lispy languages.
 
@@ -3120,9 +3179,7 @@ that character only to be normal punctuation.")
                            "\\)\\_>")
                    '(0 mdw-number-face))
              (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
-                   '(0 mdw-punct-face))))
-
-  (mdw-post-config-mode-hack))
+                   '(0 mdw-punct-face)))))
 
 (defun comint-send-and-indent ()
   (interactive)