Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (when (require 'package nil t)
- (when (< emacs-major-version 24)
- ;; For important compatibility libraries like cl-lib
- (add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/")))
- (add-to-list 'package-archives
- '("melpa" . "https://melpa.org/packages/") t)
- (package-initialize))
- (if (string-equal (cadr command-line-args) "debug")
- (setq debug-on-error t))
- ; The following make emacs behave like emacs even for the Mac mappings of the
- ; external keyboard
- ; Command is control, alt and control become meta
- ;
- ; This deals with the horror of what xterm does do meta pageup and meta pagedown
- (global-set-key "\e[5;" (make-sparse-keymap))
- (global-set-key "\e[6;" (make-sparse-keymap))
- (global-set-key "\e[5;3" (make-sparse-keymap))
- (global-set-key "\e[6;3" (make-sparse-keymap))
- (global-set-key "\e[5;3~" 'beginning-of-buffer)
- (global-set-key "\e[6;3~" 'end-of-buffer)
- (global-set-key [C-return] 'set-mark-command) ;; Mac OSX steals command-space as Spotlight
- (unless (string= emacs-version "23.1.1")
- (unless (display-graphic-p)
- (set-keyboard-coding-system nil)))
- (unless (display-graphic-p)
- ;; deal with the Unicode sequences that xterm sends when Alt (meta) keys
- ;; are used. N.B. Works with Alt-letter, Alt-\, Alt-space, and Alt-Shift-:
- (defun make-meta-key ()
- (interactive)
- (let ((e (read-event)))
- ;; (message "Got event %s; basic event is %s" e (event-basic-type e))
- (if (numberp e)
- (let* ((basic (event-basic-type e))
- (shifted (+ basic 64))
- (basecode (if (<= shifted 127) shifted basic))
- (keys (vector (event-convert-list (list 'meta basecode))))
- (command (key-binding keys)))
- ;; (message "Result is %s; commandp says %s" command (commandp command))
- (command-execute command))
- (error "this can't happen"))))
- (global-set-key [?\M-C] 'make-meta-key)
- (defun do-nothing () (interactive) nil)
- (global-set-key [?\M-B] 'do-nothing))
- (when (display-graphic-p)
- (global-set-key "" 'undo))
- (global-set-key (kbd "C-`") 'undo)
- (global-set-key "\e" 'suspend-emacs) ; maybe 'suspend-frame ?
- (setq mac-command-modifier 'control)
- (setq mac-option-modifier 'meta)
- (setq mac-control-modifier 'meta)
- (setq x-select-enable-clipboard 't)
- (add-to-list 'load-path "~nr/emacs")
- (add-to-list 'load-path "/usr/share/emacs/site-lisp/emacs-goodies-el")
- (add-to-list 'auto-mode-alist (cons "\\.rkt$" 'scheme-mode))
- (defun force-compile-key ()
- (interactive)
- (local-set-key (kbd "C-c C-C") 'compile))
- (add-hook 'scheme-mode-hook 'force-compile-key)
- (require 'tex-mode)
- (setq tex-indent-arg 0)
- (setq tex-indent-basic 0)
- (setq tex-indent-item tex-indent-basic)
- ;;(require 'electric) ;; tried to turn off using customization
- ;;(electric-indent-mode -1) ;; weird way to turn it off
- (add-to-list 'auto-mode-alist (cons "\\.tex$" 'latex-mode))
- (condition-case nil
- (load-library "quack")
- (error nil))
- (when (fboundp 'quack-install)
- (quack-install))
- (defvar noweb-support 'mini
- "Internal configuration in NR's .emacs file to control whether noweb files
- are edited using mmm-mode or noweb-mode. Value is a symbol and should be
- either mmm or noweb or love or mini.")
- (setq noweb-support 'love)
- (defun turn-off-electric-indent-mode ()
- (electric-indent-local-mode t))
- (add-hook 'text-mode-hook 'turn-off-electric-indent-mode)
- (defun disable-compile-shortcut ()
- (local-set-key (kbd "C-c C-c") 'with-editor-finish))
- (add-hook 'text-mode-hook 'disable-compile-shortcut t)
- (unless (= emacs-major-version 23)
- (when (require 'filladapt nil t)
- (add-hook 'text-mode-hook 'turn-on-filladapt-mode)
- (global-set-key (kbd "C-x f") 'filladapt-mode)
- ;(setq noweb-support 'ess)) ;; not working on yorkie
- ))
- (if nil
- (when
- (require 'polymode nil 'no-error)
- (when
- (load "noweb-poly" 'no-error 'no-message)
- (setq noweb-support 'poly)
- (load-library "noweb-love"))) ;; for old files not yet converted
- )
- (if (eq noweb-support 'noweb)
- (progn
- (defun open-line-and-reparse (arg)
- "Insert a newline and leave point before it.
- If there is a fill prefix and/or a left-margin, insert them on the new line
- if the line would have been blank.
- With arg N, insert N newlines.
- After the insertion, reparse the boundaries between code and documentation."
- (interactive "*p")
- (open-line arg)
- (noweb-update-chunk-vector))
- ;(autoload 'noweb-mode "~/emacs/noweb-mode" "Editing noweb files." t)
- (add-to-list 'auto-mode-alist (cons "\\.nw$" 'noweb-mode))
- (defun set-up-noweb-mode () "set preferences for noweb" (interactive)
- (font-lock-mode 0)
- (local-set-key "\C-o" 'open-line-and-reparse)
- (noweb-update-chunk-vector)
- )
- (add-hook 'noweb-mode-hook 'set-up-noweb-mode)
- (if (or (string-match "20\\.4\\(\\.[0-9]+\\)?" emacs-version)
- (string-match "21\\.[0-9]+\\(\\.[0-9]+\\)?" emacs-version))
- (add-hook 'noweb-select-mode-hook
- '(lambda () (hack-local-variables-prop-line)))
- (message "Not sure about noweb-select-mode-hook in emacs version %s"
- emacs-version))
- (require 'cc-mode)
- (c-set-offset 'brace-list-entry 0) ; makes noweb happy
- ))
- (defun filter-not (f xs)
- (if (null xs)
- xs
- (if (funcall f (car xs))
- (filter-not f (cdr xs))
- (cons (car xs) (filter-not f (cdr xs))))))
- (defun this-para-fill-prefix ()
- "Show the fill prefix for this paragraph"
- (interactive)
- (fill-context-prefix
- (save-excursion (fill-forward-paragraph -1) (point))
- (save-excursion (fill-forward-paragraph 1) (point))))
- ;; (require 'desktop)
- ;; (defvar old-desktop-save)
- ;; (fset 'old-desktop-save (symbol-function 'desktop-save))
- ;; (if (string-match "23\\.2\\(\\.[0-9]+\\)?" emacs-version)
- ;; (let ((old-buffer-list (symbol-function 'buffer-list)))
- ;; (fset 'old-buffer-list old-buffer-list)
- ;; (defun desktop-save (dirname &optional release)
- ;; "Save the desktop in a desktop file.
- ;; Parameter DIRNAME specifies where to save the desktop file.
- ;; Optional parameter RELEASE says whether we're done with this desktop.
- ;; See also `desktop-base-file-name'."
- ;; (interactive "DDirectory to save desktop file in: ")
- ;; (flet ((buffer-list ()
- ;; (filter-not 'buffer-base-buffer
- ;; (funcall 'old-buffer-list))))
- ;; (funcall 'old-desktop-save dirname release)))))
- (add-hook 'kill-emacs-hook 'kill-indirect-buffers)
- (defun kill-indirect-buffers ()
- "Kill all indirect buffers"
- (interactive)
- (dolist (b (buffer-list))
- (if (buffer-base-buffer b)
- (kill-buffer b))))
- (require 'compile)
- (setq compile-command "mk")
- (autoload 'knoweb-mode "knoweb")
- ;; (add-hook 'mmm-noweb-class-hook 'knoweb-mode)
- (when (eq noweb-support 'mmm)
- (require 'mmm-mode)
- (setq mmm-global-mode 'buffers-with-submode-classes)
- (mmm-add-mode-ext-class 'latex-mode "\\.nw\\'" 'noweb)
- (add-to-list 'auto-mode-alist '("\\.nw$" . latex-mode))
- (setq mmm-submode-decoration-level 2)
- (defun emulate-noweb-reparse-in-mmm
- () "Set noweb reparse key to reparse in mmm-mode"
- (local-set-key "\M-n\M-l" 'mmm-parse-buffer)
- (local-set-key "\M-n\M-n" 'mmm-narrow-to-submode-region)
- )
- (add-hook 'mmm-noweb-class-hook 'emulate-noweb-reparse-in-mmm)
- )
- (if (eq noweb-support 'love)
- (progn
- (load-library "noweb-love")
- ;(add-to-list 'auto-mode-alist '("\\.nw$" . noweb-mode))
- ))
- (when (eq noweb-support 'ess)
- (require 'ess-noweb-mode)
- (require 'ess-noweb-font-lock-mode)
- (add-to-list 'auto-mode-alist '("\\.nw$" . ess-noweb-mode))
- )
- (autoload 'mini-noweb-mode "mini-noweb-mode" "Bare-bones noweb support." t)
- (if (eq noweb-support 'mini)
- (progn
- (load-library "mini-noweb-mode")
- (add-to-list 'auto-mode-alist '("\\.nw$" . mini-noweb-mode))
- (defun noweb-mode (mini-noweb-mode))
- ))
- ; work around haskell-ghci bug
- (setq inhibit-site-startup-message t)
- (setq inhibit-splash-screen t)
- (setq inhibit-site-start t)
- (setq vc-handle-cvs nil)
- (if (fboundp 'one-buffer-one-frame-mode)
- (one-buffer-one-frame-mode nil))
- (or (fboundp 'add-to-list)
- ;; Introduced in Emacs 19.29.
- (defun add-to-list (list-var element)
- "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
- If you want to use `add-to-list' on a variable that is not defined
- until a certain package is loaded, you should put the call to `add-to-list'
- into a hook function that will be run only after loading the package.
- `eval-after-load' provides one way to do this. In some cases
- other hooks, such as major mode hooks, can do the job."
- (or (member element (symbol-value list-var))
- (set list-var (cons element (symbol-value list-var))))))
- (setq automounter-pattern "/automounter")
- ; (add-to-list 'load-path "/usr/lib/emacs/site-lisp")
- (require 'scroll-in-place)
- (global-set-key [mouse-5] 'scroll-up)
- (global-set-key [mouse-4] 'scroll-down)
- ;(load "~nr/emacs/flow-control")
- ;(no-flow-control) ; PC/IC doesn't require it!
- ;(load "~nr/emacs/arrow") ; arrow keys for WYSE
- ;(load-file "/usr/local/src/clu/elisp/setup.el")
- (if (file-readable-p "/usr/local/teTeX/info/dir")
- (setq Info-default-directory-list
- (append Info-default-directory-list '("/usr/local/teTeX/info/"))))
- (if (file-readable-p "/usr/share/info/dir")
- (setq Info-default-directory-list
- (append Info-default-directory-list '("/usr/share/info/"))))
- (setq twelf-root "/home/nr/net/twelf/")
- ;(load (concat twelf-root "emacs/twelf-init.el"))
- (if (not (fboundp 'add-hook))
- (defun add-hook (hook function &optional append)
- "Add to the value of HOOK the function FUNCTION unless already present.
- \(It becomes the first hook on the list unless optional APPEND is non-nil, in
- which case it becomes the last). HOOK should be a symbol, and FUNCTION may be
- any valid function. HOOK's value should be a list of functions, not a single
- function. If HOOK is void, it is first set to nil."
- (or (boundp hook) (set hook nil))
- (set hook
- (if append
- (nconc (symbol-value hook) (list function))
- (cons function (symbol-value hook))))))
- (defun require-comint ()
- (require 'comint))
- (setq sl2h-ok-without-prompting nil)
- (defun sl2h (p1 p2)
- "Convert latex to html in region"
- (interactive "r")
- (if (or sl2h-ok-without-prompting
- (y-or-n-p "Convert region from LaTeX to HTML? "))
- (shell-command-on-region p1 p2 "sl2h" nil 't))
- )
- (defun sl2h-without-prompting ()
- "Make sl2h work without prompting (local to buffer)"
- (interactive)
- (make-local-variable 'sl2h-ok-without-prompting)
- (setq sl2h-ok-without-prompting 't)
- )
- (setq pandoc-without-prompting nil)
- (defun pandoc (p1 p2)
- "Convert markdown to html in region using pandoc"
- (interactive "r")
- (if (or pandoc-without-prompting
- (y-or-n-p "Convert region from Pandoc Markdown to HTML? "))
- (shell-command-on-region p1 p2 "pandoc -S --columns=72" nil 't))
- )
- (defun m2l (p1 p2)
- "Convert markdown to latex in region"
- (interactive "r")
- (when (y-or-n-p "Convert region from Markdown to LaTeX? ")
- (shell-command-on-region p1 p2 "m2l" nil 't)))
- (defun html2ascii (p1 p2)
- "Convert html to ascii in region"
- (interactive "r")
- (shell-command-on-region p1 p2 "html2ascii" nil 't)
- )
- (global-set-key "\M-s" 'sl2h)
- (defun change-meta-s ()
- (local-set-key "\M-s" 'sl2h))
- (defun change-close-block ()
- (define-skeleton latex-close-block
- "Create an \\end{...} to match the last unclosed \\begin{...}."
- (save-excursion
- (tex-last-unended-begin)
- (if (not (looking-at "\\\\begin\\(\\s *{[^}\n]*}\\)")) '("{" _ "}")
- (match-string 1)))
- "\\end" str "\n"))
- ;; (when (boundp 'adaptive-fill-first-line-regexp)
- ;; (setq adaptive-fill-first-line-regexp
- ;; (purecopy "\\`\\([ \t]*\\|[ \t]*[-.*>]+[ \t]+\\|[ \t]*[0-9]+\\.[ \t]+\\)\\'")))
- ;;
- ;; (setq adaptive-fill-regexp "[ ]*\\([-|#;>*.]+ *\\|(?[0-9]+[.):] *\\)*")
- (add-hook 'text-mode-hook 'turn-on-auto-fill)
- (add-hook 'text-mode-hook
- (function (lambda ()
- (require 'flyspell)
- (unless flyspell-mode
- (flyspell-mode)))))
- ;;*---------------------------------------------------------------------*/
- ;;* flyspell-goto-previous-word ... */
- ;;*---------------------------------------------------------------------*/
- (defun flyspell-goto-previous-word (position)
- "Go to the first misspelled word that occurs before point.
- But don't look beyond what's visible on the screen."
- (interactive "d")
- (let ((top (window-start))
- (bot (window-end)))
- (save-restriction
- (narrow-to-region top bot)
- (overlay-recenter (point))
- (add-hook 'pre-command-hook
- (function flyspell-auto-correct-previous-hook) t t)
- (unless flyspell-auto-correct-previous-pos
- ;; only reset if a new overlay exists
- (setq flyspell-auto-correct-previous-pos nil)
- (let ((overlay-list (overlays-in (point-min) position))
- (new-overlay 'dummy-value))
- ;; search for previous (new) flyspell overlay
- (while (and new-overlay
- (or (not (flyspell-overlay-p new-overlay))
- ;; check if its face has changed
- (not (eq (get-char-property
- (overlay-start new-overlay) 'face)
- 'flyspell-incorrect))))
- (setq new-overlay (car-safe overlay-list))
- (setq overlay-list (cdr-safe overlay-list)))
- ;; if nothing new exits new-overlay should be nil
- (if new-overlay ;; the length of the word may change so go to the start
- (setq flyspell-auto-correct-previous-pos
- (overlay-start new-overlay)))))
- (if (not flyspell-auto-correct-previous-pos)
- nil
- (goto-char flyspell-auto-correct-previous-pos)
- t))))
- (add-hook 'text-mode-hook (function (lambda () (abbrev-mode 1))))
- (add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))
- (add-hook 'tex-mode-hook
- (function (lambda ()
- (set (make-local-variable 'search-whitespace-regexp)
- "[ \t\r\n\f~]+"))))
- (add-hook 'TeX-mode-hook 'set-up-tex-mode)
- (add-hook 'tex-mode-hook 'set-up-tex-mode)
- (add-hook 'text-mode-hook 'change-meta-s)
- (add-hook 'latex-mode-hook 'change-meta-s)
- (add-hook 'TeX-mode-hook 'change-meta-s)
- (add-hook 'latex-mode-hook 'set-up-tex-mode)
- ;(add-hook 'haskell-mode-hook 'turn-off-haskell-font-lock)
- (add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
- (add-hook 'haskell-mode-hook 'require-comint) ;; bug workaround
- ;(global-set-key "" 'previous-line)
- ;(global-set-key "" 'suspend-emacs)
- ;(global-set-key "s" 'save-buffer)
- ;(global-set-key "\er" 'isearch-backward)
- (global-set-key "c" 'center-line)
- (global-set-key "" 'auto-fill-mode)
- (global-set-key [M-C-y] 'clipboard-yank)
- ; use M-pageup and M-oagedown to go to start and end of document
- (global-set-key [M-prior] 'beginning-of-buffer)
- (global-set-key [M-next] 'end-of-buffer)
- ;(setq Info-default-directory-list
- ; (append Info-default-directory-list
- ; '("/p/TeX/info")))
- (autoload 'html-helper-mode "tempo.el" "Tempo Template Library" t)
- (autoload 'html-helper-mode "html-helper-mode.el" "HTML Helper Mode" t)
- (autoload 'longlines-mode "longlines.el" "Minor mode for editing long lines." t)
- (defun newline-back () "enter a newline; then go back"
- (interactive)
- (newline)
- (backward-char))
- (defun make-C-o-newline-back () "rebind C-o for longlines mode"
- (interactive)
- (local-set-key "" 'newline-back))
- (add-hook 'longlines-mode-hook 'make-C-o-newline-back)
- ;(autoload 'camldebug "camldebug.el" "OCaml debugger" t)
- (autoload 'tuareg-mode "tuareg" "Major mode for editing Caml code" t)
- (autoload 'camldebug "camldebug-tuareg.el" "Run the Caml debugger" t)
- ; Necessary customizations for html-helper-mode
- (setq html-helper-do-write-file-hooks t)
- (setq html-helper-build-new-buffer t)
- (put 'eval-expression 'disabled nil)
- (set-variable 'spell-command "ispell -l")
- (defun omegamacs () "Load omega macros" (interactive)
- (load "~nr/emacs/omega")
- )
- ; Underline a section title with ~~~~ or another car, as per SLPJ
- (defun underline-with-char (char)
- "Underline the previous line with copies of the character passed as argument"
- (forward-line -1)
- (let* ((bol (point))
- (eol (progn (end-of-line) (point)))
- (n (- eol bol)))
- (forward-line 1)
- (insert-char char n)
- (insert-char ?\n 1))
- )
- (defun underline-with-tildes () "Underline the previous line with tildes"
- (interactive)
- (underline-with-char ?~))
- (defun underline-with-dashes (c) "Underline the previous line with dashes"
- (interactive "P")
- (underline-with-char (if (consp c) ?= ?-)))
- ; Highlight words
- (defun highlight-word () "Put stars around the current word (a little bogus)"
- (interactive)
- (backward-word 1)
- (insert-char ?* 1)
- (forward-word 1)
- (insert-char ?* 1)
- (forward-word 1)
- (backward-word 1)
- (forward-char 1)
- )
- (load-library "lua-mode")
- (add-hook 'lua-mode-hook 'font-lock-fontify-buffer)
- (defun lua-header-comment ()
- "Make current line a 'section header' Lua comment"
- (interactive)
- (let* ((bol (progn (beginning-of-line) (point)))
- (bos (if (not (looking-at "[ \t]+"))
- (point)
- (re-search-forward "[ \t]+")))
- (eos (progn
- (end-of-line) (point)))
- (spaces (- bos bol))
- (width (- 72 spaces))
- (string-width (- width (- eos bos)))
- (dashes (- (/ string-width 2) 1)) ; leave room for space
- (extra (if (= (* 2 (+ 1 dashes)) string-width) "" "-")))
- (goto-char bos)
- (insert-char ?- dashes)
- (insert-char ?\ 1)
- (end-of-line)
- (insert-char ?\ 1)
- (insert-char ?- dashes)
- (insert extra)
- (beginning-of-line)
- (insert-char ?\ spaces)
- (insert-char ?- width)
- (insert-char ?\n 1)
- (end-of-line)
- (insert-char ?\n 1)
- (insert-char ?\ spaces)
- (insert-char ?- width)
- (beginning-of-line)
- (forward-line 1))
- )
- (global-set-key "\C-X~" 'underline-with-tildes)
- (global-set-key "\C-X-" 'underline-with-dashes)
- (global-set-key "\M-*" 'highlight-word)
- (global-set-key "\M-8" 'highlight-word)
- (defun ccc () "Short form of M-x compile" (interactive)
- (compile)
- )
- (defun learn-spam (&optional classification) "Change reply to learn spam" (interactive)
- (goto-char (point-min))
- (if (re-search-forward "^To:[ ]*" nil t)
- (let ((beg (point)))
- (end-of-line)
- (delete-region beg (point))
- (insert " nr")))
- (goto-char (point-min))
- (if (re-search-forward "^Subject:[ ]" nil t)
- (let ((beg (point)))
- (end-of-line)
- (delete-region beg (point))
- (insert " learn antiSpam! ")
- (if classification (insert classification) (insert "spam"))))
- (if (re-search-forward "^----" nil t)
- (progn (beginning-of-line 2)
- (let ((beg (point)))
- (goto-char (point-max))
- (delete-region beg (point)))))
- (goto-char (point-min))
- (re-search-forward "^Subject:.*antiSpam! " nil t)
- )
- (defun learn-ham () "Change reply to learn ham/nonspam" (interactive)
- (learn-spam "nonspam"))
- (defun learn-nonspam () "Change reply to learn ham/nonspam" (interactive)
- (learn-spam "nonspam"))
- (defun tag-subject-ANSWER () "Make [ANSWER] sole tag on subject line"
- (interactive)
- (save-excursion
- (goto-char (point-min))
- (if (re-search-forward "^Subject:[ ]" nil t)
- (progn
- (save-excursion
- (let ((my-eol (save-excursion (end-of-line) (point))))
- (while (re-search-forward "\\[[^]]*\\]\\( Re:\\)? *" my-eol t)
- (replace-match ""))))
- (insert "[ANSWER] ")))))
- (defun cs152 () "Insert cs152 headers" (interactive)
- (save-excursion
- (goto-char (point-min))
- (if (re-search-forward "^To:" nil t) (replace-match "Bcc:" t))
- (goto-line 3)
- (insert "To: cs152, cs152-news\nReply-to: cs152@fas.harvard.edu\n")
- (tag-subject-ANSWER)))
- (defun x-np152-not-operative-now () "Insert cs152 headers but don't post" (interactive)
- (save-excursion
- (goto-line 3)
- (insert "Cc: cs152\nReply-to: cs152@fas.harvard.edu\n")
- (tag-subject-ANSWER)
- (goto-char (point-min))
- (if (re-search-forward "^--------\n" nil t) (insert "[not posted]\n\n"))))
- (defun x-comp40-inactive () "Insert comp40 headers" (interactive)
- (save-excursion
- (goto-char (point-min))
- (if (re-search-forward "^To:" nil t) (replace-match "Bcc:" t))
- (if (re-search-forward "^Comments: In-reply-to.*") (replace-match "Comments: [redacted]"))
- (goto-line 3)
- (insert "To: comp40\nReply-to: comp40-staff@cs.tufts.edu\n")
- (tag-subject-ANSWER)))
- (defun x-comp40-old () "Old Insert comp40 headers" (interactive)
- (save-excursion
- (goto-char (point-min))
- (if (re-search-forward "^To:" nil t) (replace-match "Bcc:" t))
- (if (re-search-forward "^Comments: In-reply-to.*") (replace-match "Comments: [redacted]"))
- (goto-line 3)
- (insert "To: comp40\nReply-to: comp40-staff@cs.tufts.edu\n")
- (goto-char (point-min))
- (if (re-search-forward "^Subject:[ ]" nil t) (insert "[ANSWER] "))))
- (defun x-np40-inactive () "Insert comp40 headers but don't post" (interactive)
- (save-excursion
- (goto-line 3)
- (insert "Cc: comp40-staff@cs.tufts.edu\nReply-to: comp40-staff@cs.tufts.edu\n")
- (tag-subject-ANSWER)
- (goto-char (point-min))
- (if (re-search-forward "^--------\n" nil t) (insert "[private response]\n\n"))))
- (defun comp105 () "Insert comp105 headers" (interactive)
- (save-excursion
- (goto-char (point-min))
- (if (re-search-forward "^To:" nil t) (replace-match "Bcc:" t))
- (if (re-search-forward "^Comments: In-reply-to.*") (replace-match "Comments: [redacted]"))
- (goto-line 3)
- (insert "To: comp105\nReply-to: comp105-staff@cs.tufts.edu\n")
- (tag-subject-ANSWER)))
- (defun np105 () "Insert comp105 headers but don't post" (interactive)
- (save-excursion
- (goto-line 3)
- (insert "Cc: comp105-staff@cs.tufts.edu\nReply-to: comp105-staff@cs.tufts.edu\n")
- (tag-subject-ANSWER)
- (goto-char (point-min))
- (if (re-search-forward "^--------\n" nil t) (insert "[private response]\n\n"))))
- (defun better-transpose (number)
- "Transpose characters before point" (interactive "p")
- (backward-char)
- (transpose-chars number)
- )
- (defun better-transpose-words (number)
- "Transpose words before point" (interactive "p")
- (forward-word -1)
- (transpose-words 1)
- )
- (global-set-key "\C-t" 'better-transpose)
- (global-set-key "\M-t" 'better-transpose-words)
- (defun better-up-list (number)
- "Move forward out of one level of parentheses, setting mark. Vide up-list"
- (interactive "p")
- (point-to-register 64)
- (exchange-point-and-mark)
- (register-to-point 64)
- (up-list number)
- )
- (defun double-quote () "Insert a double quote" (interactive)
- (tex-insert-quote 1)
- )
- (defun recognize-ocaml-error-messages
- ()
- "Add regexp for OCaml error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; OCaml
- ;; File "foo.nw", line 4, characters 9-24:
- "^File \"\\(.+\\)\", line \\([0-9]+\\), characters? \\([0-9]+\\).*:"
- 1 2 3
- )
- )
- )
- (defun recognize-utlnx-error-messages
- ()
- "Add regexp for validate-utlnx error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; validate-utlnx
- ;; scheme.grades, line 418: column scm5 for mleise01 does not include a grade
- "^\\([^[:space:]]+\\), line *\\([0-9]+\\):"
- 1 2
- )
- )
- )
- (defun recognize-lint-error-messages
- ()
- "Add regexp for ml-lint error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; sml-lint
- ;; top.sml, line 418, column 50: redundant parentheses around name
- "^\\([^[:space:]]+\\), line *\\([0-9]+\\), *column *\\([0-9]+\\):"
- 1 2 3
- )
- )
- )
- (defun recognize-gcc-error-messages
- ()
- "Add regexp for gcc error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; gcc
- ;; impcore.nw:2039:1: error: unknown type name ‘Def’
- ;;
- "^\\([^ \t\n:.][^ \n\t:]*\\):\\([0-9]+\\):\\([0-9]+\\): error"
- 1 2 3
- )
- ))
- (recognize-gcc-error-messages)
- (defun recognize-lua-error-messages
- ()
- "Add regexp for Lua error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; Lua
- ;; <tab>File:line: in function:
- "^\t\\(.+\\):\\([0-9]+\\): in \\(function\\|method\\|main chunk\\|string\\|field\\|local\\| \n\\)"
- 1 2
- )
- )
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; Lua
- ;; <tab>File:line: ...
- "^\t\\(.+lua\\):\\([0-9]+\\):"
- 1 2
- )
- )
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; Lua
- ;; /usr/bin/lua[0-9.]*: file:line:
- "^/usr/bin/lua[0-9\\.]*: \\(.+\\):\\([0-9]+\\): "
- 1 2
- )
- )
- )
- (defun recognize-sml-nj-error-messages ()
- "Add regexps for SML/NJ or \-RTL error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; Standard ML of New Jersey, \-RTL
- ;; usm.nw:8217.5...usm.nw:8228.6 Error: case object and rules don't agree...
- "^\\([^<>\n\t].*\\):\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\.\\..+\\(Error\\|Warning\\):"
- 1 2 3
- )
- )
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; Standard ML of New Jersey, \-RTL
- ;; unifailed.rtl:49.26-49.56 Error:
- ;; Function
- ;; byte
- ;; expected >>> #8 bits <<< but argument was >>> #64 loc <<<
- ;; --> failed to unify >>> #8 <<< and >>> #64 <<<
- "^\\([^<>\n\t][^\n\t .]*\\(\\.[^.\n\t\ ]+\\)*\\):\\([0-9]+\\)\\.\\([0-9]+\\).+\\(Error\\|Warning\\):"
- 1 3 4
- )
- )
- )
- (defun recognize-mlton-error-messages ()
- "Add regexp for MLton error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; MLton
- ;; Error: mlschemea.nw 289.25.
- "^Error: \\([^<>\n\t].*\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\."
- 1 2 3
- )
- )
- )
- (defun recognize-lcc-error-messages
- ()
- "Add regexp for lcc error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; lcc
- ;; gc1.c: gc1.nw:1584: warning: missing prototype
- ;;
- "^\\([^:<>\n\t ].*: \\)* \\([^:\n]+\\):\\([0-9]+\\):"
- 2 3
- )
- )
- )
- (defun recognize-ghc-error-messages
- ()
- "Add regexp for ghc error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; ghc
- ;; DiceUnknown.hs:38:24:
- ;;
- "^\\([^<>: \n\t][^\n: <>]*\\):\\([0-9]+\\):\\([0-9]+\\):"
- 1 2 3
- )
- )
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; ghc
- ;; codeGen/CgInfoTbls.hs:260: Variable not in scope: `orElse'
- ;;
- "^\\([^<>: \n\t][^\n: <>]*\\):\\([0-9]+\\):[^0-9]"
- 1 2
- )
- )
- (add-to-list 'compilation-search-path "..")
- )
- (defun recognize-lua-stack-traces
- ()
- "Add regexp for Lua stack-trace error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; lua
- ;; /home/nr/cs/105/server/evaluation/sml.lua:144: '}' expected (to close '{' at line 138) near 'F'
- ;;
- "^\t\\([^ \t\n:.][^ \t\n:]*\\):\\([0-9]+\\):"
- 1 2
- )
- )
- (add-to-list 'compilation-search-path "..")
- )
- (defun recognize-icon-error-messages ()
- "Add regexp for Icon error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (add-to-list 'compilation-error-regexp-alist
- '(
- ;; Icon
- ;; File foo.nw; Line 4 # ")" : missing right bracket
- "^File \\(.+\\); Line \\([0-9]+\\) #.*:"
- 1 2
- )
- )
- )
- (defun recognize-no-error-messages ()
- "Remove all regexps for error messages"
- (interactive)
- (setq compilation-error-regexp-alist '()))
- (defun recognize-all-ml-error-messages ()
- "Add regexp for SML/NJ or \-RTL or OCaml error messages to the regexp list used by M-x compile and compilation-mode"
- (interactive)
- (recognize-sml-nj-error-messages)
- (recognize-mlton-error-messages)
- (recognize-lcc-error-messages)
- (recognize-ocaml-error-messages))
- (defun set-up-tex-mode () "Put better-up-list in" (interactive)
- (local-set-key "\e}" 'better-up-list)
- (local-set-key "\e\"" 'double-quote)
- (local-set-key "\C-j" 'newline-and-indent)
- (local-set-key "\C-c\C-c" 'compile)
- (abbrev-mode 1)
- )
- (defun c-c-compiles () "Make C-c run M-x compile" (interactive)
- (local-set-key "\C-c\C-c" 'compile)
- )
- (defun set-up-tuareg-mode () "Customize tuareg-mode" (interactive)
- (setq tuareg-in-indent 0) ; no indentation after `in' keywords
- )
- (add-hook 'tuareg-mode-hook 'set-up-tuareg-mode)
- (defun makefile-mode-preferences () "set preferences for makefile mode" (interactive)
- (local-set-key "\C-c\C-c" 'compile)
- )
- (add-hook 'makefile-mode-hook 'makefile-mode-preferences)
- (add-hook 'after-change-major-mode-hook
- (function (lambda ()
- (unless (or (equal major-mode 'text-mode)
- (derived-mode-p 'special-mode))
- (c-c-compiles)))))
- (set-variable 'icon-indent-level 2)
- (defun icon-mode-preferences () "set preferences for icon mode" (interactive)
- (set-variable 'icon-indent-level 2)
- (local-set-key "\C-c\C-c" 'compile)
- )
- (add-hook 'icon-mode-hook 'icon-mode-preferences)
- (defun hanson () "Use Hanson's indentation conventions" (interactive)
- (set-variable 'c-indent-level 8)
- (set-variable 'c-continued-statement-offset 8)
- (set-variable 'c-label-offset -4)
- )
- ;(global-set-key "" 'suspend-emacs)
- (setq default-abbrev-file "~nr/emacs/abbrevs")
- (setq default-abbrev-file "~nr/.abbrev_defs")
- (defun new-abbrevs () "read the default abbrev file" (interactive)
- (read-abbrev-file default-abbrev-file)
- (setq save-abbrevs nil) ; don't bleat every time I run mk
- (setq save-abbrevs t) ; but don't lose my new abbrevs!
- )
- (defun edit-abbrevs() "edit the default abbrev file" (interactive)
- (find-file default-abbrev-file)
- )
- (new-abbrevs)
- (global-set-key "\C-X\C-A" 'abbrev-mode)
- (put 'minibuffer-complete-and-exit 'disabled nil)
- (defun ignore-completion-extension (s) "ignore an extension"
- (if (member s completion-ignored-extensions)
- completion-ignored-extensions
- (setq completion-ignored-extensions
- (cons s completion-ignored-extensions))))
- (ignore-completion-extension ".ps")
- (ignore-completion-extension ".pdf")
- (ignore-completion-extension ".pro")
- (ignore-completion-extension ".hi")
- (ignore-completion-extension ".hc")
- (defun bad-rev () "Revert buffer, with shorter querty" (interactive)
- (if (y-or-n-p "Revert buffer, losing undo information? ")
- (save-excursion ;; not sufficient to restore point!
- (revert-buffer 't 't)))
- )
- (defun rev () "Revert buffer, with shorter querty" (interactive)
- (if (y-or-n-p "Revert buffer, losing undo information? ")
- (let ((cur (point)))
- (unwind-protect
- (save-excursion
- (revert-buffer 't 't)
- (goto-char cur))
- (goto-char cur))))
- )
- (global-set-key "\er" 'rev)
- (defun flow-control () "Remap keys for flow control" (interactive)
- (load "~nr/emacs/xon")
- )
- (defun no-flow-control () "Undo effects of flow-control" (interactive)
- (load "~nr/emacs/xoff")
- )
- (set-variable 'c-indent-level 2)
- (defun mark-mail () "Put arrows in mail" (interactive)
- (replace-regexp "^[ ]" "> "))
- (defun unmark-mail () "Remove arrows from mail" (interactive)
- (replace-regexp "^> " ""))
- (defun insert-arrows () "Add arrows in column 1" (interactive)
- (replace-regexp "^" "> "))
- (defun print-current-line () "Print current line and column number" (interactive)
- (message "On line %d, column %d. (bogus ml-lex yypos %d, column %d)"
- (+ (count-lines 1 (point))
- (if (= (current-column) 0) 1 0))
- (- (point)
- (save-excursion
- (beginning-of-line)
- (point)))
- (+ (- (point) (point-min)) 2)
- (+ (- (point)
- (save-excursion
- (beginning-of-line)
- (point)))
- 1)))
- (defun shell-command-replace (command)
- "Run shell command on region and replace it"
- (interactive "sCommand to run on region: ")
- (shell-command-on-region (mark) (point) command nil 't)
- )
- (defvar nr-block-string "/*nr*/" "*string inserted by nr-block function")
- (defun nr-block (count) "(nr-block count) inserts count lins of nr-block-string"
- (interactive "Nnumber of lines to insert? ")
- (let ((col (current-column)))
- (while (> count 0)
- (progn
- (insert nr-block-string)
- (forward-line)
- (move-to-column col 't)
- (setq count (- count 1))))
- (if (eolp) (delete-horizontal-space))))
- (defun unquote ()
- "Unquote quoted-printable = sign escapes"
- (interactive)
- (shell-command-on-region (mark) (point)
- "sed 's/^ > //g' | unquote | sed 's/^/ > /'" nil 't)
- )
- (defun filed-with-reprints () "Insert where= in bibtex file" (interactive)
- (beginning-of-line)
- (insert " where=\"filed with reprints\",\n")
- )
- (global-set-key "\eg" 'goto-line)
- (global-set-key "\C-Xl" 'print-current-line)
- (defun adjust-lua-indent-level ()
- (set-variable 'lua-indent-level 2))
- (autoload 'html-mode "~/emacs/html-mode" "Editing HTML files." t)
- (defun html-mode-c-c-compile () "Make C-c C-c call M-x compile" (interactive)
- (define-key html-mode-map "\C-c\C-c" 'compile))
- (add-hook 'html-hook 'html-mode-c-c-compile t)
- (setq auto-mode-alist (append (list (cons "\\.html$" 'html-mode))
- auto-mode-alist))
- (setq auto-mode-alist
- (append auto-mode-alist
- '(("\\.[hg]s$" . haskell-mode)
- ("\\.hi$" . haskell-mode)
- ("\\.l[hg]s$" . literate-haskell-mode))))
- (autoload 'haskell-mode "haskell-mode"
- "Major mode for editing Haskell scripts." t)
- (autoload 'literate-haskell-mode "haskell-mode"
- "Major mode for editing literate Haskell scripts." t)
- ;; (add-hook 'haskell-mode-hook 'turn-on-haskell-font-lock)
- ;; (add-hook 'haskell-mode-hook 'turn-on-haskell-decl-scan)
- (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
- (add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
- ;; (add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent)
- ;; (add-hook 'haskell-mode-hook 'turn-on-haskell-hugs)
- (add-hook 'haskell-mode-hook 'bind-compile-key)
- (add-hook 'c-mode-hook 'bind-compile-key)
- (add-hook 'c++-mode-hook 'bind-compile-key)
- (add-hook 'sml-mode-hook 'bind-compile-key)
- (add-hook 'lua-mode-hook 'adjust-lua-indent-level)
- (add-hook 'lua-mode-hook '(lambda () (setq lua-electric-flag nil)))
- (add-hook 'lua-mode-hook 'bind-compile-key)
- (add-hook 'lua-mode-hook 'bind-lua-header-key)
- (defun bind-lua-header-key ()
- (local-set-key "\C-c-" 'lua-header-comment))
- (autoload 'lua-mode "lua-mode"
- "Major mode for editing Lua scripts." t)
- (setq auto-mode-alist
- (append auto-mode-alist
- '(("\\.lua$" . lua-mode)
- ("\\.nbs$" . lua-mode)
- ("\\.tracksl$" . lua-mode)
- ("\\.nws$" . lua-mode))))
- (add-to-list 'interpreter-mode-alist '("lua5.1" . lua-mode))
- (add-to-list 'interpreter-mode-alist '("/usr/bin/lua5.1" . lua-mode))
- (add-to-list 'interpreter-mode-alist '("lua40" . lua-mode))
- (add-to-list 'interpreter-mode-alist '("lua50" . lua-mode))
- (add-to-list 'interpreter-mode-alist '("lua" . lua-mode))
- (add-to-list 'interpreter-mode-alist '("lua5.1-courseware" . lua-mode))
- (defun bind-compile-key ()
- (local-set-key "\C-c\C-c" 'compile))
- (global-set-key "\C-c\C-c" 'compile)
- (setq auto-mode-alist
- (cons '("\\.ml[iylpb]?$" . caml-mode) auto-mode-alist))
- (autoload 'caml-mode "caml" "Major mode for editing Caml code." t)
- (autoload 'run-caml "inf-caml" "Run an inferior Caml process." t)
- ;(autoload 'odin "/usr/public/src/cmd/Odin/etc/odin" nil t)
- (setq auto-mode-alist (append (list (cons "\\.tib$" 'tex-mode))
- auto-mode-alist))
- (autoload 'sml-mode "sml-mode" "Major mode for editing ML programs." t)
- (setq auto-mode-alist
- (append '(("\\.sml$" . sml-mode) ("\\.cm$" . sml-mode) ("\\.rtl$" . sml-mode)
- ("\\.lrtl$" . sml-mode)
- ("\\.sled$" . sml-mode) ("\\.sig$" . sml-mode)) auto-mode-alist))
- (setq sml-mode-info "~nr/emacs/sml-mode.info")
- (defun sml-new-prompt () "skip errors and go to prompt" (interactive)
- (sml-skip-errors)
- (sml-next-error)
- )
- (defun set-up-sml-mode () "set preferences for sml" (interactive)
- ; (setq sml-indent-level 2)
- (setq sml-case-indent t)
- (setq indent-tabs-mode nil)
- (local-set-key "\C-ck" 'sml-new-prompt)
- )
- (add-hook 'sml-mode-hook 'set-up-sml-mode)
- (defun set-up-caml-mode () "set preferences for caml" (interactive)
- (setq caml-case-indent t)
- (setq indent-tabs-mode nil)
- (local-set-key "\C-ck" 'caml-new-prompt)
- )
- (add-hook 'caml-mode-hook 'set-up-caml-mode)
- (setq sml-program-name "sml-nw")
- (setq sml-program-name "sml")
- (defun search-list (x l) "look up in a list"
- (cond
- ((null l) nil)
- ((equal (car l) x) t)
- (t (search-list x (cdr l)))))
- (defun search-list (x l)
- "Search for x on l"
- (let ((list l)
- found)
- (while (not (or found (null l)))
- (if (equal x (car list))
- (setq found t)
- (setq list (cdr list))))
- found))
- (defun exists-buffer (n) "search for buffer" (interactive "sName of buffer?")
- (search-list n (buffer-list)))
- ;(autoload 'mud "/u/norman/emacs/mud" nil t)
- (autoload 'mud "/usr/public/lib/emacs/mud" nil t)
- (setq mud-use-entire-window t)
- (setq mud-default-default-server "LambdaMOO")
- ;;; (push auto-mode-alist '( "\\.fw" . funnelweb-mode))
- ;(load-library "assoc")
- (defun keymaps-at-point ()
- "List entire keymaps present at point."
- (interactive)
- (let ((map-list
- (list
- (mapcar (lambda (overlay)
- (overlay-get overlay 'keymap))
- (overlays-at (point)))
- (mapcar (lambda (overlay)
- (overlay-get overlay 'local-map))
- (overlays-at (point)))
- (get-text-property (point) 'keymap)
- (get-text-property (point) 'local-map))))
- (apply #'message
- (concat
- "Overlay keymap: %s\n"
- "Overlay local-map: %s\n"
- "Text-property keymap: %s\n"
- "Text-property local-map: %s")
- map-list)))
- (defun key-binding-at-point (key)
- (mapcar (lambda (keymap) (when (keymapp keymap)
- (lookup-key keymap key)))
- (list
- ;; More likely
- (get-text-property (point) 'keymap)
- (mapcar (lambda (overlay)
- (overlay-get overlay 'keymap))
- (overlays-at (point)))
- ;; Less likely
- (get-text-property (point) 'local-map)
- (mapcar (lambda (overlay)
- (overlay-get overlay 'local-map))
- (overlays-at (point))))))
- (defun locate-key-binding (key)
- "Determine in which keymap KEY is defined."
- (interactive "kPress key: ")
- (let ((ret
- (list
- (key-binding-at-point key)
- (minor-mode-key-binding key)
- (local-key-binding key)
- (global-key-binding key))))
- (when (called-interactively-p 'any)
- (message "At Point: %s\nMinor-mode: %s\nLocal: %s\nGlobal: %s"
- (or (nth 0 ret) "")
- (or (mapconcat (lambda (x) (format "%s: %s" (car x) (cdr x)))
- (nth 1 ret) "\n ")
- "")
- (or (nth 2 ret) "")
- (or (nth 3 ret) "")))
- ret))
- (defun aput (alist-symbol key &optional value)
- "Inserts a key-value pair into an alist.
- The alist is referenced by ALIST-SYMBOL. The key-value pair is made
- from KEY and optionally, VALUE. Returns the altered alist or nil if
- ALIST is nil.
- If the key-value pair referenced by KEY can be found in the alist, and
- VALUE is supplied non-nil, then the value of KEY will be set to VALUE.
- If VALUE is not supplied, or is nil, the key-value pair will not be
- modified, but will be moved to the head of the alist. If the key-value
- pair cannot be found in the alist, it will be inserted into the head
- of the alist (with value nil if VALUE is nil or not supplied)."
- (let ((a (assq key (eval alist-symbol))))
- (if a
- (setcdr a value)
- (set alist-symbol (cons (cons key value) (eval alist-symbol))))))
- (setq auto-mode-case-fold nil)
- (aput 'auto-mode-alist "^[0-9]+\\'" 'text-mode)
- (aput 'auto-mode-alist "/[0-9]+\\'" 'text-mode)
- (aput 'auto-mode-alist "^[-A-Z]+\\'" 'text-mode)
- (aput 'auto-mode-alist "/[-A-Z]+\\'" 'text-mode)
- (aput 'auto-mode-alist "/nr/todo/[-a-z]+$" 'text-mode)
- (aput 'auto-mode-alist "draft$" 'text-mode)
- (aput 'auto-mode-alist "/notes$" 'text-mode)
- (aput 'auto-mode-alist "\\.grades$" 'text-mode)
- (aput 'auto-mode-alist "^notes$" 'text-mode)
- (aput 'auto-mode-alist "\\.page$" 'text-mode)
- (aput 'auto-mode-alist "^template$" 'text-mode)
- (aput 'auto-mode-alist "/template$" 'text-mode)
- (aput 'auto-mode-alist "\\.md$" 'text-mode)
- (aput 'auto-mode-alist "^mail\\.Re" 'text-mode)
- (aput 'auto-mode-alist "/mail\\.Re" 'text-mode)
- (aput 'auto-mode-alist "^cvs[a-zA-Z0-9]+$" 'text-mode)
- (aput 'auto-mode-alist "/cvs[a-zA-Z0-9]+$" 'text-mode)
- (aput 'auto-mode-alist "svn-commit\\.tmp$" 'text-mode)
- (aput 'auto-mode-alist "next-actions" 'text-mode)
- (aput 'auto-mode-alist "grades/emails/[0-9][0-9]" 'text-mode)
- (aput 'auto-mode-alist "\\.ig$" 'modula-3-mode)
- (aput 'auto-mode-alist "\\.mg$" 'modula-3-mode)
- (aput 'auto-mode-alist "\\.i3$" 'modula-3-mode)
- (aput 'auto-mode-alist "\\.m3$" 'modula-3-mode)
- (aput 'auto-mode-alist "\\.latex$" 'tex-mode)
- (aput 'auto-mode-alist "\\.sty$" 'tex-mode)
- (aput 'auto-mode-alist "\\.html$" 'text-mode)
- (assq-delete-all "\\.bib$" auto-mode-alist)
- (assq-delete-all "\\.bib\\'" auto-mode-alist)
- (setq my-awful-emacs-test (assq "\\.bib\\'" auto-mode-alist))
- (autoload 'modula-3-mode "/usr/local/m3/lib/elisp/modula3" nil t)
- (defun m3-mode-hook-function ()
- (setq m3-abbrev-enabled 'polite)
- (setq m3-electric-end 'all) ;; or 'proc-mod if you find this too intrusive
- (setq m3-blink-end-matchers t))
- (add-hook 'm3-mode-hook 'm3-mode-hook-function)
- ; try this only on an older emacs---presumably a newer is built in?
- (if (and (string< "20" emacs-version) (string< emacs-version "22"))
- ; (load "mwheel.el")
- 0)
- (setq-default indent-tabs-mode nil)
- (defun my-tab-key ()
- "Tab that always tabs in Fundamental mode" (interactive)
- (if (string= "Fundamental" mode-name)
- (insert "\t")
- (if (and (boundp 'noweb-mode) noweb-mode
- (not (and (boundp 'mini-noweb-mode) mini-noweb-mode)))
- (save-restriction
- (noweb-update-chunk-vector)
- (noweb-narrow-to-chunk)
- (indent-for-tab-command))
- (indent-for-tab-command))))
- (defun my-newline-and-indent ()
- "Newline and indent that works better with noweb mode"
- (interactive "*")
- (if (and (boundp 'noweb-mode) noweb-mode
- (not (and (boundp 'mini-noweb-mode) mini-noweb-mode)))
- (save-restriction
- (noweb-update-chunk-vector)
- (noweb-narrow-to-chunk)
- (newline-and-indent))
- (newline-and-indent)))
- (defun use-my-indent-keys ()
- "Locally bind tab and ^J to keys that indent better" (interactive)
- (local-set-key "\t" 'my-tab-key)
- (local-set-key "\C-j" 'my-newline-and-indent))
- (global-set-key "\t" 'my-tab-key)
- (add-hook 'noweb-select-code-mode-hook 'use-my-indent-keys)
- ;;;;;;;;;;;;;;;; joys of emacs 19 ;;;;;;;;;;;;;;;;
- (if (string< emacs-version "19")
- 0
- (progn
- (require 'rect)
- (if (fboundp 'apply-on-rectangle)
- (progn
- (defun my-open-rectangle (start end)
- "Blank out rectangle with corners at point and mark, shifting text right.
- The text previously in the region is not overwritten by the blanks,
- but instead winds up to the right of the rectangle.
- And then run untabify for NO tabs"
- (interactive "r")
- (apply-on-rectangle 'open-rectangle-line start end nil)
- (untabify start end)
- (goto-char start))
- (autoload 'operate-on-rectangle "rect.el"))
- (progn
- (defun my-open-rectangle (start end)
- "Blank out rectangle with corners at point and mark, shifting text right.
- The text previously in the region is not overwritten by the blanks,
- but instead winds up to the right of the rectangle.
- And DON'T insert any tabs"
- (interactive "r")
- (operate-on-rectangle 'open-rectangle-line start end nil)
- (untabify start end))))
- (autoload 'operate-on-rectangle "rect.el")
- (global-set-key "\C-xro" 'my-open-rectangle)
- (defun my-delete-rectangle (start end)
- "Delete (don't save) text in rectangle with point and mark as corners.
- The same range of columns is deleted in each line starting with the line
- where the region begins and ending with the line where the region ends."
- (interactive "r")
- (operate-on-rectangle 'delete-rectangle-line start end t)
- (untabify start end))
- (defun indent-paragraph () "Indent current paragraph by paragraph-indent-level"
- (interactive)
- (mark-paragraph)
- (while (eolp) (forward-char 1))
- (forward-char paragraph-indent-level)
- (exchange-point-and-mark)
- (beginning-of-line)
- (my-open-rectangle (mark) (point)))
- (defun my-find-alternate-file (filename)
- "Find file FILENAME, select its buffer, kill previous buffer.
- If the current buffer now contains an empty file that you just visited
- \(presumably by mistake), use this command to visit the file you really want."
- (interactive
- (let ((file buffer-file-name)
- (file-name nil)
- (file-dir nil))
- (and file
- (setq file-name (file-name-nondirectory file)
- file-dir (file-name-directory file)))
- (list (read-file-name
- "Find alternate file: " file-dir))))
- (and (buffer-modified-p)
- ;; (not buffer-read-only)
- (not (yes-or-no-p (format "Buffer %s is modified; kill anyway? "
- (buffer-name))))
- (error "Aborted"))
- (let ((obuf (current-buffer))
- (ofile buffer-file-name)
- (onum buffer-file-number)
- (otrue buffer-file-truename)
- (oname (buffer-name)))
- (rename-buffer " **lose**")
- (setq buffer-file-name nil)
- (setq buffer-file-number nil)
- (setq buffer-file-truename nil)
- (unwind-protect
- (progn
- (unlock-buffer)
- (find-file filename))
- (cond ((eq obuf (current-buffer))
- (setq buffer-file-name ofile)
- (setq buffer-file-number onum)
- (setq buffer-file-truename otrue)
- (lock-buffer)
- (rename-buffer oname))))
- (or (eq (current-buffer) obuf)
- (kill-buffer obuf))))
- (global-unset-key "\C-xm") ;; don't launch mail
- (when (fboundp 'set-auto-mode)
- (defun my-set-auto-mode ()
- "Set the current buffer's mode automatically"
- (interactive)
- (set-auto-mode))
- (global-set-key "\M-m" 'my-set-auto-mode))
- (set-variable 'paragraph-indent-level 2)
- (global-set-key "\M-p" 'indent-paragraph)
- (global-set-key "\C-xrd" 'my-delete-rectangle)
- (global-set-key "\C-x\C-q" 'toggle-read-only)
- (global-set-key "\C-x\e" 'repeat-complex-command)
- (global-set-key "\C-x\C-v" 'my-find-alternate-file)
- (global-set-key "\M-i" 'indented-text-mode)
- (global-unset-key [C-down-mouse-2])
- (global-set-key [C-mouse-2] 'mouse-kill)
- (global-set-key [S-mouse-2] 'mouse-kill-ring-save)
- (global-set-key [end] 'end-of-line)
- (global-set-key [home] 'beginning-of-line)
- (global-set-key [M-end] 'end-of-buffer)
- (global-set-key [M-home] 'beginning-of-buffer)))
- (menu-bar-mode -1)
- (if (fboundp 'scroll-bar-mode)
- (scroll-bar-mode -1))
- (if (fboundp 'tool-bar-mode)
- (tool-bar-mode -1))
- (put 'downcase-region 'disabled nil)
- (defalias 'unblock-comments (read-kbd-macro
- "C-s 4** C-a 2*C-k C-n 2*C-k C-p 3*C-d M-\\ C-e 3*DEL M-\\ C-SPC C-a
- <<capitalize-region>> C-a \\ section{ C-e } RET < *"))
- (auto-compression-mode 't)
- (global-set-key [S-delete] 'keyboard-quit)
- (eval-after-load "compile"
- '(add-hook 'compilation-mode-hook 'recognize-ghc-error-messages))
- (eval-after-load "compile"
- '(add-hook 'compilation-mode-hook 'recognize-lua-stack-traces))
- (eval-after-load "compile"
- '(add-hook 'compilation-mode-hook 'recognize-icon-error-messages))
- (eval-after-load "compile"
- '(add-hook 'compilation-mode-hook 'recognize-all-ml-error-messages))
- (eval-after-load "compile"
- '(add-hook 'compilation-mode-hook 'recognize-lint-error-messages))
- (eval-after-load "compile"
- '(add-hook 'compilation-mode-hook 'recognize-lua-error-messages))
- (eval-after-load "compile"
- '(add-hook 'compilation-mode-hook 'recognize-utlnx-error-messages))
- ;; (eval-after-load "compile"
- ;; '(setq compilation-search-path (cons ".." compilation-search-path)))
- (custom-set-variables
- ;; custom-set-variables was added by Custom.
- ;; If you edit it by hand, you could mess it up, so be careful.
- ;; Your init file should contain only one such instance.
- ;; If there is more than one, they won't work right.
- '(adaptive-fill-regexp "[ ]*\\([-–!|#%;>*·•‣⁃◦]+[ ]*\\)*")
- '(compilation-search-path (quote (nil "..")))
- '(default-input-method "TeX")
- '(desktop-globals-to-save
- (quote
- (desktop-missing-file-warning tags-file-name tags-table-list search-ring regexp-search-ring register-alist file-name-history compile-command)))
- '(desktop-path (quote ("~")))
- '(electric-indent-mode nil)
- '(filladapt-token-table
- (quote
- (("^" beginning-of-line)
- (">+" citation->)
- ("\\(\\w\\|[0-9]\\)[^'`\"<
- ]*>[ ]*" supercite-citation)
- (";+" lisp-comment)
- ("#+" sh-comment)
- ("%+" postscript-comment)
- ("///*" c++-comment)
- ("@c[ ]" texinfo-comment)
- ("@comment[ ]" texinfo-comment)
- ("\\\\item[ ]" bullet)
- ("[0-9]+\\.[ ]" bullet)
- ("[0-9]+\\(\\.[0-9]+\\)+[ ]" bullet)
- ("[A-Za-z]\\.[ ]" bullet)
- ("(?[0-9]+)[ ]" bullet)
- ("(?[@A-Za-z])[ ]" bullet)
- ("[0-9]+[A-Za-z]\\.[ ]" bullet)
- ("(?[0-9]+[A-Za-z])[ ]" bullet)
- ("[-~*+]+[ ]" bullet)
- ("o[ ]" bullet)
- ("[ ]+" space)
- ("$" end-of-line))))
- '(ispell-personal-dictionary "~/.ispell_words")
- '(ispell-program-name "ispell")
- '(paragraph-separate "\\([ ]*\\|~*\\|-*\\|=*\\|[ >]*\\)$")
- '(paragraph-start "\\|[ ]*$\\|~*$")
- '(quack-programs
- (quote
- ("drracket" "bigloo" "csi" "csi -hygienic" "gosh" "gsi" "gsi ~~/syntax-case.scm -" "guile" "kawa" "mit-scheme" "mred -z" "mzscheme" "mzscheme -M errortrace" "mzscheme -il r6rs" "mzscheme -il typed-scheme" "mzscheme3m" "mzschemecgc" "racket" "rs" "scheme" "scheme48" "scsh" "sisc" "stklos" "sxi")))
- '(quack-remap-find-file-bindings-p nil)
- '(safe-local-variable-values
- (quote
- ((c-indent-level . 4)
- (TeX-master . "paper.ltx")
- (mmm-noweb-code-mode . scheme-mode)
- (mmm-noweb-code-mode . c)
- (mmm-noweb-code-mode . c-mode)
- (old-mode . poly-noweb+c)
- (old-mode . Noweb)
- (tab-width . 4)
- (ess-noweb-default-code-mode . scheme-mode)
- (bogus-mode . poly-noweb+fundamental-mode)
- (noweb-code-mode . scheme-mode)
- (ess-noweb-default-code-mode . c-mode)
- (default-ess-noweb-code-mode . sml-mode)
- (noweb-default-code-mode . c-mode)
- (tex-main-file . guide\.tex)
- (TeX-master . "proposal")
- (mini-noweb-code-mode . scheme-mode)
- (mini-noweb-code-mode . sml-mode)
- (noweb-doc-mode . fundamental-mode)
- (noweb-code-mode . tex-mode)
- (noweb-code-mode . icon-mode)
- (noweb-doc-mode . text-mode)
- (noweb-code-mode . caml-mode)
- (noweb-code-mode . c-mode)
- (noweb-code-mode . fundamental-mode)
- (tex-main-file . book\.nw)
- (noweb-code-mode . sml-mode))))
- '(sh-basic-offset 2)
- '(sml-nested-if-indent t)
- '(x-select-enable-clipboard t))
- (custom-set-faces
- ;; custom-set-faces was added by Custom.
- ;; If you edit it by hand, you could mess it up, so be careful.
- ;; Your init file should contain only one such instance.
- ;; If there is more than one, they won't work right.
- '(flyspell-duplicate ((t (:foreground "blue" :underline t :weight bold))))
- '(flyspell-duplicate-face ((t (:foreground "blue" :underline t :weight bold))) t)
- '(mmm-default-submode-face ((t (:background "gray96"))))
- '(mmm-special-submode-face ((t (:background "honeydew2")))))
- (put 'upcase-region 'disabled nil)
- ;;;; (require 'darcsum)
- (when (string-equal (cadr command-line-args) "/home/nr/todo")
- (require 'desktop)
- (if (boundp 'desktop-restore-eager)
- (setq desktop-restore-eager 10))
- (setq desktop-dirname "/home/nr")
- (if (string< emacs-version "22")
- (progn
- (defun save-nr-desktop ()
- (desktop-save "/home/nr"))
- (desktop-load-default)
- (desktop-read "/home/nr")
- (add-hook 'kill-emacs-hook 'save-nr-desktop t)))
- ;; emacs 23 and later
- (setq desktop-save t) ; 'ask-if-new was causing too much hassle
- (setq desktop-base-file-name ".emacs23.desktop")
- (setq desktop-save-mode t)
- (desktop-save-mode 1)
- ; (desktop-read desktop-dirname)
- )
- (defun renumber-list (start end &optional num)
- "Renumber the list items in the current START..END region.
- If optional prefix arg NUM is given, start numbering from that number
- instead of 1."
- (interactive "*r\np")
- (save-excursion
- (goto-char start)
- (setq num (or num 1))
- (save-match-data
- (while (re-search-forward "^\\([ \t]*\\)[0-9]+" end t)
- (replace-match (concat "\\1" (number-to-string num)))
- (setq num (1+ num))))))
- (defun count-words-nr (begin end)
- "Count the number of words in the buffer (or with prefix arg, the region)."
- (interactive (list (point-min) (point-max)))
- (if current-prefix-arg
- (progn
- (setq begin (region-beginning))
- (setq end (region-end))))
- (save-excursion
- (goto-char begin)
- (let ((count 0))
- (while (and (< (point) end) (re-search-forward "\\<" end t))
- (progn
- (incf count)
- (forward-char 1)))
- (message "%s words (%s)" count (if current-prefix-arg "region" "buffer")))))
- (defalias 'wc-w 'count-words-nr)
- (defun current-fill-context-prefix ()
- "Call `fill-context-prefix` on the current paragraph"
- (interactive)
- (message "Fill context prefix is '%s'" (fill-context-prefix
- (save-excursion (backward-paragraph 1) (point))
- (save-excursion (forward-paragraph 1) (point)))))
- (put 'narrow-to-region 'disabled nil)
- (when (fboundp 'electric-indent-mode)
- (electric-indent-mode -1) ; turn it off
- (add-hook 'after-change-major-mode-hook (lambda() (electric-indent-mode -1)))
- ; keep it off
- )
- (defun yank-primary ()
- "Yank primary selection"
- (interactive)
- (let ((primary
- (cond
- ((eq system-type 'windows-nt)
- ;; MS-Windows emulates PRIMARY in x-get-selection, but not
- ;; in x-get-selection-value (the latter only accesses the
- ;; clipboard). So try PRIMARY first, in case they selected
- ;; something with the mouse in the current Emacs session.
- (or (x-get-selection 'PRIMARY)
- (x-get-selection-value)))
- ((fboundp 'x-get-selection-value) ; MS-DOS and X.
- ;; On X, x-get-selection-value supports more formats and
- ;; encodings, so use it in preference to x-get-selection.
- (or (x-get-selection-value)
- (x-get-selection 'PRIMARY)))
- ;; FIXME: What about xterm-mouse-mode etc.?
- (t
- (x-get-selection 'PRIMARY)))))
- (unless primary
- (error "No selection is available"))
- (push-mark (point))
- (insert primary)))
- (defun delete-horizontal-space-forward ()
- "Delete all spaces following point."
- (interactive)
- (let ((orig-pos (point)))
- (delete-region
- orig-pos
- (progn
- (skip-chars-forward " \t")
- (point)))))
- (when (and
- (= (display-pixel-height) 2160)
- (member "Droid Sans Mono" (font-family-list)))
- (set-face-attribute 'default nil :font "Droid Sans Mono" :height 130))
- (global-set-key (kbd "C-x g") 'magit-status)
- (defun insert-fixed-fonts ()
- "Insert sample uses of all fixed-width fonts"
- (interactive)
- (let ((case-fold-search t)
- (str "The quick brown fox jumps over the lazy dog ´`''\"\"1lI|¦!Ø0Oo{[()]}.,:; ")
- (font-families
- (remove-if-not (lambda (s)
- (or (string-match "fixed" s) (string-match "mono" s)))
- (cl-remove-duplicates
- (sort (font-family-list)
- (lambda(x y) (string< (upcase x) (upcase y))))
- :test 'string=))))
- (dolist (ff font-families)
- (insert
- (propertize str 'font-lock-face `(:family ,ff)) ff "\n"
- (propertize str 'font-lock-face `(:family ,ff :slant italic)) ff "\n"))))
- (defvar compilation-error-data nil)
- (defun compilation-error-search ()
- "Search for matching compilation error regexp"
- (interactive)
- (setq compilation-error-data
- (enumerate-first-match 1 compilation-error-regexp-alist)))
- (defun enumerate-first-match (i rules)
- (if (null rules)
- nil
- (let ((item (car rules)))
- (if (symbolp item)
- (setq item (cdr (assq item
- compilation-error-regexp-alist-alist))))
- (let ((file (nth 1 item))
- (line (nth 2 item))
- (col (nth 3 item))
- (type (nth 4 item))
- (pat (car item))
- end-line end-col fmt
- props)
- (cond
- ((not (memq 'omake compilation-error-regexp-alist)) nil)
- ((string-match "\\`\\([^^]\\|\\^\\( \\*\\|\\[\\)\\)" pat)
- nil) ;; Not anchored or anchored but already allows empty spaces.
- (t (setq pat (concat "^ *" (substring pat 1)))))
- (if (consp file) (setq fmt (cdr file) file (car file)))
- (if (consp line) (setq end-line (cdr line) line (car line)))
- (if (consp col) (setq end-col (cdr col) col (car col)))
- (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
- (error "HYPERLINK should be an integer: %s" (nth 5 item)))
- (if (re-search-forward pat (point-max) t)
- (list 'INDEX i 'PAT pat 'MATCHED (match-string 0) 'FULL-ITEM item)
- (enumerate-first-match (+ 1 i) (cdr rules)))))))
- (defun do-nothing (&rest args)
- (interactive)
- nil)
- ; http://endlessparentheses.com/ispell-and-abbrev-the-perfect-auto-correct.html
- (defun endless/ispell-word-then-abbrev (p)
- "Call `ispell-word', then create an abbrev for it.
- With prefix P, create local abbrev. Otherwise it will
- be global."
- (interactive "P")
- (let ((bef (downcase (or (thing-at-point 'word)
- "")))
- aft)
- (call-interactively 'ispell-word)
- (setq aft (downcase
- (or (thing-at-point 'word) "")))
- (unless (or (string= aft bef)
- (string= aft "")
- (string= bef ""))
- (message "\"%s\" now expands to \"%s\" %sally"
- bef aft (if p "loc" "glob"))
- (define-abbrev
- (if p local-abbrev-table global-abbrev-table)
- bef aft))))
- (defun endless/flyspell-word-then-abbrev (p)
- "Call `ispell-word', then create an abbrev for it.
- With prefix P, create local abbrev. Otherwise it will
- be global."
- (interactive "P")
- (save-excursion
- (if (flyspell-goto-previous-word (point))
- (let ((bef (downcase (or (thing-at-point 'word)
- "")))
- aft)
- (call-interactively 'ispell-word)
- (setq aft (downcase
- (or (thing-at-point 'word) "")))
- (unless (or (string= aft bef)
- (string= aft "")
- (string= bef ""))
- (message "\"%s\" now expands to \"%s\" %sally"
- bef aft (if p "loc" "glob"))
- (define-abbrev
- (if p local-abbrev-table global-abbrev-table)
- bef aft)))
- (message "Cannot find a misspelled word"))))
- (define-key ctl-x-map "\C-i"
- #'endless/flyspell-word-then-abbrev)
- (add-to-list 'initial-frame-alist '(sticky . nil))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement