(require 'advice) (require 'filladapt) (require 'hideshow) (require 'term) (require 'comint) (require 'vc) (unless (noninteractive)
(require 'uptimes)) (eval-when-compile
(require 'uptimes)) (eval-when-compile (require 'dired)
(require 'cc-cmds)
(require 'cc-styles)
(require 'jde))
(setq auto-mode-alist (append '(("\\.plt$" . gnuplot-mode)
("\\.m$" . matlab-mode)
("\\.jl$" . sawfish-mode)) auto-mode-alist))
(setq display-time-day-and-date t display-time-form-list '(date time-text load) display-time-interval 30 display-time-24hr-format t display-time-load-list '(0.5 1.2 1.5 1.7 2.3 2.9))
(defvar gawd-uptime-string nil
"The uptime string displayed in the modeline.")
(defun gawd-update-uptime ()
"Update the `gawd-uptime-string' displayed in the modeline."
(interactive)
(setq gawd-uptime-string
(multiple-value-bind (days hours mins secs)
(uptimes-uptime-values)
(format "%id-%0.2i:%0.2i" days hours mins))))
(unless (noninteractive)
(gawd-update-uptime)
(add-hook 'display-time-hook 'gawd-update-uptime)
(define-modeline-control "uptime" (list "---{" 'gawd-uptime-string "}%-")
"Modeline control identifying XEmacs's uptime."
nil "button3 displays all uptime records for this XEmacs.")
(define-key modeline-uptime-map (kbd "<button1>") 'uptimes-this)
(define-key modeline-uptime-map (kbd "<button3>") 'uptimes)
(setq-default modeline-format (append modeline-format
(list (cons modeline-uptime-extent 'modeline-uptime))))
(setq-default modeline-format (list-shuffle-predicated #'(lambda (el seq) (eq (cdr-safe el) 'modeline-uptime))
#'(lambda (el seq)
(nth (- (length seq) 2) seq))
modeline-format))
(setq modeline-format (default-value 'modeline-format)))
(require 'tramp)
(add-hook 'dired-load-hook
(function (lambda ()
"Set up dired variables initially"
(setq dired-ls-F-marks-symlinks (memq system-type '(aix-v3 hpux silicon-graphics-unix usg-unix-v))
dired-copy-preserve-time t
dired-no-confirm '(byte-compile compress ispell load shell uncompress)
dired-omit-files t
dired-compression-method-alist (cons '(bzip2 ".bz2" ("bzip2") ("bzip2" "-d") "-f")
dired-compression-method-alist)))))
(eval-when-compile
(require 'igrep))
(igrep-define zgrep)
(igrep-define bzgrep)
(igrep-find-define zgrep)
(igrep-find-define bzgrep)
(defun gawd-simultaneous-find-file (file-list &optional displayp)
"Visit all files in FILE-LIST.
Arrange them in the frame's buffer list with `record-buffer', as
though switched to via `\\[switch-to-buffer]'.
If DISPLAYP is non-nil, display them simultaneously, like
`dired-simultaneous-find-file'; otherwise, do not affect the
display.
This provides a much-needed feature, the equivalent of `vi *' for
heathens, only more powerful. `dired-simultaneous-find-file'
implements much of this, but not all, as it cannot hide the
buffers it displays and cannot be used to look at more than
a small number of files at once."
(if displayp (dired-simultaneous-find-file file-list)
(mapc (function (lambda (file)
(let ((find-file-run-dired t))
(record-buffer (find-file-noselect file)))))
file-list)))
(defun gawd-dired-do-find-file (&optional arg)
"Visit all marked files at once.
With negative prefix arg, display them simultaneously.
See also functions `dired-do-find-file' and `gawd-simultaneous-find-file'."
(interactive "p")
(gawd-simultaneous-find-file (dired-get-marked-files nil) (< arg 0)))
(add-hook 'dired-setup-keys-hook
#'(lambda ()
"Set up dired keymaps initially"
(define-key dired-mode-map (kbd "C-c F") 'gawd-dired-do-find-file)))
(defun gawd-dired-do-to-file-internal (function &optional args)
"Call some FUNCTION on the marked files, loading them temporarily
if they're not already loaded, and saving them afterwards."
(let* ((file-buffer-exists (get-buffer (dired-get-filename 'no-dir)))
(file-buffer (if file-buffer-exists
file-buffer-exists
(find-file-noselect (dired-get-filename)))))
(save-excursion
(save-window-excursion
(set-buffer file-buffer)
(set-window-buffer (last-nonminibuf-window) file-buffer t)
(save-restriction
(apply function args)
(unless file-buffer-exists
(save-buffer)
(kill-buffer file-buffer)))))))
(defun gawd-dired-ispell-file ()
"Ispell a file."
(gawd-dired-do-to-file-internal 'ispell)
nil)
(defun gawd-dired-ispell-file-comments ()
"Ispell a file's comments."
(gawd-dired-do-to-file-internal 'ispell-comments-and-strings)
nil)
(defun gawd-dired-ispell-marked-files (&optional arg)
"Ispell the marked (or next ARG) files."
(interactive "P")
(dired-map-over-marks-check 'gawd-dired-ispell-file arg 'ispell "spell-check"))
(defun gawd-dired-ispell-marked-file-comments (&optional arg)
"Ispell the marked (or next ARG) files."
(interactive "P")
(dired-map-over-marks-check 'gawd-dired-ispell-file-comments arg 'ispell "spell-check"))
(add-hook 'dired-setup-keys-hook
#'(lambda ()
"Set up dired keymaps initially"
(define-key dired-mode-map (kbd "C-c $") 'gawd-dired-ispell-marked-files)
(define-key dired-mode-map (kbd "C-c ;") 'gawd-dired-ispell-marked-file-comments)))
(mapc #'(lambda (mode)
(put mode 'flyspell-mode-predicate 'flyspell-generic-progmode-verify))
'(c-mode c++-mode java-mode shell-script-mode cperl-mode jde-mode lisp-mode scheme-mode lisp-interaction-mode))
(add-hook 'calendar-load-hook
#'(lambda ()
(setq calendar-week-start-day 1 number-of-diary-entries [2 2 2 2 2 4 1]
mark-diary-entries-in-calendar t
mark-holidays-in-calendar t
european-calendar-style t)))
(setq browse-kill-ring-quit-action 'save-and-restore
browse-kill-ring-display-duplicates nil)
(setq tempbuf-mode-line-string " Temp")
(add-hook 'custom-mode-hook 'turn-on-tempbuf-mode)
(add-hook 'w3-mode-hook 'turn-on-tempbuf-mode)
(add-hook 'Manual-mode-hook 'turn-on-tempbuf-mode)
(add-hook 'browse-kill-ring-hook 'turn-on-tempbuf-mode)
(setq w3m-language "English"
w3m-process-environment nil
w3m-coding-system 'iso-8859-1
w3m-output-coding-system 'iso-8859-1
w3m-file-coding-system 'iso-8859-1
w3m-file-name-coding-system 'iso-8859-1
w3m-bookmark-file-coding-system 'iso-8859-1)
(setq w3m-key-binding 'info w3m-display-inline-image t
w3m-pop-up-windows nil
w3m-search-default-engine "google")
(add-hook 'w3m-load-hook
#'(lambda ()
(add-to-list 'w3m-content-type-alist
'("application/x-dvi" "\\.dvi$" ("xdvi" file)))))
(setq ps-paper-type 'a4)
(defalias 'efs-get-pid 'emacs-pid)
(bbdb-initialize) (setq bbdb-info-file "bbdb.info.gz" bbdb-north-american-phone-numbers-p nil bbdb-notice-auto-save-file t)
(defvar mail-mode-hook nil
"Called when a new mail message is created.
Should be created in sendmail.el, but sendmail.el forgets to do so.")
(setq ispell-dictionary "british"
hyphenation-initial-language "uk")
(setq tshell-input-autoexpand nil)
(defvar gawd-term-output-filter-functions '(comint-truncate-buffer)
"Functions to call immediately after output is inserted into the buffer.
One possible function is `comint-truncate-buffer'.
These functions get one argument, a string containing the text inserted.")
(make-local-hook 'gawd-term-output-filter-functions)
(defadvice term-emulate-terminal (after gawd-term-emulate-terminal)
"Implement output-filter-functions for term-mode.
Called after the string has been displayed.
Only calls its hooks if we have just ended a line; kludgy, maybe,
but CPU-efficient, and good enough for log tailing :)"
(if (= (aref str (- (length str) 1)) ?\n)
(save-excursion (set-buffer (process-buffer proc))
(run-hook-with-args 'gawd-term-output-filter-functions str))))
(defun gawd-snuff-message-function (fmt &rest args)
"Print a one-line message at the bottom of the frame.
The arguments are the same as to `format'.
Unlike `message' this does a regexp match over the
`log-message-ignore-regexps' itself, and displays the message with
the 'no-log label if it matches the regexp.
Bind this locally to `message' when you want to add expensive things
to the `log-message-ignore-regexps' around one or two functions or
subrs you do not want to modify. Do not bind it permanently there,
as it adds an extra regexp scan, and so is actually slower than a
`message' would be."
(if (and (null fmt) (null args))
(progn
(clear-message nil)
nil)
(let ((str (apply 'format fmt args)))
(display-message (if (log-message-filter 'message str)
'message
'no-log) str)
str)))
(defadvice term-previous-matching-input (around gawd-term-previous-matching-input-snuff-logging last)
"Block logging of the `History item:' messages. (They are still displayed.)"
(let ((old-message-function (symbol-function 'message))
(log-message-ignore-regexps (append log-message-ignore-regexps
'("\\`History item: "
"\\`\\(Partially c\\|C\\)omplet\\(ing\\|ed\\)"))))
(unwind-protect (progn (fset 'message (symbol-function 'gawd-snuff-message-function))
ad-do-it)
(fset 'message old-message-function))))
(defadvice term-replace-by-expanded-history-before-point
(around gawd-term-replace-by-expanded-history-before-point-snuff-logging last)
"Block logging of the `History item:' messages. (They are still displayed.)"
(unwind-protect (let ((old-message-function (symbol-function 'message))
(log-message-ignore-regexps (append log-message-ignore-regexps
'("\\`History item: "
"\\`\\(Partially c\\|C\\)omplet\\(ing\\|ed\\)"))))
(unwind-protect (progn (fset 'message (symbol-function 'gawd-snuff-message-function))
ad-do-it)
(fset 'message old-message-function)))))
(defadvice term-replace-by-expanded-history-before-point
(around gawd-term-replace-by-expanded-history-before-point-snuff-logging last)
"Block logging of the `History item:' messages. (They are still displayed.)"
(let ((log-message-ignore-regexps (append log-message-ignore-regexps
'("\\`History item: "
"\\`\\(Partially c\\|C\\)omplet\\(ing\\|ed\\)"))))
ad-do-it))
(setq tshell-mode-map (make-sparse-keymap))
(set-keymap-parents tshell-mode-map term-mode-map)
(define-key tshell-mode-map "\C-c\C-f" 'tshell-forward-command)
(define-key tshell-mode-map "\C-c\C-b" 'tshell-backward-command)
(define-key tshell-mode-map "\t" 'term-dynamic-complete)
(define-key tshell-mode-map "\M-?" 'term-dynamic-list-filename-completions)
(define-key term-mode-map (kbd "M-r") 'term-previous-matching-input-from-input)
(define-key term-mode-map (kbd "M-C-r") 'term-previous-matching-input)
(substitute-key-definition 'previous-line 'term-previous-input tshell-mode-map)
(substitute-key-definition 'next-line 'term-next-input tshell-mode-map)
(define-key tshell-mode-map (kbd "<up>") 'term-previous-input)
(define-key tshell-mode-map (kbd "<down>") 'term-next-input)
(define-key tshell-mode-map (kbd "S-up") 'previous-line)
(define-key tshell-mode-map (kbd "S-down") 'next-line)
(setq term-input-ring-size 256)
(defun gawd-evil-term-process-coding-system-bugfix ()
"Fix a horrible bug in the term `process-coding-system' stuff.
TODO: Remove, when the bug is fixed."
(set-buffer-process-coding-system 'binary 'binary))
(add-hook 'term-exec-hook 'gawd-evil-term-process-coding-system-bugfix)
(setq Manual-program "/usr/bin/man-nocolor")
(defcustom Manual-mode-hook 'gawd-frob-man-keymap
"Function or functions run on entry to Manual-mode."
:type 'hook
:group 'man)
(defun gawd-frob-man-keymap ()
"Frob the `Manual-mode-map' to allow hyperlinking.
A kludge. Attached to the `Manual-mode-hook' before manual mode is
entered for the first time, it removes itself after manipulating the
keymap. It defines the extra keys used by the `Manual-mode-map', and
removes the overriding definitions of these keys as undefined from
the `view-minor-mode-map'. (Why are they there? God alone knows.)"
(define-key Manual-mode-map (kbd "TAB") 'gawd-manual-next-xref)
(define-key Manual-mode-map (kbd "C-RET") 'gawd-manual-follow-xref)
(define-key view-minor-mode-map (kbd "TAB") nil)
(define-key view-minor-mode-map (kbd "C-RET") nil)
(define-key view-minor-mode-map ?l nil)
(remove-hook 'Manual-mode-hook 'gawd-frob-man-keymap))
(defun gawd-manual-next-xref ()
"Jump to the next cross-reference, if any.
The `next' cross-reference is defined as that with the lowest position
greater than `point' and less than `point-max', or, failing that, that
with the lowest point greater than `point-min'."
(interactive)
(let ((next-man-xref (function (lambda (extent nothing) (setq the-posn (or the-posn
(and (eq (car-safe (extent-property extent 'man))
'Manual-follow-xref)
(extent-start-position extent)))))))
(the-posn)) (if (not (eq (point) (point-max)))
(map-extents next-man-xref (current-buffer) (+ 1 (point)) (point-max) nil 'start-and-end-in-region 'man))
(if (null the-posn)
(map-extents next-man-xref (current-buffer) (point-min) (point) nil 'start-in-region 'man))
(if (not (null the-posn))
(goto-char the-posn)))
nil)
(defun gawd-manual-follow-xref (point)
"Follow the cross-reference under POINT.
Nothing happens when not on a cross-reference."
(interactive "d")
(let ((man-extent (extent-at point (current-buffer) 'man)))
(if (and man-extent
(eq (car-safe (extent-property man-extent 'man)) 'Manual-follow-xref))
(eval (extent-property man-extent 'man)))))
(defun window-edges (&optional window)
"Return a list giving the edge coordinates of WINDOW."
(let ((edges (window-pixel-edges window))
tmp)
(setq tmp edges)
(setcar tmp (/ (car tmp) (face-width 'default)))
(setq tmp (cdr tmp))
(setcar tmp (/ (car tmp) (face-height 'default)))
(setq tmp (cdr tmp))
(setcar tmp (/ (car tmp) (face-width 'default)))
(setq tmp (cdr tmp))
(setcar tmp (/ (car tmp) (face-height 'default)))
edges))
(make-obsolete 'window-edges "use `window-pixel-edges' instead.")
(define-key shared-lisp-mode-map "\C-m" 'newline-and-indent)
(setq TeX-macro-global '("/usr/teTeX/sitemf/tex/latex/"))
(add-hook 'LaTeX-mode-hook
#'(lambda ()
(require 'font-latex)))
(defadvice c-backslash-region (after gawd-c-backslash-region-no-spaces activate)
"Do not space out the region, so that text strings as well as macros
may be backslashified."
(if (not delete-flag)
(save-excursion (goto-char from)
(while (re-search-forward "\\s-*\\\\$" nil t)
(replace-match " \\" nil t)))))
(setq vm-mime-charset-font-alist `(("Windows-1252" . ,(face-font-name 'default))))
(defun gawd-setup-c-mode-keymap ()
"Fix up the cc-mode keymap.
Substitute C-specific functions for Lisp-specific functions
still bound to keys in cc-mode, for some reason. (It's probably RMS's
fault. Most things are, except for those that are not.)
Always indent on RET."
(define-key c-mode-base-map "\C-m" 'c-context-line-break)
(substitute-key-definition 'beginning-of-defun 'c-beginning-of-defun c-mode-base-map (current-global-map))
(substitute-key-definition 'end-of-defun 'c-end-of-defun c-mode-base-map (current-global-map)))
(defun gawd-setup-c-mode ()
"Set up C, C++ and Java mode.
This is run in the `c-mode-common-hook' to set up indentation and other
parameters on creation of buffers managed by cc-mode.el."
(gawd-setup-c-mode-keymap)
(setq c-default-style '((c . "gnu") (java-mode . "java") (other . "user"))))
(defvar gawd-personal-code-regexp nil
"A regular expression matching code that is written to your coding standards.
(That is, code that is not written to, say, the GNU standards.)
nil means that the code is written to your standards all the time.")
(defun gawd-personal-code-p (&optional buffer)
"Return t if the BUFFER is possibly visiting personal code."
(or (null gawd-personal-code-regexp)
(null (buffer-file-name buffer))
(string-match gawd-personal-code-regexp (buffer-file-name buffer))))
(defun gawd-clean-up-c-common-hook ()
"Clean up the C mode common hook.
Removes the globally-useful style setup functions from the hook, so
that they only get run once, rather than repeatedly."
(remove-hook 'c-mode-common-hook 'gawd-setup-c-mode-keymap)
(remove-hook 'c-mode-common-hook 'gawd-clean-up-c-common-hook))
(defun gawd-setup-this-c-mode-buffer ()
"Set up this buffer for viewing C code.
This happens even if it is a personal-styled buffer."
(c-setup-filladapt)
(hs-minor-mode 1)
(if (not (gawd-personal-code-p))
(progn
(c-make-styles-buffer-local t) (c-toggle-hungry-state 1)
(setq fill-column 80)
(auto-fill-mode))))
(add-hook 'c-mode-common-hook 'gawd-setup-c-mode-keymap t)
(add-hook 'c-mode-common-hook 'gawd-clean-up-c-common-hook t)
(add-hook 'c-mode-common-hook 'gawd-setup-this-c-mode-buffer t)
(defun gawd-jde-initialize ()
"Initialize the JDE's myriad settings."
(setq jde-compile-option-debug t
jde-compile-option-optimize t
jde-compile-option-depend t
jde-compile-option-target '("1.3")
jde-help-remote-file-exists-function '("url-file-exists")
jde-auto-parse-max-buffer-size 500000
jde-complete-function 'jde-complete-minibuf
jde-import-auto-sort-function 'jde-import-organize
jde-jdk-registry '(("1.4.1" . "/usr/packages.bin/non-free/j2sdk1.4.1"))
jde-jdk '("1.4.1")
jde-quote-classpath nil
jde-checkstyle-option-lcurly-type '("nl")
jde-checkstyle-option-lcurly-method '("nl")
jde-checkstyle-option-lcurly-other '("nl")
jde-checkstyle-option-lcurly-other '("alone")
jde-checkstyle-option-allow-paren-padding t
jde-checkstyle-option-block-try '("stmt")
jde-checkstyle-option-block-catch '("ignore")
jde-checkstyle-option-block-finally '("stmt")
jde-checkstyle-option-allow-noauthor t
jde-checkstyle-option-maxlinelen 132
jde-checkstyle-option-javadoc-check-unused-throws t
jde-gen-k&r nil
jde-gen-method-signature-padding-1 " "
jde-xref-cache-size 10)
(remove-hook 'jde-mode-hook 'gawd-jde-initialize))
(add-hook 'jde-mode-hook 'gawd-jde-initialize)
(add-hook 'emacs-lisp-mode-hook 'checkdoc-minor-mode)
(add-hook 'emacs-lisp-mode-hook 'hs-minor-mode)
(add-hook 'lisp-interaction-mode-hook 'checkdoc-minor-mode)
(add-hook 'lisp-interaction-mode-hook 'hs-minor-mode)
(add-hook 'ielm-mode-hook 'checkdoc-minor-mode)
(add-hook 'ielm-mode-hook 'hs-minor-mode)
(define-key hs-minor-mode-map (kbd "C-c h") 'hs-hide-block)
(define-key hs-minor-mode-map (kbd "C-c s") 'hs-show-block)
(define-key hs-minor-mode-map (kbd "C-c H") 'hs-hide-all)
(define-key hs-minor-mode-map (kbd "C-c S") 'hs-show-all)
(when (not (featurep 'xemacs))
(define-key hs-minor-mode-map (kbd "C-c l") 'hs-hide-level))
(when (not (featurep 'xemacs))
(setq recentf-save-file (locate-user-emacs-file ".recentf"))
(recentf-mode 1))
(when (not (featurep 'xemacs))
(setq filesets-menu-ensure-use-cached t))
(add-hook 'ediff-prepare-buffer-hook 'turn-off-hideshow)
(add-hook 'vc-before-checkin-hook
(lambda ()
(goto-char (point-min))
(hs-show-block)))
(provide 'gawd-mode-frobs)