---
(safe-require 'd-time)
(setq large-movement-list '(d-smooth-up
d-smooth-down
d-forward-c-defun
d-backward-c-defun
d-forward-page
d-backward-page
beginning-of-buffer
end-of-buffer
exchange-point-and-mark))
(defun d-deposit-mark-if-small-movement ()
(if (not (memq last-command large-movement-list))
(push-mark (point) 'no-msg)))
(defun d-one-window ()
(interactive)
(save-match-data
(if (eq 1 (count-windows))
(cond
((string= (buffer-name) "*Article*")
(let ((list (mapcar 'buffer-name (buffer-list))))
(while list
(if (string-match "\\*Summary" (car list))
(switch-to-buffer (car list)))
(setq list (cdr list)))))
((string= (buffer-name) "*compilation*")
(bury-buffer))
(t (widen))))
(while (not (d-is-good-buffer (current-buffer)))
(bury-buffer)
(other-window 1))
(delete-other-windows)
(recenter (/ (window-height) 2))
))
(defun d-shift-f2 ()
(interactive)
(cond
((and (buffer-file-name)
(or (string= (buffer-file-name) (expand-file-name "d:/allegro-403/docs/txt/allegro.txt"))
(string-match "/TAGS" (buffer-file-name))))
(bury-buffer))
((and (buffer-file-name)
(not (eq major-mode 'dired-mode)))
(save-buffer)
(kill-buffer nil))
((eq major-mode 'dired-mode)
(kill-buffer nil))
((d-is-good-buffer (current-buffer))
(bury-buffer))
((not (d-is-good-buffer (current-buffer)))
(kill-buffer nil))
)
)
(global-set-key "\C-e" 'call-last-kbd-macro)
(global-set-key "\C-v" 'scroll-up)
(global-set-key "\M-v" 'scroll-down)
(global-unset-key "\M-z")
(global-set-key "\C-x\C-k" 'kill-compilation)
(global-set-key "\C-xk" 'kill-buffer)
(global-set-key "\M-i" 'indent-relative)
(global-set-key "\M-s" 'center-line)
(global-set-key "\C-xy" 'insert-register)
(global-set-key "\C-o" 'split-line)
(global-set-key "\C-xp" 'picture-mode)
(global-set-key "\C-x\C-p" 'picture-mode)
(global-unset-key "\C-p")
(global-unset-key [mouse-2])
(global-set-key "\C-n" 'd-narrow)
(global-set-key [(s ? )] (function (lambda () (interactive) (push-mark))))
(global-set-key [(s ?x)] 'execute-extended-command)
(global-set-key [(control meta backspace)] 'backward-kill-sexp)
(global-set-key [(shift insert)] 'electric-buffer-list)
(global-set-key [(control insert)] 'electric-buffer-list)
(defun switch-to-old-buffer (buffer)
(interactive (list (read-buffer "Switch to old buffer: " (other-buffer) t)))
(switch-to-buffer buffer))
(defun d-is-good-buffer (buf)
(and (not (= (aref (buffer-name buf) 0) ?*))
(not (= (aref (buffer-name buf) 0) ?\ ))
)
)
(defun d-narrow ()
(interactive)
(assert (looking-at "[ \t]*[[({]"))
(assert "})]")
(let (p-low p-high)
(setq p-low (point))
(forward-sexp 1)
(setq p-high (point))
(narrow-to-region p-low p-high)
(goto-char (point-min))))
(define-key isearch-mode-map [backspace] 'isearch-delete-char)
(define-key read-expression-map [?\t] 'd-complete-lisp)
(global-set-key [(shift f2)] 'd-shift-f2)
(global-set-key [(meta f2)] 'd-shift-f2)
(global-set-key [f3] 'd-super-f3)
(defun d-super-f3 ()
(interactive)
(if (buffer-file-name)
(call-interactively 'save-buffer))
(d-save-some-buffers)
(d-f3)
(d-f3)
)
(defun d-f3-a ()
(interactive)
(let ((ptr (buffer-list)))
(while ptr
(when (buffer-live-p (car ptr))
(set-buffer (car ptr))
(if (buffer-file-name)
(if (and (not (string-match "/TAGS" (buffer-file-name)))
(not (string= (buffer-file-name) "/media/www/C80GB/allegro-403/docs/txt/allegro.txt")))
(kill-buffer (car ptr)))))
(setq ptr (cdr ptr))) ))
(defun d-f3-b ()
"kills dired buffers"
(let ((ptr (buffer-list)))
(while ptr
(if (and (buffer-live-p (car ptr))
(save-excursion
(set-buffer (car ptr))
(and (eq major-mode 'dired-mode)
(not (string-match "/bamboo_system_files/" default-directory))
(not (string-match "/Driver Pack Solution/" default-directory))
(not (string-match "/wordpress/" default-directory))
)))
(kill-buffer (car ptr)))
(setq ptr (cdr ptr)))))
(defun d-f3-c ()
"Also kills dired buffers"
(let ((ptr (buffer-list)))
(while ptr (cond
((and (buffer-live-p (car ptr))
(buffer-name (car ptr))
(= (aref (buffer-name (car ptr)) 0) ?*)
(not (d-is-good-buffer (car ptr))))
(kill-buffer (car ptr)))
((and (buffer-live-p (car ptr))
(save-excursion
(set-buffer (car ptr))
(and (not (buffer-file-name))
(buffer-name)
(eq major-mode 'dired-mode)
(not (string-match "/bamboo_system_files/" default-directory))
(not (string-match "/Driver Pack Solution/" default-directory))
(not (string-match "/wordpress/" default-directory))
)))
(kill-buffer (car ptr)))
((and (buffer-live-p (car ptr))
(save-excursion
(set-buffer (car ptr))
(and (not (buffer-file-name))
(buffer-name)
(/= (aref (buffer-name) 0) ?\ )
(/= (aref (buffer-name) 0) ?*)
(not (string= "bamboo_system_files" (buffer-name)))
(not (string= "Driver Pack Solution" (buffer-name)))
(not (string= "wordpress" (buffer-name)))
)))
(kill-buffer (car ptr))))
(setq ptr (cdr ptr)))))
(defun d-f3 ()
(interactive)
(delete-other-windows)
(if (get-buffer "*info*") (kill-buffer "*info*"))
(if (get-buffer "*Buffer List*") (kill-buffer "*Buffer List*"))
(let (d)
(setq d (if (get-buffer "*compilation*") (save-excursion (set-buffer "*compilation*") default-directory)))
(if (eq major-mode 'dired-mode) (setq d default-directory))
(d-f3-a)
(d-f3-b)
(d-f3-c)
(if d
(dired d)
(dired "~/")
)))
(defun d-save-and-bury ()
(interactive)
(if (buffer-file-name)
(save-buffer))
(bury-buffer))
(defun save-and-bury-and-remove-window ()
(interactive)
(if (buffer-file-name)
(save-buffer))
(bury-buffer)
)
(global-set-key [(shift f3)] 'd-save-and-bury)
(global-set-key [(meta f3)] 'd-widen)
(defun d-widen ()
(interactive)
(widen)
(recenter))
(global-set-key [(shift f4)] 'd-save-and-bury)
(global-set-key [(meta f4)] 'd-save-and-bury)
(global-set-key [f4] 'd-f4)
(defun d-f4 ()
(interactive)
(if (get-buffer "*Calendar*")
(kill-buffer "*Calendar*"))
(if (d-currently-editing-file "~/.diary")
(save-excursion
(set-buffer (d-currently-editing-file "~/.diary"))
(save-buffer)
(kill-buffer nil)))
(if (boundp 'd-speedbar)
(d-speedbar))
(cond
( )
)
)
(global-unset-key "\M-^")
(global-set-key "\C-xnd" (function
(lambda () (interactive)
(mark-defun)
(call-interactively 'narrow-to-region))))
(global-set-key "\M-!" (function
(lambda () (interactive)
(call-interactively 'shell-command)
(if (condition-case err
(save-excursion
(set-buffer "*Shell Command Output*")
(d-check-for-sod-off-emacs))
(error ))
(d-one-window))
(redraw-display)))
)
(global-set-key [kp-enter] 'kp-enter)
(global-set-key [f8] 'undo)
(if prefs-advanced-user-p
(progn
(global-set-key [(control f12)] 'd-complete-file)
(global-set-key [(meta f12)] 'd-complete-file)
(global-set-key [(shift f12)] 'd-complete-file)
))
(defun d-occur ()
(interactive)
(let ((case-fold-search nil))
(call-interactively 'occur)))
(defun d-query-replace (from-string to-string &optional arg)
(interactive (query-replace-read-args "Query replace" nil))
(let ((case-fold-search nil))
(query-replace from-string to-string arg)))
(defun d-query-replace-regexp (regexp to-string &optional arg)
(interactive (query-replace-read-args "Query replace regexp" t))
(let ((case-fold-search nil))
(query-replace-regexp regexp to-string arg)))
(global-set-key "\M-*" 'query-replace-regexp)
(global-set-key "\M-%" 'query-replace)
(setq auto-mode-alist
(append '(("\\.txh$" . texinfo-mode))
auto-mode-alist))
(defun d-texinfo-stuff ()
"My own Texinfo mode customizations."
(set (make-local-variable 'dabbrev-case-fold-search) nil)
(set (make-local-variable 'dabbrev-case-replace) nil))
(add-hook 'texinfo-mode-hook 'd-texinfo-stuff)
(add-hook 'texinfo-mode-hook 'turn-on-font-lock)
(add-hook 'change-log-mode-hook 'turn-on-font-lock)
(defun d-info-mode-hook ()
(define-key Info-mode-map [f1] 'Info-exit))
(add-hook 'Info-mode-hook 'd-info-mode-hook)
(defun d-archive-mode-hook ()
(when prefs-davins-keybindings-online-p
(local-set-key "\C-d" 'd-find-file)
(local-set-key "\C-f" 'd-find-file)
(define-key archive-mode-map "\C-d" 'd-find-file)
))
(add-hook 'archive-mode-hook 'd-archive-mode-hook)
(condition-case err
(show-paren-mode t)
(error
(message "Cannot show parens %s" (cdr err))))
(add-to-list 'auto-mode-alist '("\\.\\(arc\\|zip\\|lzh\\|zoo\\)\\'" . archive-mode))
(defun d-archive-hook ()
(when (string-match "\\.zip$" (buffer-name))
(archive-mode 1)
))
(autoload 'archive-mode "arc-mode" "Major mode for editing archives." t)
(defadvice archive-extract (after stub activate)
(read-only-mode 1)
)
(define-key text-mode-map [(shift prior)] 'backward-paragraph)
(define-key text-mode-map [(shift next)] 'forward-paragraph)
(progn
(global-set-key [(control prior)] 'd-backward-page)
(global-set-key [(control next)] 'd-forward-page)
)
(define-key text-mode-map [return] 'd-indent-new-comment-line)
(eval-after-load "doctor" '(define-key doctor-mode-map [return] 'doctor-ret-or-read))
(when prefs-davins-keybindings-online-p
(global-set-key "\C-o" 'd-control-o)
)
(defun d-control-o ()
(interactive)
(let ((x (current-column)))
(call-interactively 'split-line)
(when (= 0 x)
(move-to-column 0))
))
(modify-syntax-entry ?_ "w" text-mode-syntax-table)
(modify-syntax-entry ?- "w" text-mode-syntax-table)
(modify-syntax-entry ?\" "w" text-mode-syntax-table)
(add-hook 'makefile-mode-hook 'turn-on-font-lock)
(defun d-makefile-mode-hook ()
(interactive)
(when prefs-davins-keybindings-online-p
(local-set-key [f12] 'do-shell-line)
(local-set-key [return] 'd-indent-new-comment-line)
(local-set-key [left] 'backward-char)
(local-set-key [right] 'forward-char)
(local-set-key [up] 'previous-line)
(local-set-key [down] 'next-line)
(local-set-key "\t" 'self-insert-command)
(setq tab-width 10)
)
)
(add-hook 'makefile-mode-hook 'd-makefile-mode-hook)
(add-hook 'gud-mode-hook 'd-gud-mode-hook)
(defun d-gud-mode-hook ()
(interactive)
(when prefs-davins-keybindings-online-p
(local-set-key "\C-d" 'd-find-file)
(local-set-key "\C-f" 'd-find-file)
)
(font-lock-mode 1)
)
(defun d-picture-mode--backspace ()
(interactive)
(if (eq 0 (current-column))
(d-beep)
(forward-char -1)
(delete-char 1)
(insert " ")
(forward-char -1)
)
)
(defun d-picture-mode--delete ()
(interactive)
(if (eolp)
(d-beep)
(delete-char 1)
(insert " "))
)
(defun d-picture-mode--right ()
(interactive)
(if (looking-at "$")
(insert " ")
(forward-char 1))
)
(defun d-picture-mode-hook ()
(when prefs-davins-keybindings-online-p
(define-key picture-mode-map [left] 'backward-char)
(define-key picture-mode-map [right] 'd-picture-mode--right)
(define-key picture-mode-map [backspace] 'd-picture-mode--backspace)
(define-key picture-mode-map [delete] 'd-picture-mode--delete)
(define-key picture-mode-map [(shift backspace)] 'd-picture-mode--backspace)
(define-key picture-mode-map [(shift delete)] 'd-picture-mode--delete)
)
)
(add-hook 'picture-mode-hook 'd-picture-mode-hook)
(eval-after-load
"asm-mode"
'(when prefs-davins-keybindings-online-p
(define-key asm-mode-map "\C-m" 'd-indent-new-comment-line)
(define-key asm-mode-map "\C-j" 'd-indent-new-comment-line)
))
(eval-after-load
"hexl"
'(when prefs-davins-keybindings-online-p
(define-key hexl-mode-map "\C-f" 'd-find-file)
(define-key hexl-mode-map "\C-d" 'd-find-file)
(define-key hexl-mode-map "\C-b" 'd-kill-buffer)
)
)
(eval-after-load
"gnus"
'(when prefs-davins-keybindings-online-p
(define-key gnus-summary-mode-map "\C-d" 'd-find-file)
(define-key gnus-summary-mode-map "\C-f" 'd-find-file)
))
(eval-after-load
"tar-mode"
'(when prefs-davins-keybindings-online-p
(define-key tar-mode-map "\C-d" 'd-find-file)
(define-key tar-mode-map "\C-f" 'd-find-file)
))
(defun d-sh-mode-hook ()
(interactive)
(when prefs-davins-keybindings-online-p
(if prefs-advanced-user-p (local-set-key "`" 'dabbrev-expand))
(local-set-key [f12] 'do-shell-line)
)
)
(add-hook 'sh-mode-hook 'd-sh-mode-hook)
(autoload 'd-pretty-printer "p-print"
"pretty prints all files in current dir to file \"printout\""
t)
(defun d-indent-new-comment-line ()
(interactive)
(when prefs-davins-keybindings-online-p
(cond
((eq (current-column) 0)
(insert "\n"))
((or (eq major-mode 'c++-mode) (eq major-mode 'java-mode) (eq major-mode 'jtw-mode))
(cond
((save-excursion
(beginning-of-line)
(looking-at "^[ \t]*///"))
(insert "\n/// ")
(c-indent-command))
((save-excursion
(beginning-of-line)
(looking-at "^[ \t]*//"))
(insert "\n// ")
(c-indent-command))
((save-excursion
(beginning-of-line)
(looking-at "[ \t]*/\\*\\*"))
(insert "\n *")
(c-indent-command))
((save-excursion
(beginning-of-line)
(looking-at "[ \t]*/\\*"))
(insert "\n * ")
(c-indent-command))
((save-excursion
(beginning-of-line)
(looking-at "[ \t]*\\*"))
(insert "\n * ")
(c-indent-command))
(t
(indent-new-comment-line))
)
(execute-kbd-macro "\t")
(skip-chars-forward "*")
(forward-char 1)
)
((and (or (eq major-mode 'makefile-mode) (eq major-mode 'text-mode))
(save-excursion
(beginning-of-line)
(looking-at "^###")))
(insert "\n### "))
((and (eq major-mode 'text-mode)
(save-excursion
(beginning-of-line)
(looking-at "^===")))
(insert "\n=== "))
((and (eq major-mode 'text-mode)
(save-excursion
(beginning-of-line)
(looking-at "^///")))
(insert "\n/// "))
((and (eq major-mode 'emacs-lisp-mode)
(save-excursion
(beginning-of-line)
(looking-at "^[ \t]*;;;")))
(let (p)
(beginning-of-line)
(setq p (point))
(skip-chars-forward " \t")
(delete-region p (point))
(end-of-line)
(insert "\n;;; ")))
((and (eq major-mode 'emacs-lisp-mode)
(save-excursion
(beginning-of-line)
(looking-at "^[ \t]*;;")))
(insert "\n;; ")
(lisp-indent-line))
((and (eq major-mode 'emacs-lisp-mode))
(insert "\n")
(lisp-indent-line))
((and (eq major-mode 'latex-mode)
(save-excursion
(beginning-of-line)
(looking-at "^[ \t]*%%%")))
(insert "\n%%% "))
((eq major-mode 'html-mode)
(insert "\n"))
(t
(indent-new-comment-line)))))
(autoload 'log-mode "log" nil t nil)
(defadvice capitalize-word (around capitalise-bugfix activate)
"Make `capitalise-word' capitalise A_b_c as A_B_C."
(let (p1 p2)
(setq p1 (point))
ad-do-it
(setq p2 (point))
(capitalise-word-bugfix-region p1 p2)
)
)
(defun capitalise-word-bugfix-region (p1 p2)
(goto-char p1)
(while (< (point) p2)
(let ((ch (char-after (point)))
(strobe nil))
(if (= ch ?_)
(progn
(setq strobe t)
(forward-char 1)
(setq ch (char-after (point))))
(setq strobe nil))
(if (and strobe (<= ch ?z) (>= ch ?a))
(progn
(delete-char 1)
(insert-char (- ch 32) 1))
(forward-char 1)))))
(defadvice yank (around d-yank activate)
ad-do-it
(cond
((eq major-mode 'emacs-lisp-mode)
(call-interactively 'indent-region))
((eq major-mode 'text-mode)
t)
(t
))
)
(defadvice yank-pop (around d-yank-pop activate)
ad-do-it
(cond
((eq major-mode 'emacs-lisp-mode)
(call-interactively 'indent-region))
((eq major-mode 'text-mode)
t)
(t
)))
(defadvice indent-for-tab-command (around d-minibuffer-fix activate)
(if (active-minibuffer-window)
(d-complete-file nil)
ad-do-it)
)
(d-quote
(interactive)
(cond
((eq major-mode 'text-mode)
(re-search-forward "[\r\n]" nil t)
(backward-char 1)
(re-search-backward "[^ ]" nil t)
(forward-char 1))
((eq major-mode 'dired-mode)
))
)
(defun d-try-to-find-file (file)
(if (file-exists-p file)
(find-file file)))
(defun allegro-load ()
(interactive)
(progn
(d-try-to-find-file "c:/allegro-403/docs/txt/allegro.txt")
(d-try-to-find-file "/media/www/C1TB/allegro-403/docs/txt/allegro.txt")
(read-only-mode 1))
)
(defun tmm-menubar ()
(interactive))
(when (and prefs-davins-keybindings-online-p
prefs-windows-bindings-p)
(global-set-key (kbd "C-z") 'undo)
)
(defadvice mark-whole-buffer (around d-mark-whole-buffer activate)
ad-do-it
(transient-mark-mode 1))
(global-set-key "\C-a" 'd-select-all)
(defun d-select-all ()
(interactive)
(mark-whole-buffer)
(transient-mark-mode 1)
)
(provide 'd-keys)