X-Git-Url: https://git.distorted.org.uk/~mdw/profile/blobdiff_plain/b50c6712281d0a2de044e16df203828e67a84314..3782446f0bbdc76405aadc6c73f78ce37153fd55:/el/dot-emacs.el diff --git a/el/dot-emacs.el b/el/dot-emacs.el index cb19d10..23b2c97 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -169,6 +169,17 @@ library." (set-frame-parameter frame 'menu-bar-lines 0) (set-frame-parameter frame 'menu-bar-lines old))) +;; Page motion. + +(defun mdw-fixup-page-position () + (unless (eq (char-before (point)) ? ) + (forward-line 0))) + +(defadvice backward-page (after mdw-fixup compile activate) + (mdw-fixup-page-position)) +(defadvice forward-page (after mdw-fixup compile activate) + (mdw-fixup-page-position)) + ;; Splitting windows. (unless (fboundp 'scroll-bar-columns) @@ -240,6 +251,14 @@ P") sb-width)) (mdw-divvy-window width))) +(defvar mdw-frame-width-fudge + (cond ((<= emacs-major-version 20) 1) + ((= emacs-major-version 26) 3) + (t 0)) + "The number of extra columns to add to the desired frame width. + +This is sadly necessary because Emacs 26 is broken in this regard.") + ;; Don't raise windows unless I say so. (defvar mdw-inhibit-raise-frame nil @@ -347,9 +366,9 @@ as output rather than a string." (months ["Chaos" "Discord" "Confusion" "Bureaucracy" "Aftermath"]) (day-count [0 31 59 90 120 151 181 212 243 273 304 334]) - (year (- (extract-calendar-year date) 1900)) - (month (1- (extract-calendar-month date))) - (day (1- (extract-calendar-day date))) + (year (- (calendar-extract-year date) 1900)) + (month (1- (calendar-extract-month date))) + (day (1- (calendar-extract-day date))) (julian (+ (aref day-count month) day)) (dyear (+ year 3066))) (if (and (= month 1) (= day 28)) @@ -404,6 +423,8 @@ as output rather than a string." (let ((mdw-diary-for-org-mode-p t)) ad-do-it)) +(defvar diary-time-regexp nil) + (defadvice diary-add-to-list (before mdw-trim-leading-space compile activate) "Trim leading space from the diary entry string." (save-match-data @@ -546,6 +567,11 @@ Evil key bindings are defined in `mdw-evil-keymap-keys'." This is used by advice on `switch-to-buffer-other-frame' to inhibit finding buffers in random frames.") +(setq display-buffer--other-frame-action + '((display-buffer-reuse-window display-buffer-pop-up-frame) + (reusable-frames . nil) + (inhibit-same-window . t))) + (defadvice walk-windows (around mdw-inhibit activate) "If `mdw-inhibit-walk-windows' is non-nil, then do nothing." (and (not mdw-inhibit-walk-windows) @@ -562,6 +588,15 @@ Even if an existing window in some random frame looks tempting." Pretend they don't exist. They might be on other display devices." (ad-set-arg 2 nil)) +;; Rename buffers along with files. + +(defadvice rename-file (after mdw-rename-buffers (from to &optional forcep) + compile activate) + (let ((buffer (get-file-buffer from))) + (when buffer + (with-current-buffer buffer + (set-visited-file-name to nil t))))) + ;;;-------------------------------------------------------------------------- ;;; Improved compilation machinery. @@ -793,7 +828,7 @@ Use this to arrange for per-server settings.") (delete-region (+ (match-beginning 0) 2) (point)) (setq string (buffer-substring (point) (+ (point) size))) (delete-region (point) (+ (point) size)) - (insert (format "%S" (mm-subst-char-in-string ?\n ?\s string))) + (insert (format "%S" (subst-char-in-string ?\n ?\s string))) ;; [mdw] missing from upstream (backward-char 1)) (beginning-of-line) @@ -839,6 +874,18 @@ Use this to arrange for per-server settings.") '(defalias 'nnimap-transform-headers (symbol-function 'mdw-nnimap-transform-headers))) +(defadvice gnus-other-frame (around mdw-hack-frame-width compile activate) + "Always arrange for mail/news frames to be 80 columns wide." + (let ((default-frame-alist (cons `(width . ,(+ 80 mdw-frame-width-fudge)) + (cl-delete 'width default-frame-alist + :key #'car)))) + ad-do-it)) + +;; Preferred programs. + +(setq mailcap-user-mime-data + '(((type . "application/pdf") (viewer . "mupdf %s")))) + ;;;-------------------------------------------------------------------------- ;;; Utility functions. @@ -1253,7 +1300,14 @@ case." (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 page-delimiter (concat "^" "\f" + "\\|" "^" + ".\\{0,4\\}" + "-\\{5\\}" + "\\(" " " ".*" " " "\\)?" + "-+" + ".\\{0,2\\}" + "$")) (setq comment-column 40) (auto-fill-mode 1) (setq fill-column mdw-text-width) @@ -1393,11 +1447,12 @@ doesn't match any of the regular expressions in (((type w32)) :family "courier new" :height 85) (((type x)) :family "6x13" :foundry "trad" :height 130) (t :foreground "white" :background "black")) -(if (mdw-emacs-version-p 23) - (mdw-define-face variable-pitch - (((type x)) :family "sans" :height 100)) - (mdw-define-face variable-pitch - (((type x)) :family "helvetica" :height 90))) +(mdw-define-face fixed-pitch-serif + (((type w32)) :family "courier new" :height 85 :weight bold) + (((type x)) :family "6x13" :foundry "trad" :height 130 :weight bold) + (t :foreground "white" :background "black" :weight bold)) +(mdw-define-face variable-pitch + (((type x)) :family "helvetica" :height 120)) (mdw-define-face region (((min-colors 64)) :background "grey30") (((class color)) :background "blue") @@ -1447,6 +1502,10 @@ doesn't match any of the regular expressions in (mdw-define-face comint-highlight-input (t nil)) +(mdw-define-face Man-underline + (((type tty)) :underline t) + (t :slant italic)) + (mdw-define-face ido-subdir (t :foreground "cyan" :weight bold)) @@ -1841,6 +1900,21 @@ doesn't match any of the regular expressions in mdw-point-overlay-mode (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t)))) +(defvar mdw-terminal-title-alist nil) +(defun mdw-update-terminal-title () + (when (let ((term (frame-parameter nil 'tty-type))) + (and term (string-match "^xterm" term))) + (let* ((tty (frame-parameter nil 'tty)) + (old (assoc tty mdw-terminal-title-alist)) + (new (format-mode-line frame-title-format))) + (unless (and old (equal (cdr old) new)) + (if old (rplacd old new) + (setq mdw-terminal-title-alist + (cons (cons tty new) mdw-terminal-title-alist))) + (send-string-to-terminal (concat "\e]2;" new "\e\\")))))) + +(add-hook 'post-command-hook 'mdw-update-terminal-title) + ;;;-------------------------------------------------------------------------- ;;; C programming configuration. @@ -4334,7 +4408,7 @@ This allows you to pass a list of arguments through `ansi-term'." ;;;-------------------------------------------------------------------------- ;;; Magit configuration. -(setq magit-diff-refine-hunk 'all +(setq magit-diff-refine-hunk 't magit-view-git-manual-method 'man magit-log-margin '(nil age magit-log-margin-width t 18) magit-wip-after-save-local-mode-lighter "" @@ -4426,6 +4500,41 @@ there is sadness." (set-window-dedicated-p (or window (selected-window)) nil)) ;;;-------------------------------------------------------------------------- +;;; Man pages. + +;; Turn off `noip' when running `man': it interferes with `man-db''s own +;; seccomp(2)-based sandboxing, which is (in this case, at least) strictly +;; better. +(defadvice Man-getpage-in-background + (around mdw-inhibit-noip (topic) compile activate) + "Inhibit the `noip' preload hack when invoking `man'." + (let* ((old-preload (getenv "LD_PRELOAD")) + (preloads (save-match-data (split-string old-preload ":"))) + (any nil) + (filtered nil)) + (while preloads + (let ((item (pop preloads))) + (if (save-match-data + (string-match "\\(/\\|^\\)noip\.so\\(:\\|$\\)" item)) + (setq any t) + (push item filtered)))) + (if any + (unwind-protect + (progn + (setenv "LD_PRELOAD" + (and filtered + (with-output-to-string + (setq filtered (nreverse filtered)) + (let ((first t)) + (while filtered + (if first (setq first nil) + (write-char ?:)) + (write-string (pop filtered))))))) + ad-do-it) + (setenv "LD_PRELOAD" old-preload)) + ad-do-it))) + +;;;-------------------------------------------------------------------------- ;;; MPC configuration. (eval-when-compile (trap (require 'mpc)))