el/dot-emacs.el: Fix tab key in TeX-ish modes.
[profile] / el / dot-emacs.el
index 5f27085..a96482f 100644 (file)
@@ -293,6 +293,56 @@ it's currently off."
         (or transient-mark-mode (setq transient-mark-mode 'only))
         (set-mark (mark t)))))
 
+;; Improved compilation machinery.
+
+(setq compile-command
+      (let ((ncpu (with-temp-buffer
+                   (insert-file-contents "/proc/cpuinfo")
+                   (buffer-string)
+                   (count-matches "^processor\\s-*:"))))
+       (format "make -j%d -k" (* 2 ncpu))))
+
+(defun mdw-compilation-buffer-name (mode)
+  (concat "*" (downcase mode) ": "
+         (abbreviate-file-name default-directory) "*"))
+(setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
+
+(eval-after-load "compile"
+  '(progn
+     (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
+
+(defun mdw-compile (command &optional directory comint)
+  "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
+The DIRECTORY may be nil to not change.  If COMINT is t, then
+start an interactive compilation.
+
+Interactively, prompt for the command if the variable
+`compilation-read-command' is non-nil, or if requested through
+the prefix argument.  Prompt for the directory, and run
+interactively, if requested through the prefix.
+
+Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
+force prompting for a directory.
+
+Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
+prompting for the command.
+
+Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
+to force interactive compilation."
+  (interactive
+   (let* ((prefix (prefix-numeric-value current-prefix-arg))
+         (command (eval compile-command))
+         (dir (and (plusp (logand prefix #x54))
+                   (read-directory-name "Compile in directory: "))))
+     (list (if (or compilation-read-command
+                  (plusp (logand prefix #x42)))
+              (compilation-read-command command)
+            command)
+          dir
+          (plusp (logand prefix #x58)))))
+  (let ((default-directory (or directory default-directory)))
+    (compile command comint)))
+
 ;; Functions for sexp diary entries.
 
 (defun mdw-not-org-mode (form)
@@ -2377,13 +2427,13 @@ name, as a symbol."
          (list
 
           ;; Handle the keywords defined above.
-          (list (concat "\\<\\(" rust-keywords "\\)\\>")
+          (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
                 '(0 font-lock-keyword-face))
-          (list (concat "\\<\\(" rust-builtins "\\)\\>")
+          (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
                 '(0 font-lock-variable-name-face))
 
           ;; Handle numbers too.
-          (list (concat "\\<\\("
+          (list (concat "\\_<\\("
                               "[0-9][0-9_]*"
                               "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
                               "\\|" "\\.[0-9_]+"
@@ -2395,7 +2445,7 @@ name, as a symbol."
                               "\\|" "0b[01_]+"
                               "\\)"
                               "\\([ui]\\(8\\|16\\|32\\|64\\|s\\|size\\)\\)?"
-                        "\\)\\>")
+                        "\\)\\_>")
                 '(0 mdw-number-face))
 
           ;; And anything else is punctuation.
@@ -3108,7 +3158,7 @@ strip numbers instead."
   (local-set-key [?$] 'self-insert-command)
 
   ;; Make `tab' be useful, given that tab stops in TeX don't work well.
-  (local-set-key "\C-i" 'indent-relative)
+  (local-set-key "\C-\M-i" 'indent-relative)
   (setq indent-tabs-mode nil)
 
   ;; Set fill prefix.
@@ -3627,6 +3677,9 @@ that character only to be normal punctuation.")
    "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
   (auto-fill-mode 1))
 
+(eval-after-load "flyspell"
+  '(define-key flyspell-mode-map "\C-\M-i" nil))
+
 ;;;--------------------------------------------------------------------------
 ;;; Outline and hide/show modes.
 
@@ -3829,6 +3882,18 @@ there is sadness."
 (mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
 (mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
 
+(defun mdw-mpc-louder (step)
+  (interactive (list (if current-prefix-arg
+                        (prefix-numeric-value current-prefix-arg)
+                      +10)))
+  (mpc-proc-cmd (format "volume %+d" step)))
+
+(defun mdw-mpc-quieter (step)
+  (interactive (list (if current-prefix-arg
+                        (prefix-numeric-value current-prefix-arg)
+                      +10)))
+  (mpc-proc-cmd (format "volume %+d" (- step))))
+
 (defun mdw-mpc-hack-lines (arg interactivep func)
   (if (and interactivep (use-region-p))
       (let ((from (region-beginning)) (to (region-end)))
@@ -3857,7 +3922,8 @@ there is sadness."
               (decf n)))))))
 
 (defun mdw-mpc-select-one ()
-  (unless (get-char-property (point) 'mpc-select)
+  (when (and (get-char-property (point) 'mpc-file)
+            (not (get-char-property (point) 'mpc-select)))
     (mpc-select-toggle)))
 
 (defun mdw-mpc-unselect-one ()
@@ -3866,18 +3932,15 @@ there is sadness."
 
 (defun mdw-mpc-select (&optional arg interactivep)
   (interactive (list current-prefix-arg t))
-  (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one)
-  (mpc-selection-refresh))
+  (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
 
 (defun mdw-mpc-unselect (&optional arg interactivep)
   (interactive (list current-prefix-arg t))
-  (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one)
-  (mpc-selection-refresh))
+  (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
 
 (defun mdw-mpc-unselect-backwards (arg)
   (interactive "p")
-  (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one)
-  (mpc-selection-refresh))
+  (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
 
 (defun mdw-mpc-unselect-all ()
   (interactive)
@@ -3894,6 +3957,49 @@ there is sadness."
   (beginning-of-line)
   (forward-line (- arg)))
 
+(defun mdw-mpc-playlist-add (&optional arg interactivep)
+  (interactive (list current-prefix-arg t))
+  (let ((mpc-select mpc-select))
+    (when (or arg (and interactivep (use-region-p)))
+      (setq mpc-select nil)
+      (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
+    (setq mpc-select (reverse mpc-select))
+    (mpc-playlist-add)))
+
+(defun mdw-mpc-playlist-delete (&optional arg interactivep)
+  (interactive (list current-prefix-arg t))
+  (setq mpc-select (nreverse mpc-select))
+  (mpc-select-save
+    (when (or arg (and interactivep (use-region-p)))
+      (setq mpc-select nil)
+      (mpc-selection-refresh)
+      (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
+      (mpc-playlist-delete)))
+
+(defun mdw-mpc-hack-tagbrowsers ()
+  (setq-local mode-line-format
+             '("%e"
+               mode-line-frame-identification
+               mode-line-buffer-identification)))
+(add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
+
+(defun mdw-mpc-hack-songs ()
+  (setq-local header-line-format
+             ;; '("MPC " mpc-volume " " mpc-current-song)
+             (list (propertize " " 'display '(space :align-to 0))
+                   ;; 'mpc-songs-format-description
+                   '(:eval
+                     (let ((deactivate-mark) (hscroll (window-hscroll)))
+                       (with-temp-buffer
+                         (mpc-format mpc-songs-format 'self hscroll)
+                         ;; That would be simpler than the hscroll handling in
+                         ;; mpc-format, but currently move-to-column does not
+                         ;; recognize :space display properties.
+                         ;; (move-to-column hscroll)
+                         ;; (delete-region (point-min) (point))
+                         (buffer-string)))))))
+(add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
+
 (eval-after-load "mpc"
   '(progn
      (define-key mpc-mode-map "m" 'mdw-mpc-select)
@@ -3902,11 +4008,13 @@ there is sadness."
      (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
      (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
      (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
+     (define-key mpc-mode-map "/" 'mpc-songs-search)
      (setq mpc-songs-mode-map (make-sparse-keymap))
      (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
      (define-key mpc-songs-mode-map "l" 'mpc-playlist)
-     (define-key mpc-songs-mode-map "+" 'mpc-playlist-add)
-     (define-key mpc-songs-mode-map "-" 'mpc-playlist-delete)))
+     (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
+     (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
+     (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
 
 ;;;--------------------------------------------------------------------------
 ;;; Inferior Emacs Lisp.