X-Git-Url: https://git.distorted.org.uk/~mdw/profile/blobdiff_plain/f617db13b0685c674817a6c7c1d148da3c07081f..8b2504c3d66bd867de2143d4223852918f425945:/dot-emacs.el?ds=sidebyside diff --git a/dot-emacs.el b/dot-emacs.el index 66f9190..4222f53 100644 --- a/dot-emacs.el +++ b/dot-emacs.el @@ -36,6 +36,47 @@ ,(if (cdr forms) (cons 'progn forms) (car forms)) (error (message "Error (trapped): %s" (error-message-string err))))) +;; --- Configuration reading --- + +(defvar mdw-config nil) +(defun mdw-config (sym) + "Read the configuration variable named SYM." + (unless mdw-config + (setq mdw-config (with-temp-buffer + (insert-file-contents "~/.mdw.conf") + (replace-regexp "^[ \t]*\\(#.*\\|\\)\n" "" + nil (point-min) (point-max)) + (replace-regexp (concat "^[ \t]*" + "\\([-a-zA-Z0-9_.]*\\)" + "[ \t]*=[ \t]*" + "\\(.*[^ \t\n]\\|\\)" + "[ \t]**\\(\n\\|$\\)") + "(\\1 . \"\\2\") " + nil (point-min) (point-max)) + (car (read-from-string + (concat "(" (buffer-string) ")")))))) + (cdr (assq sym mdw-config))) + +;; --- Is an Emacs library available? --- + +(defun library-exists-p (name) + "Return non-nil if NAME.el (or NAME.elc) is somewhere on the Emacs load +path. The non-nil value is the filename we found for the library." + (let ((path load-path) elt (foundp nil)) + (while (and path (not foundp)) + (setq elt (car path)) + (setq path (cdr path)) + (setq foundp (or (let ((file (concat elt "/" name ".elc"))) + (and (file-exists-p file) file)) + (let ((file (concat elt "/" name ".el"))) + (and (file-exists-p file) file))))) + foundp)) + +(defun maybe-autoload (symbol file &optional docstring interactivep type) + "Set an autoload if the file actually exists." + (and (library-exists-p file) + (autoload symbol file docstring interactivep type))) + ;; --- Splitting windows --- (defconst mdw-scrollbar-width (if window-system 6 1) @@ -251,6 +292,46 @@ Not much right now. Just support for doing MailCrypt stuff." (perform-replace "\n-- \n" "\n-- " nil nil nil))) (add-hook 'mail-setup-hook 'mdwmail-mangle-signature) +;;;----- URL viewing -------------------------------------------------------- + +(defun mdw-w3m-browse-url (url &optional new-session-p) + "Invoke w3m on the URL in its current window, or at least a different one. +If NEW-SESSION-P, start a new session." + (interactive "sURL: \nP") + (save-excursion + (let ((window (selected-window))) + (unwind-protect + (progn + (select-window (or (and (not new-session-p) + (get-buffer-window "*w3m*")) + (progn + (if (one-window-p t) (split-window)) + (get-lru-window)))) + (w3m-browse-url url new-session-p)) + (select-window window))))) + +(defvar mdw-good-url-browsers + '((w3m . mdw-w3m-browse-url) + browse-url-w3 + browse-url-mozilla) + "List of good browsers for mdw-good-url-browsers; each item is a browser +function name, or a cons (CHECK . FUNC). A symbol FOO stands for (FOO +. FOO).") + +(defun mdw-good-url-browser () + "Return a good URL browser. Trundle the list of such things, finding the +first item for which CHECK is fboundp, and returning the correponding FUNC." + (let ((bs mdw-good-url-browsers) b check func answer) + (while (and bs (not answer)) + (setq b (car bs) + bs (cdr bs)) + (if (consp b) + (setq check (car b) func (cdr b)) + (setq check b func b)) + (if (fboundp check) + (setq answer func))) + answer)) + ;;;----- Paragraph filling -------------------------------------------------- ;; --- Useful variables --- @@ -1010,7 +1091,7 @@ strip numbers instead." "del" "elif" "else" "except" "exec" "finally" "for" "from" "global" "if" "import" "in" "is" "lambda" "not" "or" "pass" "print" "raise" "return" "try" - "while")))) + "while" "yield")))) (setq font-lock-keywords (list 't @@ -1550,12 +1631,11 @@ strip numbers instead." "\\)\\>\\|[0-9]+\\|$\\)\\)") '(1 font-lock-keyword-face))) message-mode-keywords))) - (setq font-lock-defaults - '(message-mode-keywords nil nil nil nil)) (turn-on-font-lock-if-enabled) - (run-hooks 'messages-mode-hook)) + (run-hooks 'cpp-messages-mode-hook)) -(add-hook 'messages-file-hook 'mdw-misc-mode-config t) +(add-hook 'messages-mode-hook 'mdw-misc-mode-config t) +(add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t) ; (add-hook 'messages-file-hook 'mdw-fontify-messages t) ;;;----- Messages-file mode ------------------------------------------------- @@ -1729,7 +1809,7 @@ strip numbers instead." 'comint-watch-for-password-prompt)) (defun mdw-term-mode-setup () - (setq term-prompt-regexp "^[^]#$%>»\n]*[]#$%>»] *") + (setq term-prompt-regexp "^[^]#$%>»}\n]*[]#$%>»}] *") (make-local-variable 'mouse-yank-at-point) (make-local-variable 'transient-mark-mode) (setq mouse-yank-at-point t)