X-Git-Url: https://git.distorted.org.uk/~mdw/profile/blobdiff_plain/18cdb02347fe06f0930369c27a7f363d9d830b73..56366becd663ec64162bb01ca33a85d70e549bdd:/el/dot-emacs.el diff --git a/el/dot-emacs.el b/el/dot-emacs.el index 0a5274c..34df1a0 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) @@ -355,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)) @@ -577,6 +588,34 @@ 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. + +(defvar mdw-inhibit-rename-buffer nil + "If non-nil, `rename-file' won't rename the buffer visiting the file.") + +(defmacro mdw-advise-to-inhibit-rename-buffer (function) + "Advise FUNCTION to set `mdw-inhibit-rename-buffer' while it runs. + +This will prevent `rename-file' from renaming the buffer." + `(defadvice ,function (around mdw-inhibit-rename-buffer compile activate) + "Don't rename the buffer when renaming the underlying file." + (let ((mdw-inhibit-rename-buffer t)) + ad-do-it))) +(mdw-advise-to-inhibit-rename-buffer recode-file-name) +(mdw-advise-to-inhibit-rename-buffer set-visited-file-name) +(mdw-advise-to-inhibit-rename-buffer backup-buffer) + +(defadvice rename-file (after mdw-rename-buffers (from to &optional forcep) + compile activate) + "If a buffer is visiting the file, rename it to match the new name. + +Don't do this if `mdw-inhibit-rename-buffer' is non-nil." + (unless mdw-inhibit-rename-buffer + (let ((buffer (get-file-buffer from))) + (when buffer + (with-current-buffer buffer + (set-visited-file-name to nil t)))))) + ;;;-------------------------------------------------------------------------- ;;; Improved compilation machinery. @@ -861,6 +900,11 @@ Use this to arrange for per-server settings.") :key #'car)))) ad-do-it)) +;; Preferred programs. + +(setq mailcap-user-mime-data + '(((type . "application/pdf") (viewer . "mupdf %s")))) + ;;;-------------------------------------------------------------------------- ;;; Utility functions. @@ -1275,7 +1319,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) @@ -1868,17 +1919,17 @@ doesn't match any of the regular expressions in mdw-point-overlay-mode (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t)))) -(defvar terminal-title-alist nil) +(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 terminal-title-alist #'string=)) + (old (assoc tty mdw-terminal-title-alist)) (new (format-mode-line frame-title-format))) - (unless (and old (string= (cdr old) new)) + (unless (and old (equal (cdr old) new)) (if old (rplacd old new) - (setq terminal-title-alist - (cons (cons tty new) terminal-title-alist))) + (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)