dot/gitconfig.in: Disable SSH connection caching by git-annex.
[profile] / el / dot-emacs.el
index f917905..bd29385 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
@@ -91,6 +96,14 @@ This may be at the expense of cool features.")
                    (concat "(" (buffer-string) ")")))))))
   (cdr (assq sym mdw-config)))
 
+;; Local variables hacking.
+
+(defun run-local-vars-mode-hook ()
+  "Run a hook for the major-mode after local variables have been processed."
+  (run-hooks (intern (concat (symbol-name major-mode)
+                            "-local-variables-hook"))))
+(add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
+
 ;; Set up the load path convincingly.
 
 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
@@ -893,7 +906,11 @@ doesn't match any of the regular expressions in
   (if (not mdw-point-overlay-mode)
       (mdw-remove-point-overlay)
     (overlay-put mdw-point-overlay 'window (selected-window))
-    (move-overlay mdw-point-overlay (point) (1+ (point)) (current-buffer))))
+    (if (bolp)
+       (move-overlay mdw-point-overlay
+                     (point) (1+ (point)) (current-buffer))
+      (move-overlay mdw-point-overlay
+                   (1- (point)) (point) (current-buffer)))))
 
 (defvar mdw-point-overlay-buffers nil
   "List of buffers using `mdw-point-overlay-mode'.")
@@ -924,6 +941,41 @@ doesn't match any of the regular expressions in
   (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
 
 ;;;--------------------------------------------------------------------------
+;;; Fullscreen-ness.
+
+(defvar mdw-full-screen-parameters
+  '((menu-bar-lines . 0)
+    ;(vertical-scroll-bars . nil)
+    )
+  "Frame parameters to set when making a frame fullscreen.")
+
+(defvar mdw-full-screen-save
+  '(width height)
+  "Extra frame parameters to save when setting fullscreen.")
+
+(defun mdw-toggle-full-screen (&optional frame)
+  "Show the FRAME fullscreen."
+  (interactive)
+  (when window-system
+    (cond ((frame-parameter frame 'fullscreen)
+          (set-frame-parameter frame 'fullscreen nil)
+          (modify-frame-parameters
+           nil
+           (or (frame-parameter frame 'mdw-full-screen-saved)
+               (mapcar (lambda (assoc)
+                         (assq (car assoc) default-frame-alist))
+                       mdw-full-screen-parameters))))
+         (t
+          (let ((saved (mapcar (lambda (param)
+                                 (cons param (frame-parameter frame param)))
+                               (append (mapcar #'car
+                                               mdw-full-screen-parameters)
+                                       mdw-full-screen-save))))
+            (set-frame-parameter frame 'mdw-full-screen-saved saved))
+          (modify-frame-parameters frame mdw-full-screen-parameters)
+          (set-frame-parameter frame 'fullscreen 'fullboth)))))
+
+;;;--------------------------------------------------------------------------
 ;;; General fontification.
 
 (defmacro mdw-define-face (name &rest body)
@@ -1932,6 +1984,85 @@ doesn't match any of the regular expressions in
   (mdw-post-config-mode-hack))
 
 ;;;--------------------------------------------------------------------------
+;;; 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)))))
+
+  ;; Hack key bindings.
+  (local-set-key [?{] 'mdw-self-insert-and-indent)
+  (local-set-key [?}] 'mdw-self-insert-and-indent)
+
+  ;; Final hacking.
+  (mdw-post-config-mode-hack))
+
+;;;--------------------------------------------------------------------------
 ;;; Awk programming configuration.
 
 ;; Make Awk indentation nice.
@@ -2010,16 +2141,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
@@ -2167,20 +2311,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.
@@ -2694,8 +2835,8 @@ that character only to be normal punctuation.")
   (or (booleanp value)
       (every (lambda (v) (memq v '(?\" ?')))
             (if (listp value) value (list value)))))
-(put 'mdw-conf-quote-normal 'safe-local-variable '
-     mdw-conf-quote-normal-acceptable-value-p)
+(put 'mdw-conf-quote-normal 'safe-local-variable
+     'mdw-conf-quote-normal-acceptable-value-p)
 
 (defun mdw-fix-up-quote ()
   "Apply the setting of `mdw-conf-quote-normal'."
@@ -2710,15 +2851,7 @@ that character only to be normal punctuation.")
                   (if (listp flag) flag (list flag)))
             (set-syntax-table table)
             (and font-lock-mode (font-lock-fontify-buffer)))))))
-(defun mdw-fix-up-quote-hack ()
-  "Unpleasant hack to call `mdw-fix-up-quote' at the right time.
-Annoyingly, `hack-local-variables' is done after `set-auto-mode'
-so we wouldn't see a local-variable setting of
-`mdw-conf-quote-normal' in `conf-mode-hook'.  Instead, wire
-ourselves onto `hack-local-variables-hook' here, and check the
-setting once it's actually been made."
-  (add-hook 'hack-local-variables-hook 'mdw-fix-up-quote t t))
-(add-hook 'conf-mode-hook 'mdw-fix-up-quote-hack t)
+(add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t)
 
 ;;;--------------------------------------------------------------------------
 ;;; Shell scripts.
@@ -2740,6 +2873,9 @@ setting once it's actually been made."
     (let ((executable-set-magic #'(lambda (s &rest r) s)))
       (sh-set-shell shell-name)))
 
+  ;; Don't insert here-document scaffolding automatically.
+  (local-set-key "<" 'self-insert-command)
+
   ;; Now enable my keys and the fontification.
   (mdw-misc-mode-config)