dot/emacs, el/dot-emacs.el: New gadget to force window selection.
[profile] / el / dot-emacs.el
index 67a5d1e..c7849f3 100644 (file)
@@ -55,8 +55,7 @@ This may be at the expense of cool features.")
 ;;; Some general utilities.
 
 (eval-when-compile
-  (unless (fboundp 'make-regexp)
-    (load "make-regexp"))
+  (unless (fboundp 'make-regexp) (load "make-regexp"))
   (require 'cl))
 
 (defmacro mdw-regexps (&rest list)
@@ -288,6 +287,59 @@ This is sadly necessary because Emacs 26 is broken in this regard."
   (set-frame-parameter frame 'background-color (car colour))
   (set-frame-parameter frame 'foreground-color (cdr colour)))
 
+;; Window configuration switching.
+
+(defvar mdw-current-window-configuration nil
+  "The current window configuration register name, or `nil'.")
+
+(defun mdw-switch-window-configuration (register &optional no-save)
+  "Switch make REGISTER be the new current window configuration.
+If a current window configuration register is established, and
+NO-SAVE is nil, then save the current window configuration to
+that register first.
+
+Signal an error if the new register contains something other than
+a window configuration.  If the register is unset then save the
+current window configuration to it immediately.
+
+With one or three C-u, or an odd numeric prefix argument, set
+NO-SAVE, so the previous window configuration register is left
+unchanged.
+
+With two or three C-u, or a prefix argument which is an odd
+multiple of 2, just clear the record of the current window
+configuration register, so that the next switch doesn't save the
+prevailing configuration."
+  (interactive
+   (let ((arg current-prefix-arg))
+     (list (if (or (and (consp arg) (= (car arg) 16) (= (car arg) 64))
+                  (and (integerp arg) (not (zerop (logand arg 2)))))
+              nil
+            (register-read-with-preview "Switch to window configuration: "))
+          (or (and (consp arg) (= (car arg) 4) (= (car arg) 64))
+              (and (integerp arg) (not (zerop (logand arg 1))))))))
+
+  (let ((current-windows (list (current-window-configuration)
+                              (point-marker)))
+       (register-value (and register (get-register register))))
+    (when (and mdw-current-window-configuration (not no-save))
+      (set-register mdw-current-window-configuration current-windows))
+    (cond ((null register)
+          (setq mdw-current-window-configuration nil))
+         ((not (or (null register-value)
+                   (and (consp register-value)
+                        (window-configuration-p (car register-value))
+                        (integer-or-marker-p (cadr register-value))
+                        (null (caddr register-value)))))
+          (error "Register `%c' is not a window configuration" register))
+         (t
+          (cond ((null register-value)
+                 (set-register register current-windows))
+                (t
+                 (set-window-configuration (car register-value))
+                 (goto-char (cadr register-value))))
+          (setq mdw-current-window-configuration register)))))
+
 ;; Don't raise windows unless I say so.
 
 (defcustom mdw-inhibit-raise-frame nil
@@ -592,6 +644,34 @@ Evil key bindings are defined in `mdw-evil-keymap-keys'."
 
 ;; Some hacks to do with window placement.
 
+(defvar mdw-designated-window nil
+  "The window chosen by `mdw-designate-window', or nil.")
+
+(defun mdw-designate-window (cancel)
+  "Use the selected window for the next pop-up buffer.
+With a prefix argument, clear the designated window."
+  (interactive "P")
+  (cond (cancel
+        (setq mdw-designated-window nil)
+        (message "Window designation cleared."))
+       (t
+        (setq mdw-designated-window (selected-window))
+        (message "Window designated."))))
+
+(defun mdw-display-buffer-in-designated-window (buffer alist)
+  "Display function to use the designated window."
+  (prog1 mdw-designated-window
+    (when mdw-designated-window
+      (select-window mdw-designated-window)
+      (switch-to-buffer buffer nil t))
+    (setq mdw-designated-window nil)))
+
+(setq display-buffer-base-action
+      (let* ((action display-buffer-base-action)
+            (funcs (car action))
+            (alist (cdr action)))
+       (cons (cons 'mdw-display-buffer-in-designated-window funcs) alist)))
+
 (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
   "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
   (interactive "bBuffer: ")
@@ -1096,21 +1176,6 @@ tramp, which seems to get itself into a twist."
   (let ((auto-revert-check-vc-info t))
     (auto-revert-buffers)))
 
-(defun comint-send-and-indent ()
-  (interactive)
-  (comint-send-input)
-  (and mdw-auto-indent
-       (indent-for-tab-command)))
-
-(defadvice comint-line-beginning-position
-    (around mdw-calculate-it-properly () activate compile)
-  "Calculate the actual line start for multi-line input."
-  (if (or comint-use-prompt-regexp
-         (eq (field-at-pos (point)) 'output))
-      ad-do-it
-    (setq ad-return-value
-           (constrain-to-field (line-beginning-position) (point)))))
-
 ;;;--------------------------------------------------------------------------
 ;;; Dired hacking.
 
@@ -3153,6 +3218,7 @@ name, as a symbol."
 
 (setq-default cperl-indent-level 2
              cperl-continued-statement-offset 2
+             cperl-indent-region-fix-constructs nil
              cperl-continued-brace-offset 0
              cperl-brace-offset -2
              cperl-brace-imaginary-offset 0
@@ -4244,7 +4310,7 @@ strip numbers instead."
 ;;;--------------------------------------------------------------------------
 ;;; HTML, CSS, and other web foolishness.
 
-(setq-default css-indent-offset 2)
+(setq-default css-indent-offset 8)
 
 ;;;--------------------------------------------------------------------------
 ;;; SGML hacking.
@@ -4807,11 +4873,12 @@ align the other subforms beneath it.  Otherwise, indent them
   (if mdw-friendly-name (setq ad-return-value mdw-friendly-name)
     ad-do-it))
 
-(trap
- (if (not mdw-fast-startup)
-     (progn
-       (require 'slime-autoloads)
-       (slime-setup '(slime-autodoc slime-c-p-c)))))
+(eval-and-compile
+  (trap
+    (if (not mdw-fast-startup)
+       (progn
+         (require 'slime-autoloads)
+         (slime-setup '(slime-autodoc slime-c-p-c))))))
 
 (let ((stuff '((cmucl ("cmucl"))
               (sbcl ("sbcl") :coding-system utf-8-unix)
@@ -4943,6 +5010,21 @@ align the other subforms beneath it.  Otherwise, indent them
   (auto-fill-mode -1)
   (setq tab-width 8))
 
+(defun comint-send-and-indent ()
+  (interactive)
+  (comint-send-input)
+  (and mdw-auto-indent
+       (indent-for-tab-command)))
+
+(defadvice comint-line-beginning-position
+    (around mdw-calculate-it-properly () activate compile)
+  "Calculate the actual line start for multi-line input."
+  (if (or comint-use-prompt-regexp
+         (eq (field-at-pos (point)) 'output))
+      ad-do-it
+    (setq ad-return-value
+           (constrain-to-field (line-beginning-position) (point)))))
+
 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
 (defun term-send-meta-left  () (interactive) (term-send-raw-string "\e\e[D"))
 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
@@ -5098,6 +5180,15 @@ there is sadness."
   (set-window-dedicated-p (or window (selected-window)) nil))
 
 ;;;--------------------------------------------------------------------------
+;;; SQL stuff.
+
+(setq sql-postgres-options '("-n" "-P" "pager=off")
+      sql-postgres-login-params
+       '((user :default "mdw")
+         (database :default "mdw")
+         (server :default "db.distorted.org.uk")))
+
+;;;--------------------------------------------------------------------------
 ;;; Man pages.
 
 ;; Turn off `noip' when running `man': it interferes with `man-db''s own