Skip to content

Instantly share code, notes, and snippets.

@mechanicker
Created December 2, 2010 09:57
Show Gist options
  • Save mechanicker/725056 to your computer and use it in GitHub Desktop.
Save mechanicker/725056 to your computer and use it in GitHub Desktop.
emacs customization helper file
;; -*-mode:Emacs-Lisp;buffer-cleanup-p:t;buffer-read-only:t-*-
;; Time-stamp: <2010-09-14 12:13:40 dky>
;;-----------------------------------------------------------------------------
;; Author : Dhruva Krishnamurthy
;; Date : 7th Dec 2000
;; Note : I thank a lot of other people whose code I have used
;;-----------------------------------------------------------------------------
;; Some variable declarations
(defvar buffer-cleanup-p nil
"Buffer local variable to determine if a cleanup is required before saving")
(make-variable-buffer-local 'buffer-cleanup-p)
(defvar buffer-cleanup-mode-list nil
"List of modes to enable buffer-cleanup")
;;-----------------------------------------------------------------------------
;; Local C/C++ style
;;-----------------------------------------------------------------------------
(defconst dky-style
'((tab-width . 8)
(c-basic-offset . 4) ; Saner indent width
(c-tab-always-indent . t)
(c-comment-only-line-offset . 0)
(c-hanging-braces-alist . ((substatement-open after)
(brace-list-open)))
(c-hanging-colons-alist . ((member-init-intro before)
(inher-intro)
(case-label after)
(label after)
(access-label after)))
(c-cleanup-list . (scope-operator
empty-defun-braces
defun-close-semi))
(c-offsets-alist . ((arglist-close . c-lineup-arglist)
(label . -1000)
(substatement-open . 0)
(case-label . +)
(block-open . 0)
(inline-open . 0)
(inline-close . 0)
(knr-argdecl-intro . -)
(member-init-intro . +)
;; (access-label . -1000)
(statement-block-intro . +)))
(indent-tabs-mode . nil)
(c-echo-syntactic-information-p . nil)
(comment-style . extra-line))
"*User defined C/C++ Programming Style")
(c-add-style "dky" dky-style nil)
;;-----------------------------------------------------------------------------
;; Gets current line
;;-----------------------------------------------------------------------------
(defun get-current-line()
"User method"
(buffer-substring-no-properties (save-excursion (beginning-of-line) (point))
(save-excursion (end-of-line) (point))))
;;-----------------------------------------------------------------------------
;; Is Buffer Empty ?
;;-----------------------------------------------------------------------------
(defun empty-buffer-p()
"User method"
(= (buffer-size) 0))
;;-----------------------------------------------------------------------------
;; Jump to matching paren - downloaded
;;-----------------------------------------------------------------------------
(defun match-paren (arg)
"Go to the matching paren if on a paren; otherwise insert %."
(interactive "p")
(cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1)))))
;;-----------------------------------------------------------------------------
;; strip-ctrl-m
;;-----------------------------------------------------------------------------
(defun strip-ctrl-m()
"User method to remove the ^M in text files"
(interactive)
(catch 'ret
(if (interactive-p)
(barf-if-buffer-read-only))
(if buffer-read-only
(throw 'ret nil)))
(if (not (empty-buffer-p))
(progn
(point-to-register 'p' nil)
(beginning-of-buffer)
(replace-regexp "\r$" "")
(register-to-point 'p' nil))))
;;-----------------------------------------------------------------------------
;; Finding EOL type for [X]Emacs
;;-----------------------------------------------------------------------------
(defun buffer-eol-type()
"User method to return buffers end of line type for both XEmacs and Emacs"
(defvar buffer-eol nil)
(setq buffer-eol (coding-system-eol-type buffer-file-coding-system))
(catch 'eol
(if (not (integerp buffer-eol))
(progn
(if (eq buffer-eol 'lf)
(throw 'eol 0))
(if (eq buffer-eol 'crlf)
(setq buffer-eol 1))
(throw 'eol 1))
(if (eq buffer-eol 'lf)
(throw 'eol 2)))
(throw 'eol buffer-eol)))
;;-----------------------------------------------------------------------------
;; Change coding type to UNIX(LF - line feed)
;;-----------------------------------------------------------------------------
(defun buffer-set-eol-lf(&optional type)
"User method to change the coding type to Unix to expose ^M/defined type"
(catch 'ret
(if buffer-read-only
(throw 'ret nil))
(if (not type)
(setq type 'undecided-unix))
(if (or (and (or (equal type 'undecided-unix)
(equal type 'unix))
(= (buffer-eol-type) 0))
(and (or (equal type 'undecided-dos)
(equal type 'dos))
(not (= (buffer-eol-type) 0))))
(throw 'ret nil))
(set-buffer-file-coding-system type)
(throw 'ret t)))
;;-----------------------------------------------------------------------------
;; Perform user defined cleanup and save buffer
;;-----------------------------------------------------------------------------
(defun buffer-cleanup(&optional force)
"User method to perform some clean up before saving buffer"
(interactive)
;; Strip CTRL-M on save
(if (or force
(interactive-p)
(and (boundp 'buffer-cleanup-p)
buffer-cleanup-p
(member major-mode buffer-cleanup-mode-list)))
(progn
(if (functionp 'blank-cleanup)
(blank-cleanup)
(if (functionp 'whitespace-cleanup)
(whitespace-cleanup)))
(let ((file (buffer-file-name)))
(if (and file (functionp 'vc-registered) (not (vc-registered file)))
(buffer-set-eol-lf 'undecided-unix)))
(strip-ctrl-m))))
;;-----------------------------------------------------------------------------
;; Intelligent HOME to toggle between 1st text and ZERO column
;;-----------------------------------------------------------------------------
(defun intelli-home()
"User method to toggle between 1st text and ZERO column"
(interactive)
(catch 'ret
(let ((pos (point)) (blpos (line-beginning-position)) (btpos 0))
;; If at begin of line
(if (= blpos pos)
(progn
(beginning-of-line-text)
(throw 'ret t)))
(beginning-of-line-text)
(setq btpos (point))
;; If at begin of text
(if (= btpos pos)
(progn
(beginning-of-line)
(throw 'ret t)))
;; Cursor after first text
(if (> pos btpos)
(throw 'ret t))
;; Cursor in between begin of line and first text
;; Closer to first text
(if (> (- pos blpos) (- btpos pos))
(throw 'ret t))
;; Closer to begin line
(if (or (< (- pos blpos) (- btpos pos))
(= (- pos blpos) (- btpos pos)))
(progn
(beginning-of-line)
(throw 'ret t))))))
;;-----------------------------------------------------------------------------
;; Move to end of line text (as beginning-of-line-text)
;;-----------------------------------------------------------------------------
(defun end-of-line-text()
"User method to simulate beginning-of-line-text for end of line"
(interactive)
(end-of-line)
(while (looking-at "[ \t\n]+")
(backward-char 1)))
;;-----------------------------------------------------------------------------
;; Intelligent END to toggle between Last text and Last column
;;-----------------------------------------------------------------------------
(defun intelli-end()
"User method to toggle between Last text and Last column"
(interactive)
(catch 'ret
(let ((pos (point)) (elpos (line-end-position)) (etpos 0))
;; If at begin of line
(if (= elpos pos)
(progn
(end-of-line-text)
(throw 'ret t)))
(end-of-line)
(setq etpos (point))
;; If at begin of text
(if (= etpos pos)
(progn
(end-of-line)
(throw 'ret t)))
;; Cursor after first text
(if (< pos etpos)
(throw 'ret t))
;; Cursor in between begin of line and first text
;; Closer to first text
(if (< (- pos elpos) (- etpos pos))
(throw 'ret t))
;; Closer to begin line
(if (or (> (- pos elpos) (- etpos pos))
(= (- pos elpos) (- etpos pos)))
(progn
(end-of-line)
(throw 'ret t))))))
;;-----------------------------------------------------------------------------
;; Speedbar hack to execute command on file like in dired
;;-----------------------------------------------------------------------------
(defun speedbar-exec-cmd()
"User method to enable dired like command execution in Speedbar"
(interactive)
(let ((cmd nil)
(obj nil)
(path (speedbar-line-path))
(file (speedbar-line-file)))
(setq obj (substring file (length path)))
(setq cmd (read-from-minibuffer (concat "! on " obj ": ")))
(if cmd
(progn
(call-process cmd nil " *Speedbar* " t file)
(set-buffer (get-buffer " *Speedbar* "))
(speedbar-message (buffer-string))
(kill-buffer " *Speedbar* ")))))
;;-----------------------------------------------------------------------------
;; To chop a string OFF a given length from RIGHT. Usefull and fast when you
;; know the chop length
;;-----------------------------------------------------------------------------
(defun chop(arg len)
"User method"
(if (> (length arg) len)
(setq arg (substring arg 0 (- (length arg) len)))))
;;-----------------------------------------------------------------------------
;; To split a string to right and left of a seperator from RIGHT. Return value
;; is Left string, lstr and rstr with have split str
;;-----------------------------------------------------------------------------
(defun strtok(str sep)
"User method"
(defvar num 0)
(defvar rstr nil)
(defvar lstr nil)
(setq sep (string-to-char sep))
(setq num (1- (length str)))
(if (arrayp [str])
(while (progn
(setq num (1- num))
(not (or (char-equal (aref str num) sep)
(equal num 0))))))
(setq rstr (substring str (- (1+ num) (length str)) nil))
(setq lstr (substring str 0 num)))
;;-----------------------------------------------------------------------------
;; To Toggle between HEADER and SOURCE file using TAGS
;;-----------------------------------------------------------------------------
(defun jump-to-header()
"User method to jump to header"
(if (or (equal major-mode 'c-mode)
(equal major-mode 'c++-mode))
(progn
(let ((tagname nil))
(setq tagname (file-name-sans-extension (buffer-name)))
(if (equal (file-name-extension (buffer-name)) "h")
(pop-tag-mark))
(if (not (string= tagname nil))
(find-tag tagname))))))
;;-----------------------------------------------------------------------------
;; Open existing or new file
;;-----------------------------------------------------------------------------
(defun open-file(filename)
"User method"
(interactive "FOpen File: ")
(message "%s" filename))
;;-----------------------------------------------------------------------------
;; enable-flyspell
;;-----------------------------------------------------------------------------
(defun enable-flyspell()
"User method"
(symbolp flyspell-mode)
(if (not flyspell-mode)
(flyspell-mode)))
;;-----------------------------------------------------------------------------
;; Find string in list
;;-----------------------------------------------------------------------------
(defun find-in-list(inlist word)
"User method Function to search for a word in a list and return t is found"
(catch 'ret
(if (not (and inlist
word
(listp inlist)
(stringp word)))
(throw 'ret nil))
(let ((lst inlist))
(while lst
(if (string= word (car lst))
(throw 'ret t))
(setq lst (cdr lst))))
(throw 'ret nil)))
;;-----------------------------------------------------------------------------
;; List folders for load path
;;-----------------------------------------------------------------------------
(defun get-dir-list(&optional topdir)
"User method to get the list of directories alone,\
do not forget the final \'\/\' in the argument."
(if (not topdir)
(setq topdir default-directory))
(let ((dir-list (list topdir)))
(if (file-directory-p topdir)
(progn
(setq dir-ls (cdr (directory-files topdir)))
(while (setq dd (car (setq dir-ls (cdr dir-ls))))
(if (file-directory-p (setq dd (concat topdir dd)))
(nconc dir-list (list dd))))))
(cdr dir-list)))
;;-----------------------------------------------------------------------------
;; CNext/V5 Development Specific Code
;;-----------------------------------------------------------------------------
(defun get-add-line-number()
(interactive)
(let ((lnum (concat "#" (substring (what-line) 5) ":\n")))
(next-multiframe-window)
(end-of-buffer)
(insert-string lnum)
(goto-char (1- (point-max)))))
;;-----------------------------------------------------------------------------
;; Add CNext Code Review Tag at specified point or cursor location
;;-----------------------------------------------------------------------------
(defun insert-review-tag(BUF POS TAG &optional PRE POST)
"User method to insert the code review tag in CNext source files"
(catch 'ret
(if (or
(not BUF) (not POS) (not TAG)
(not (bufferp BUF)) (not (integerp POS)) (not (stringp TAG)))
(throw 'ret nil))
(set-buffer BUF)
(goto-char POS)
(let ((dt nil) (mm nil) (dd nil) (yy nil))
(setq dt (calendar-current-date))
(setq mm (int-to-string (car dt)))
(setq dd (int-to-string (car (cdr dt))))
(setq yy (substring (int-to-string (car (cdr (cdr dt)))) 2 4))
(if (= 1 (length dd))
(setq dd (concat "0" dd)))
(if (= 1 (length mm))
(setq mm (concat "0" mm)))
(if PRE
(insert-string PRE))
(insert-string (concat " * @" TAG " dky ") yy ":" mm ":" dd)
(if POST
(insert-string POST))
(throw 'ret (point)))))
;;-----------------------------------------------------------------------------
;; Find review tag insertion position
;;-----------------------------------------------------------------------------
(defun find-review-tag(BUF)
(catch 'ret
(if (not (and BUF (bufferp BUF)))
(throw 'ret nil))
(point-to-register 'p' nil)
(set-buffer BUF)
(let ((pos nil))
(beginning-of-buffer)
(setq pos (re-search-forward "[ \t]*\*[ \t]*\@fullreview" nil t))
(if pos
(progn
(goto-char pos)
(beginning-of-line)
(setq pos (+ (point) (length (get-current-line))))
(register-to-point 'p' nil)))
(throw 'ret pos))))
;;-----------------------------------------------------------------------------
;; Find review tag insertion position
;;-----------------------------------------------------------------------------
(defun add-review-tag(&optional BUF)
(interactive)
(if (not BUF)
(setq BUF (current-buffer)))
(catch 'ret
(let ((pos 0))
(setq pos (find-review-tag BUF))
(if (not pos)
(setq pos 1))
(if (> pos 1)
(throw 'ret (insert-review-tag BUF pos "quickreview" "\n")))
(setq pos (insert-review-tag BUF pos "fullreview" "/**\n" "\n */\n"))
(throw 'ret pos))))
;;--------------- Provide the Library for Loading -----------------------------
(provide 'dky)
;;--------------- Provide the Library for Loading -----------------------------
;; -*-mode:Emacs-Lisp;buffer-cleanup-p:t;buffer-read-only:t-*-
;; Time-stamp: <2010-11-25 19:21:34 dky>
;;-----------------------------------------------------------------------------
;; Author : Dhruva Krishnamurthy
;; File : DOT Emacs file
;; This needs lot of Elise source files not found in release
;; Note : Do not byte-compile the .emacs file. If you do, the saving
;; of customisation thru Emacs will get saved in .emacs.elc
;; and you would not want that!!
;; Status :
;; o Also works with both Emacs and XEmacs
;; o Modified GNUS "from" address in NNTP to dummy
;;-----------------------------------------------------------------------------
;; Now that the splash screen does not time out, disable it!
(setq inhibit-splash-screen t)
(if (functionp 'set-scroll-bar-mode)
(set-scroll-bar-mode 'right))
;; M$ specific hacks to resize windows through Elisp
;; (w32-send-sys-command 61728) ; Restore frame
;; (w32-send-sys-command 61488) ; Maximize frame
;; (w32-send-sys-command 61760) ; Start screen saver
;; Some missing things across emacs versions
(if (symbolp 'defvaralias)
(fset 'defvaralias 'defalias))
;; Setup home if we run as different user
(defconst home (expand-file-name (concat "~" init-file-user)))
;;---------------------------- Personal details -------------------------------
(defvar *user-first-name "Dhruva"
"User defined variable for storing user\'s first name")
(defvar *user-last-name "Krishnamurthy"
"User defined variable for storing user\'s last name")
(defvar *user-backup-dir (concat home "/.backup")
"User defined variable for storing backup files")
;; Provide default or will be calculated
(defvar *user-short-name nil
"User defined variable for storing user\'s short name")
(defvar *user-full-name (if (and *user-first-name
*user-last-name)
(concat *user-first-name " " *user-last-name)
nil)
"User defined variable for storing user\'s full name")
;; Ensure either full name or first & last name is set
(if (not (or *user-first-name
*user-last-name
*user-full-name))
(error "Please set either user first & second name or full name"))
;; Compute first & last name if full name is given
(if *user-full-name
(progn
(setq *user-first-name (car (split-string *user-full-name " "))
*user-last-name (cadr (split-string *user-full-name " ")))))
;; Compute short name
(if (and (not *user-short-name)
*user-first-name
*user-last-name)
(setq *user-short-name (downcase
(concat
(string (aref *user-first-name 0))
(string (aref *user-last-name 0))
(string (aref *user-last-name
(- (length *user-last-name) 1))))))
(setq *user-short-name (substring (user-real-login-name) 0 3)))
;; Set mail credentials
(setq user-mail-address (downcase (concat *user-first-name
"@netapp.com"))
imap-default-user (downcase user-mail-address))
;; Do it here as backup,semantic & TRAMP uses this
(if (not (and (boundp '*user-backup-dir)
*user-backup-dir))
(setq *user-backup-dir home)) ; Default backup dir is HOME
(if (not (file-directory-p *user-backup-dir))
(make-directory (expand-file-name *user-backup-dir) t))
;;---------------------------- Personal details -------------------------------
;; Some frame customizations
(setq-default frame-title-format (list "%F" (format "-%d.%d: "
emacs-major-version
emacs-minor-version) "%b")
icon-title-format (list "%b"))
;; This has changed in new XEmacs
(if (featurep 'xemacs)
(defvaralias 'default-frame-plist 'default-frame-alist))
;; (add-to-list 'default-frame-alist '(height . 40))
(add-to-list 'default-frame-alist '(width . 80))
;; (add-to-list 'default-frame-alist '(vertical-scroll-bars . right))
;; Set the root folder to aid using of relative paths
(defconst *rootdir (expand-file-name
(concat invocation-directory "../../"))
"GNU Emacs ROOT directory")
;; For debugging/Pre-testing
(setq max-lisp-eval-depth 1000
w32-get-true-file-attributes nil ; to speed up on windows
overflow-newline-into-fringe nil ; Long Line display related
default-truncate-lines nil)
;; Cursor related
(and (functionp 'blink-cursor-mode)
(blink-cursor-mode 0)
(setq-default cursor-in-non-selected-windows nil))
;; For printer settings - Currently disabled
(if (and 'nil (eq 'windows-nt system-type) (require 'printing nil t))
(progn
(setq pr-txt-name "print")
(setq printer-name nil)
(pr-update-menus t)))
;; Do it at top for accessing various utils
(defconst *custom-lisp-root (concat home "/.site-lisp/"))
(if (file-directory-p *custom-lisp-root)
(add-to-list 'load-path *custom-lisp-root))
(if (not (require 'dky nil t))
(error "Unable to load dky.el package, please fix this!"))
(if (file-directory-p (concat *rootdir "site-lisp"))
(add-to-list 'load-path
(car (get-dir-list (concat *rootdir "site-lisp/")))))
(if (featurep 'xemacs)
(if (file-directory-p (concat *custom-lisp-root "/xemacs"))
(add-to-list 'load-path (concat *custom-lisp-root "/xemacs"))))
;; Add the extra load paths for other custom lisp packages
(let ((cust (get-dir-list *custom-lisp-root)))
(if (listp cust)
(progn
(add-to-list 'load-path (car cust)))))
;; INFO path
(if (not (boundp 'Info-additional-directory-list))
(setq Info-additional-directory-list ()))
(if (file-directory-p "/usr/share/info")
(add-to-list 'Info-additional-directory-list
"/usr/share/info"))
(let ((dir (concat *rootdir "info")))
(if (file-directory-p dir)
(if (featurep 'xemacs)
(add-to-list 'Info-directory-list dir t)
(add-to-list 'Info-additional-directory-list dir t))))
;; MANPATH for wo-man
(let ((dir (concat *rootdir "man")))
(if (file-directory-p dir)
(setenv "MANPATH" dir)))
;; Load the multi-gud first (Nick Roberts)
(condition-case nil
(load-library "multi-gud")
(error nil))
;; TODO: XEmacs crashes, debug it
(and
(not (featurep 'xemacs))
(require 'multi-term nil t)
(multi-term-keystroke-setup))
;; DFM specific make command
;; (setq compile-command "make_dfm -l ")
;; The modeline color sucks on terminal mode
(set-face-foreground 'modeline "ivory3")
(set-face-background 'modeline "black")
;; Do any frame setting at the beginning but after color-theme to be able to
;; override it. Fonts are set only for window mode (not for tty)
(if (eq 'windows-nt system-type)
(defconst *def-font
"-*-Lucida Sans Typewriter-normal-*-*-mono-15-*-*-*-c-*-*-*")
(progn
;; (defconst *def-font "Bitstream Vera Sans Mono-12")
))
(if (boundp '*def-font)
(add-to-list 'default-frame-alist `(font . ,*def-font)))
;; Backup files
(setq backup-inhibited t
backup-by-copying t
version-control t
delete-old-versions t)
(if (boundp 'backup-inhibited)
(make-variable-buffer-local 'backup-inhibited))
(add-to-list 'backup-directory-alist `("." . ,*user-backup-dir))
;; Time stamp format
(setq time-stamp-format
(concat "%04y-%02m-%02d %02H:%02M:%02S " *user-short-name))
;; TRAMP, accessing remote files/folders
(if (and (require 'tramp nil t) (require 'tramp-sh nil t))
(progn
(setq tramp-auto-save-directory *user-backup-dir)
(if (eq 'windows-nt system-type)
(progn
(setenv "PROMPT" "$P> ") ; Tramp likes it simple
(setq tramp-default-method "plink"))
(progn
(setenv "PS1" "$ ")
(setq tramp-default-method "sftp")))
(add-to-list 'tramp-remote-path "/usr/software/rats/bin")))
;; For cscope and other stuff
;; (add-to-list 'exec-path "/opt/extras/bin")
;; Add extra flders to PATH
(add-to-list 'exec-path
(concat *rootdir "msysgit/bin")
(concat *rootdir "msysgit/mingw/bin"))
;; For w3
(add-to-list 'load-path (concat home "/.site-lisp/w3/lisp"))
(require 'w3-auto nil t)
;; pymacs
(require 'pymacs nil t)
;; Hope to keep ssh connection from timing out by displaying a clock
;; (run-with-idle-timer 300 t
;; (lambda ()
;; (while (sit-for 1)
;; (message (format-time-string "%d %b %Y %I:%M:%S %p"
;; (current-time))))))
;; For ASPELL
(let ((dir (concat *rootdir "Aspell")))
(if (file-directory-p dir)
(progn
(setq-default aspell-root dir
ispell-program-name "aspell"
ispell-extra-args '("--reverse"))
(add-to-list 'exec-path (concat aspell-root "/bin"))
(setenv "ASPELL_CONF" (concat "prefix " aspell-root)))))
;; Execute a shell command using buffer-name is buffer is a file
(defun shell-command-buffer (&optional pre)
(interactive "P")
(if (or pre (not (buffer-file-name)))
(shell-command (read-string "shell command: "))
(progn
(shell-command
(format "%s %s" (read-string
(format "shell command on %s: " (buffer-name)))
(buffer-name)))
;; Handle changing file permissions by shell commands
(if (= 6 (/ (string-to-number
(format "%o" (file-modes (buffer-file-name)))) 100))
(toggle-read-only 0)
(toggle-read-only 1)))))
(global-set-key [(meta ?!)] 'shell-command-buffer)
;; Get first non local IP address
(if (not (functionp 'network-interface-list))
(defun network-interface-list ()
nil))
(defun get-non-local-ip-address ()
(catch 'address
(let ((itfs (network-interface-list)))
(while itfs
(let ((itf (car itfs)))
(setq itfs (cdr itfs))
(if (not (string= "lo" (car itf)))
(throw 'address (format-network-address (cdr itf) t)))))
(throw 'address "localhost"))))
;; If GNU Emacs
(if (not (featurep 'xemacs))
(progn
;; Fringe settings
(if (functionp 'fringe-mode)
(fringe-mode '(0 . right-only)))
(set-face-background 'fringe "dim grey")
(setq speedbar-show-unknown-files t) ; Speedbar customisations
;; Re-order to get mercurial first: Only if available
(if (require 'vc-hg nil t)
(setq vc-handled-backends (cons 'Hg (delq 'Hg vc-handled-backends))))
;; Fast access to files with UNC path
;; (setq vc-ignore-dir-regexp "\\`\\([\\/][\\/]\\|/net/\\|/afs/\\)\\'")
(if (eq 'windows-nt system-type)
(setq vc-ignore-dir-regexp "\\`\\([\\/][\\/]\\|/net/\\|/afs/\\)"))
(and (require 'which-func nil t)
(which-func-mode 1)
(setq which-func-cleanup-function
(lambda(arg)
(car (reverse (split-string (car arg) "::"))))))
(if (fboundp (function tool-bar-mode))
(tool-bar-mode 0))
(if (fboundp (function tooltip-mode))
(tooltip-mode 0))
(if (fboundp (function scroll-bar-mode))
(scroll-bar-mode 0))
(if (fboundp (function menu-bar-mode))
(menu-bar-mode 0))
(auto-image-file-mode t)
(setq font-running-xemacs nil)
;; Elisp replacement for GNUserv - dk
;; (and (fboundp 'make-network-process)
;; (require 'emacsserver nil t)
;; (emacsserver-start))
;; For Emacs 23: Have this working on w32!
(require 'server nil t)
(defun stub-server-ensure-safe-dir (dir)
(if (not (file-directory-p dir))
(make-directory (expand-file-name dir) t)) t)
(fset 'server-ensure-safe-dir 'stub-server-ensure-safe-dir)
(and (fboundp 'make-network-process)
(setq server-window (get-buffer-window (current-buffer)))
(defadvice kill-this-buffer
(before kill-this-buffer-server first activate)
(if server-buffer-clients
(server-buffer-done (current-buffer) t)))
(not (server-running-p server-name))
(if (not (eq 'windows-nt system-type))
(setq server-use-tcp t
server-host (get-non-local-ip-address))
t)
(server-start))
;; Recently opened files
(recentf-mode t)
(setq recentf-max-saved-items 10)
;; Exclude some files in recentf history (speedup on start)
(add-to-list 'recentf-exclude "^\/\/\\w+") ; for UNC paths
(add-to-list 'recentf-exclude "/\\w+:?\\w+_?\\w+@\\w+") ; for Tramp
(global-set-key [(control o)] 'recentf-open-files)
;; Buffer surfing
(if (condition-case nil
(load-library "icicles")
(error nil))
(progn
(setq icicle-show-Completions-help-flag t)
(icy-mode t))
(if (require 'ido nil t)
(ido-mode 'buffer)))
;; Fall back on UNIX style if not specified at buffer-local level
(setq default-buffer-file-coding-system 'undecided-unix)
;; ebrowse - C++ code browser by Gerd
;; FOR /F %a IN ('find dir -type f -name "*.cpp" -o
;; -name "*.h" -o
;; -name "*.cc"') DO @ebrowse -a %a
(and (require 'ebrowse nil t)
(setq ebrowse--attributes-flag t
ebrowse--inline-display-flag t
ebrowse--virtual-display-flag t))
;; User defined key bindings
(global-set-key [(control tab)] 'bs-cycle-next)
(global-set-key [(control shift tab)] 'bs-cycle-previous)
(global-set-key [(meta ?g)] 'goto-line)))
;; If XEmacs
(if (featurep 'xemacs)
(progn
;; Some extra customizations
(set-face-foreground 'modeline "black")
(set-face-background 'modeline "ivory4")
;; The buffer name in the modeline
(set-face-foreground 'modeline-buffer-id "yellow")
(set-face-background 'modeline-buffer-id "black")
;; for vc-registered function
(require 'vc nil t)
;; Some FSF Emacs behaviour I am used to
(require 'cc-cmds nil t)
;; To enable region deletion
(delete-selection-mode t)
(if (fboundp (function replace-in-string))
(fset 'replace-regexp-in-string 'replace-in-string))
(recent-files-initialize) ; Recent files
(add-to-list 'recent-files-dont-include "^#")
(setq comment-add 1 ; Add 2 chars to comment
mswindows-start-process-share-console t ; Hide console
gutter-buffers-tab-enabled nil
gutter-buffers-tab-visible-p nil
load-home-init-file t)
;; Due to a bug in XEmacs-21.5.18
;; (set-default-buffer-file-coding-system 'undecided-unix)
;; (set-default-file-coding-system 'undecided-unix)
(fset 'next-buffer 'switch-to-next-buffer)
(fset 'prev-buffer 'switch-to-previous-buffer)
;; User defined key bindings
(global-set-key [(control o)] 'recent-files-visit-file)
(global-set-key [(control tab)] 'next-buffer)
(global-set-key [(control shift tab)] 'prev-buffer)
(global-set-key [backspace] 'c-hungry-backspace)))
;; PC like editing mode - common to both x[e]macs
(if (fboundp (function pc-selection-mode))
(pc-selection-mode)
(and (require 'CUA-mode nil t)
(CUA-mode t)))
;; Eshell prompt customization
(setq eshell-prompt-function (lambda()
(concat (eshell/pwd) "\n" "$ ")))
;; bs customisation
(and (require 'bs nil t)
(add-to-list 'bs-configurations
(list "bs-dky" nil nil nil
'bs-visits-non-file 'bs--sort-by-mode))
(setq bs-default-configuration "bs-dky"))
;; For tagging the VI style
(setq-default make-tags-files-invisible t
tags-file-name (concat home "/TAGS"))
;; XREF
;; (if (file-directory-p (concat *rootdir "xref"))
;; (progn
;; (setq load-path (cons (concat *rootdir "xref/emacs") load-path)
;; exec-path (cons (concat *rootdir "xref") exec-path))
;; (load "xrefactory")))
;; DOS batch file mode
(require 'dosbat nil t)
;; Mail customisations
(if (fboundp (quote mail-abbrevs-setup))
(add-hook (quote mail-setup-hook) (quote mail-abbrevs-setup)))
(require 'feedmail nil t)
(setq mail-default-reply-to user-mail-address
mail-from-style 'angles
mail-signature nil
message-signature nil
mail-server "btcmvexc1-prd.hq.netapp.com"
dabbrev-case-fold-search t ; mail-id completion
feedmail-buffer-eating-function (quote feedmail-buffer-to-smtpmail)
feedmail-enable-queue t
feedmail-confirm-outgoing nil
feedmail-ask-before-queue t
;; send-mail-function 'smtpmail-send-it)
message-send-mail-function (quote feedmail-send-it)
send-mail-function (quote feedmail-send-it))
(defvaralias 'smtpmail-default-smtp-server 'mail-server)
;; Supercite
(autoload 'sc-cite-original "supercite" "Supercite 3.1" t)
(autoload 'sc-submit-bug-report "supercite" "Supercite 3.1" t)
(defun sc-tweak-attribution()
"User method to tweak the attribution in the hook"
(if (> (length attribution) 2)
(setq citation (concat (substring attribution 0 2) "> "))
(if (= (length attribution) 1)
(if (> (length (sc-mail-field "sc-firstname")) 1)
(setq citation
(concat
(substring
(sc-mail-field "sc-firstname") 0 2) "> "))))))
(setq sc-downcase-p t
sc-confirm-always-p nil
sc-electric-references-p nil
sc-preferred-header-style 1
sc-citation-leader ""
sc-preferred-attribution-list
'("X-Attribution" "initials" "sc-lastchoice" "firstname" "lastname"))
;; Mew specific
;; Stubbed using nil
(if (and nil (require 'mew nil t) (require 'mew-config nil t))
(progn
(autoload 'mew-send "mew" nil t)
(if (require 'mew-w3m nil t)
(setq mew-mime-multipart-alternative-list
'("Text/Html" "Text/Plain" ".*")))
(setq mew-demo-picture nil
mew-mail-path (concat home "/Mail/mew")
mew-refile-log-file (concat home "/Mail/mew/refilelog")
mew-addrbook-file (concat home "/Mail/mew/Addrbook")
mew-signature-file (concat home "/.signature")
mew-signature-as-lastpart nil ; Adding it in draft mode
;; User details
mew-mail-domain "netapp.com"
mew-mail-domain-list (list mew-mail-domain)
mew-user "dhruva"
;; Never worked for me!
mew-addrbook-for-cite-label 'nickname
mew-addrbook-for-cite-prefix 'nickname
mew-cite-prefix-function 'mew-cite-prefix-username
mew-cite-hook 'sc-cite-original
;; SMTP configuration
mew-smtp-auth-list '("LOGIN" "PLAIN" "CRAM-MD5")
;; IMAP configuration
mew-proto "%"
mew-cc ""
mew-fcc "%Sent Items"
mew-imap-trash-folder "%Deleted Items"
mew-imap-auth-list '("LOGIN" "CRAM-MD5")
mew-imap-delete nil
mew-imap-size 10240 ; 10k size limit
mew-imap-header-only nil ; Get header only it 't
mew-auto-get t
mew-use-cached-passwd t
mew-passwd-lifetime 12
mew-passwd-timer-unit 60
mew-use-biff t
mew-use-biff-bell t
mew-complete-folder-ignore-case t ; Case insensitive folders
mew-icon-directory (concat *rootdir "site-lisp/mew/etc")
mew-from (concat *user-full-name " <" user-mail-address ">")
;; Insert extra mail headers
mew-header-alist (list
`("X-Attribution:" . ,*user-short-name)))
;; (defvaralias 'mew-pop-user 'user-mail-address)
(setq mew-smtp-user (downcase *user-first-name))
(setq mew-imap-user mew-smtp-user)
;; (defvaralias 'mew-pop-server 'mail-server)
(setq mew-smtp-server mail-server
mew-imap-server mail-server
mew-nntp-server "news.gmane.org")
;; Make it return t always
(or (autoload 'mew-user-agent-compose "mew" nil t) t)
(if (boundp 'mail-user-agent)
(setq mail-user-agent 'mew-user-agent))
(if (fboundp 'define-mail-user-agent)
(define-mail-user-agent
'mew-user-agent
'mew-user-agent-compose
'mew-draft-send-message
'mew-draft-kill
'mew-send-hook))
;; Mew filters/rules for filling mails
(setq mew-refile-guess-alist
'(
("Content-class:"
("appointment" . "%Calendar")
("calendarmessage" . "%Calendar")
)
("From:"
;; VMS lab level
("xxyyxx@zz.com" . "%Official/VMS")
("xxyyzz@zz.com" . "%Official/VMS")
;; Tech stuff
("buzz@zz.com" . "%Official/Tech")
)
))
(add-hook 'mew-draft-mode-newdraft-hook
(lambda()
"Cursor will be somewhere at the EOF"
(end-of-buffer)
(insert "\n\n--\n") ; Prepare for inserting signature
(mew-draft-insert-signature)
(search-backward-regexp "^[ \t]*[Tt]o[ \t]*:")
(auto-fill-mode t)
(end-of-line-nomark)))
(add-to-list 'exec-path (concat *rootdir "cygwin/bin/"))
(add-to-list 'exec-path (concat *rootdir "site-lisp/mew/"))
(add-to-list 'exec-path (concat *rootdir "site-lisp/mew/bin"))
(if (file-directory-p (concat *rootdir "site-lisp/mew/info"))
(add-to-list 'Info-additional-directory-list
(concat *rootdir "site-lisp/mew/info") t))))
;; GNUS for reading NEWS groups and MAIL
(if (and (require 'message nil t) (require 'gnus nil t))
(progn
(setq gnus-default-nntp-server "news.gmane.org"
;; Use this password to cancel my posts
canlock-password "dk"
canlock-password-for-verify canlock-password
smtpmail-smtp-server mail-server
smtpmail-auth-credentials
(list `(,smtpmail-smtp-server 25 ,*user-first-name nil))
;; Settings for Office IMAP mail
gnus-select-method `(nnimap "Office"
(nnimap-address ,mail-server)
(nnimap-stream network)
(nnimap-authenticator login)
(nnimap-expunge-on-close always)))
;; Settings for NNTP (news)
(add-to-list 'gnus-secondary-select-methods
`(nntp
,gnus-default-nntp-server
(nntp-authinfo-user ,user-mail-address)))
;; Use Feedmail
(defvaralias 'message-send-mail-function 'send-mail-function)
(if (not (featurep 'mailalias))
(require 'mailalias nil t))
;; Fetch only part of the article if we can. I saw this in someone
;; else's .gnus
(setq gnus-read-active-file 'some)
;; Tree view for groups. I like the organisational feel this has.
(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
;; Use GNUS for mailing
(if (boundp 'mail-user-agent)
(setq mail-user-agent 'gnus-user-agent))
;; Add an extra header
;; (nconc message-required-headers
;; `((X-Attribution . ,*user-short-name)))
;; Some customizations...
(setq gnus-posting-styles
'((".*"
(signature-file (concat home "/.signature")))))
;; refresh mails at defined intervals
(setq gnus-use-demon t)
(add-hook 'gnus-startup-hook
(lambda ()
(gnus-demon-add-handler
(lambda ()
(gnus-group-get-new-news)) 10 0)))
;; Set rules & filters
(setq nnimap-split-rule
'(("Official.VMS" "^From:.*uday")
("Official.VMS.CIFS" "^From:.*shashank")))
;; Threads! I hate reading un-threaded email -- especially mailing
;; lists. This helps a ton!
(setq gnus-summary-thread-gathering-function
'gnus-gather-threads-by-subject
gnus-check-new-newsgroups 'ask-server
gnus-save-killed-list nil
nnimap-nov-file-name "imap"
;; configure nnfolder to save sent messages and drafts
;; in this case it uses folders named ``sent.YEAR'' which
;; are created and rotated automatically
gnus-gcc-mark-as-read t
nnfolder-active-file (expand-file-name
(concat home "/News/archive/active"))
nnnfolder-directory (expand-file-name
(concat home "/News/archive/"))
gnus-message-archive-method '(nnfolder "archive"
(nnfolder-inhibit-expiry t))
;; gnus-message-archive-group (concat "sent."
;; (format-time-string "%Y"))
;; To save the sent mails on server
gnus-message-archive-group "nnimap+Office:Sent Items"
nndraft-directory (expand-file-name
(concat home "/News/drafts"))
;; Things that use w3m
mm-text-html-renderer 'w3m-standalone
mm-inline-text-html-renderer 'w3m-standalone
gnus-article-wash-function 'w3m-standalone
;; Also, I prefer to see only the top level message.
;; If a message has several replies or is part of a thread,
;; only show the first message. 'gnus-thread-ignore-subject' will
;; ignore the subject and look at 'In-Reply-To:' and
;; 'References:' headers.
gnus-thread-hide-subtree t
gnus-thread-ignore-subject t)))
;; CC mode related
(setq comment-style 'extra-line
backward-delete-char-untabify-method 'hungry)
;; Set ediff options
(if (eq 'windows-nt system-type)
(setq ediff-diff-options "-w -b -B --strip-trailing-cr")
(setq ediff-diff-options "-w -b -B"))
(and (require 'autorevert nil t)
(global-auto-revert-mode 1)
(setq revert-without-query (list "*.[chly]" "*.cc" "*.cpp" "*.fl"
"*.mk" "*.el" "*.k?sh" "*.cls"
"*.pl" "*.py" "*.frm")))
(and (functionp (function global-font-lock-mode))
(global-font-lock-mode t)
(or (setq font-lock-maximum-decoration nil) t))
(if (functionp 'jit-lock-mode)
(jit-lock-mode t))
;; For word completion
(and (file-exists-p (concat home "/.abbrevs"))
(setq abbrev-mode t
abbrev-file-name (concat home "/.abbrevs"))
(read-abbrev-file abbrev-file-name t))
;; For auto line wrapping - Does not work
(setq fill-column 79
adaptive-fill-mode t
default-fill-column fill-column)
;; For Command Prompt
(if (eq 'windows-nt system-type)
(progn
(setq explicit-shell-file-name "cmdproxy"
shell-file-name "cmdproxy"
shell-command-switch "-c"
w32-quote-process-args t)))
;; Calendar/Diary specific settings - Cygwin XEmacs does not work
(setq diary-file (concat home "/diary"))
(and (file-exists-p diary-file)
(setq mark-diary-entries-in-calendar t
calendar-today-marker 'calendar-today-face)
(display-time)
(diary 0))
;; Enable tags
(defun enable-xref ()
(or (and (featurep 'xcscope) (cscope:hook))
(and (boundp 'gtags-mode) (not (gtags-mode 1)))))
;; Misc stuff, some convinient addons
;; On windows
;; $ for /r %a in (*.cpp,*.cxx,*.cc,*.c++*.h,*.hpp,*.hxx) do @echo %a >> files
;; $ gtags -f files DBPATH
(if (condition-case nil ; GLOBAL tag system
(load-library "gtags") ; Does not provide!
(error nil))
(progn
(setenv "GTAGSLIBPATH" (expand-file-name
(concat home "/.tags")))
(setq gtags-select-mode-hook
(lambda ()
(setq hl-line-face 'underline)
(hl-line-mode 1)))
;; barfs at times: path too long...
;; (define-key gtags-mode-map "\C-]" 'gtags-find-tag-from-here)
(define-key gtags-mode-map "\C-]"
(lambda()
(interactive)
(let ((tagname (gtags-current-token)))
(if (not tagname)
nil
(gtags-push-context)
(gtags-goto-tag tagname "")))))
(define-key gtags-mode-map "\C-t" 'gtags-pop-stack)
;; (define-key gtags-mode-map "\el" 'gtags-find-file)
;; (define-key gtags-mode-map "\es" 'gtags-find-symbol)
(define-key gtags-mode-map "\er" 'gtags-find-rtag)
;; (define-key gtags-mode-map "\et" 'gtags-find-tag)
;; (define-key gtags-mode-map "\ev" 'gtags-visit-rootdir)
))
;; Get cscope working in emacs
(if (require 'xcscope nil t)
(progn
(setq cscope-use-relative-paths t)
(setq cscope-do-not-update-database t)
(define-key cscope:map [(control \])]
'cscope-find-global-definition-no-prompting)
(define-key cscope:map [(meta r)]
'cscope-find-functions-calling-this-function)
(define-key cscope:map [(control t)] 'cscope-pop-mark)
(define-key cscope:map [(meta ?.)] 'cscope-find-global-definition)
;; Zap the cscope window on quit
(defadvice cscope-bury-buffer
(after delete-cscope-buffer first activate)
(delete-windows-on "*cscope*"))
)
)
(binary-overwrite-mode -1) ; Prevent overwriting binary files
(fset 'yes-or-no-p 'y-or-n-p) ; Treat 'y' or <CR> as yes, 'n' as no.
(setq require-final-newline t ; Required for most files
auto-save-default nil ; Prevent auto saving clutter
auto-save-list-file-prefix nil)
;; Add twitter mode
(if (not (featurep 'xemacs))
(progn
(if (not (boundp 'image-load-path))
(setq image-load-path nil))
(if (require 'twit nil t)
(global-set-key [(control ?c) ?t] 'twit-post))))
;; Start erc (IRC) through ssh tunnel - firewall
(defun plink-sentinel (p s)
(if (string= "interrupt" s)
(if (erc-server-buffer-p)
(kill-buffer (erc-server-buffer)))))
(defun irc-at-work ()
"IRC through SSH tunnel to bypass firewall at work"
(interactive)
(let ((proc (get-process "plink")))
(if (not proc)
(progn
(setq proc (start-process "plink" "*plink*" "plink.exe"
"-ssh" "-L" "6667:irc.freenode.net:6667"
"-nc" "irc.freenode.net:6667"
"dky@fencepost.gnu.org"))
(set-process-sentinel proc 'plink-sentinel)))
(run-erc "localhost")))
(defun run-erc (&optional server)
"With user defaults"
(interactive)
(let ((host "irc.freenode.net"))
(if (not (interactive-p))
(setq host server))
(erc :server host :full-name "Dhruva Krishnamurthy"
:nick "hackwork"
:password (read-passwd "IRC password: "))))
;; (add-hook 'erc-mode-hook 'ispell-minor-mode)
;; Add default mode to file types
(add-to-list 'auto-mode-alist '("\\.thpl$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.p[lm]$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.log$" . text-mode))
(add-to-list 'auto-mode-alist '("\\.mak$" . makefile-mode))
(add-to-list 'auto-mode-alist '("\\.[xcC]$" . c-mode))
(add-to-list 'auto-mode-alist '("\\.[hH]$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.hxx$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.hpp$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.ipp$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.\\(?:bat\\|com\\)$" . bat-mode))
(and (require 'desktop nil t) ;; Needed for 22.1, might be a bug!
(require 'info nil t)
(add-to-list 'auto-mode-alist
'("\\.info" . Info-on-current-buffer)))
(and (require 'python-mode nil t)
(setq python-indent 4)
(add-to-list 'auto-mode-alist '("\\.pyc?" . python-mode)))
(and (require 'visual-basic-mode nil t)
(add-to-list 'auto-mode-alist '("\\.cls" . visual-basic-mode))
(add-to-list 'auto-mode-alist '("\\.frm" . visual-basic-mode)))
(and (not (featurep 'xemacs))
(require 'cmake-mode nil t)
(setq auto-mode-alist
(append
'(("CMakeLists\\.txt\\'" . cmake-mode))
'(("\\.cmake\\'" . cmake-mode))
auto-mode-alist)))
;; Cleanup during buffer save: User customization
(add-to-list 'buffer-cleanup-mode-list 'html-mode)
(add-to-list 'buffer-cleanup-mode-list 'sgml-mode)
(add-to-list 'buffer-cleanup-mode-list 'perl-mode)
(add-to-list 'buffer-cleanup-mode-list 'cperl-mode)
(add-to-list 'buffer-cleanup-mode-list 'emacs-lisp-mode)
;; For org mode
(if (require 'org nil t)
(progn
(if (boundp 'org-remember-insinuate)
(org-remember-insinuate))
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(global-set-key "\C-cr" 'org-remember)
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)))
;; DocView
(if (require 'doc-view nil t)
(setq doc-view-continuous t))
;; Cleanup before saving in specific modes
(defadvice save-buffer (before clean-save-buffer first activate)
"Preprocess the file before saving... Time stamp, cleanup, backup etc"
(if c-buffer-is-cc-mode
(add-to-list 'buffer-cleanup-mode-list c-buffer-is-cc-mode))
(if (buffer-modified-p)
(progn
(setq backup-inhibited nil)
(backup-buffer)
(time-stamp)
(buffer-cleanup))))
(ad-deactivate 'save-buffer)
;; Insert a TAB and perform indentation (to correct TAB insertion at
;; beginning of line)
;; (defadvice c-indent-line-or-region (before insert-tab-indent first activate)
;; (if (> (current-column)
;; (save-excursion
;; (beginning-of-line-text)
;; (current-column)))
;; (insert "\t")))
;; For modeline control
(setq line-number-mode t
minor-mode-alist nil ; Disable minor modes in modeline
column-number-mode t
modeline-scrolling-method t
column-number-start-at-one t
modeline-click-swaps-buffers t)
;; Hook functions
(add-hook 'find-file-hook (lambda()
(if (functionp 'vc-registered)
(if (vc-registered buffer-file-name)
(setq buffer-read-only t)))))
(add-hook 'mail-citation-hook 'sc-cite-original)
(add-hook 'mh-yank-hooks 'sc-cite-original)
(add-hook 'sc-attribs-postselect-hook 'sc-tweak-attribution)
(add-hook 'emacs-lisp-mode-hook (lambda() (setq indent-tabs-mode nil)))
(add-hook 'c-mode-hook (lambda()
(c-set-style "dky")))
(add-hook 'c++-mode-hook (lambda()
(c-set-style "dky")))
(add-hook 'message-mode-hook (lambda()
(setq use-hard-newlines t)
(turn-on-auto-fill)))
(add-hook 'isearch-mode-hook (lambda()
(modify-syntax-entry ?_ "w"))) ; '_' as word
(add-hook 'text-mode-hook (lambda()
(setq use-hard-newlines t)
(turn-on-auto-fill)
(setq case-fold-search t)))
(add-hook 'emacs-lisp-mode-hook (lambda()
(modify-syntax-entry ?- "w") ; '-' as word
(outline-minor-mode t)
(setq case-fold-search t)
(turn-on-font-lock)))
(add-hook 'c-mode-common-hook (lambda()
(enable-xref)
(setq case-fold-search t
;; To identify user comments
;; comment-start (concat
;; comment-start
;; *user-short-name
;; ": ")
minor-mode-alist nil)
(if (featurep 'which-func)
(which-func-mode 1))
(outline-minor-mode t)
(turn-on-font-lock)))
(add-hook 'visual-basic-mode-hook (lambda()
(setq case-fold-search t)
(turn-on-font-lock)))
(add-hook 'perl-mode-hook 'enable-xref)
(add-hook 'cperl-mode-hook 'enable-xref)
(add-hook 'diary-hook 'appt-make-list)
(add-hook 'speedbar-mode-hook
(lambda()
(define-key speedbar-key-map [?!] 'speedbar-exec-cmd)))
(if (featurep 'recentf)
(add-hook 'kill-emacs-hook 'recentf-cleanup))
;; Global key bindings/re-bindings
(global-set-key [f2] (lambda ()
(interactive)
(ad-activate 'save-buffer)
(save-buffer)
(ad-deactivate 'save-buffer)))
(if (require 'linemark nil t)
(progn
(define-key global-map [(shift f2)] 'viss-bookmark-toggle)
(define-key global-map [(control f2)] 'viss-bookmark-next-buffer)))
(global-set-key [f3] (lambda ()
(interactive)
(ad-activate 'save-buffer)
(call-interactively 'write-file)
(ad-deactivate 'save-buffer)))
(global-set-key [f4] 'next-multiframe-window)
(global-set-key [f5] (lambda ()
(interactive)
(if (or (eq major-mode 'c-mode)
(eq major-mode 'c++-mode))
(call-interactively 'compile)
(message "Cannot compile in %s" major-mode))))
(global-set-key [f6] 'speedbar)
(global-set-key [f9] 'kill-this-buffer)
(if (not window-system)
(global-set-key [f10] 'tmm-menubar))
(global-set-key [end] 'intelli-end)
(global-set-key [select] 'intelli-end) ; Needed for tty mode
(global-set-key [home] 'intelli-home)
(global-set-key [(control ?.)] 'repeat-complex-command)
(if (not (featurep 'xemacs))
(if (eq 'windows-nt system-type)
(global-set-key [f11] (lambda ()
(interactive)
(if (and (boundp '*frame-max) *frame-max)
(progn
(setq *frame-max nil)
(w32-send-sys-command 61728))
(progn
(setq *frame-max t)
(w32-send-sys-command 61488)))))
(defun toggle-fullscreen (&optional f)
(interactive)
(set-frame-parameter f 'fullscreen
(if (frame-parameter f 'fullscreen)
nil 'fullboth)))
(global-set-key [f11] 'toggle-fullscreen)))
(global-set-key [?%] 'match-paren)
(global-set-key [(control ?q)] 'comment-region)
(global-set-key [(meta ?n)] 'menu-bar-next-tag)
(global-set-key [(control ?x) (control ?o)] 'ffap)
(global-set-key [(control ?x) ?r?p] 'register-to-point)
(global-set-key [(control meta \\)] (lambda ()
(interactive)
(cond ((indent-region (point-min)
(point-max)
nil)
(buffer-cleanup)))))
;;-----------------------------------------------------------------------------
(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.
'(icicle-reminder-prompt-flag 6)
'(load-home-init-file t t)
'(proced-command-alist (quote (("user" ("ps" "-fu" "123" "-W") 2)
("all" ("ps" "-ef") 2))))
'(safe-local-variable-values (quote ((buffer-cleanup-p . t)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment