;; awc.el ;; ;; Time-stamp: ;; ;; Collection of keybindings and useful emacs tricks ;; ************************ My Favorite Key Bindings ************************ ;; Mouse Buttons (global-set-key [M-S-down-mouse-3] 'imenu) ;; Rectangle Commands (global-set-key [S-kp-divide] 'kill-rectangle) (global-set-key [C-kp-divide] 'delete-rectangle) (global-set-key [S-kp-multiply] 'yank-rectangle) (global-set-key [C-kp-multiply] 'string-rectangle) (global-set-key [S-kp-subtract] 'open-rectangle) (global-set-key [C-kp-subtract] 'clear-rectangle) ;; Function Keys (global-set-key [f3] 'switch-to-buffer) (global-set-key [S-f3] 'list-buffers) (global-set-key [C-f3] 'ediff-buffers) (global-set-key [f4] 'other-window) (global-set-key [S-f4] 'delete-other-windows) (global-set-key [f5] 'find-file) (global-set-key [S-f5] 'revert-buffer) (global-set-key [C-f5] 'insert-file) (global-set-key [f6] 'save-buffer) (global-set-key [S-f6] 'save-some-buffers) (global-set-key [C-f6] 'byte-compile-file) (global-set-key [f7] 'query-replace) (global-set-key [S-f7] 'query-replace-regexp) (global-set-key [C-f7] 'compile) (global-set-key [f8] 'call-last-kbd-macro) (global-set-key [S-f8] 'goto-line) (global-set-key [f9] 'sort-lines) (global-set-key [C-f9] 'indent-region) (global-set-key [f11] 'shell) (global-set-key [f12] 'undo) ;; Enable case changing (put 'downcase-region 'disabled nil) (put 'upcase-region 'disabled nil) (global-set-key "\M-_l" 'downcase-region) (global-set-key "\M-_u" 'upcase-region) ;; ************************ My Favorite Emacs Tricks ************************ ;; Insert a space, moving text over to the right (fset 'insert-space [32 left]) (global-set-key [C-tab] 'insert-space) ;; Scroll by one line in the current window ;;;###autoload (defun scroll-up-one () "Scroll text up one line in the current window" (interactive) (scroll-up 1) ) ;;;###autoload (defun scroll-down-one () "Scroll text down one line in the current window" (interactive) (scroll-down 1) ) (global-set-key [M-up] 'scroll-up-one) (global-set-key [M-down] 'scroll-down-one) ;;; add support for a mouse wheel (global-set-key [mouse-4] 'scroll-up-one) (global-set-key [mouse-5] 'scroll-down-one) ;; Horizontal scrolling in current window ;;;###autoload (defun scroll-left-some () "Scroll left in the current window a little bit" (interactive) (forward-char 4) (scroll-left 4) ) ;;;###autoload (defun scroll-right-some () "Scroll right in the current window a little bit" (interactive) (backward-char 4) (scroll-right 4) ) (global-set-key [M-left] 'scroll-left-some) (global-set-key [M-right] 'scroll-right-some) ;; Duplicate the current line ;;;###autoload (defun dup-line () "Duplicate the current line" (interactive) (beginning-of-line) (let ((beg (point))) (forward-line 1) (kill-ring-save beg (point))) (yank) (forward-line -1) ) (global-set-key "\M-+" 'dup-line) ;;;; Insert the current date as YYYY-MM-DD ;;;;;###autoload ;;(defun insert-date () ;; "Insert current date (YYYY-MM-DD)" ;; (interactive) ;; (insert (time-stamp-yyyy-mm-dd)) ;;) ;;(global-set-key "\M-&" 'insert-date) (defvar insert-time-format "%T" "*Format for \\[insert-time] (c.f. 'format-time-string' for how to format).") (defvar insert-date-format "%Y-%m-%d" "*Format for \\[insert-date] (c.f. 'format-time-string' for how to format).") (defun insert-time () "Insert the current time according to the variable \"insert-time-format\"." (interactive "*") (insert (format-time-string insert-time-format (current-time)))) (defun insert-date () "Insert the current date according to the variable \"insert-date-format\"." (interactive "*") (insert (format-time-string insert-date-format (current-time)))) (defun insert-time-and-date () "Insert the current date according to the variable \"insert-date-format\", then a space, then the current time according to the variable \"insert-time-format\"." (interactive "*") (progn (insert-date) (insert " ") (insert-time))) (global-set-key "\M-_1" 'insert-date) (global-set-key "\M-_2" 'insert-time) (global-set-key "\M-_3" 'insert-time-and-date) ;; Goto the matching parenthesis in the current buffer ;; [stolen from Tim Frenz, LMC M&DS, written 8 Dec 1993] ;;;###autoload (defun goto-match-paren () "Goto the matching parenthesis in the current buffer" (interactive) (let* ((ch (buffer-substring (point) (+ (point) 1)))) (if (or (or (string-equal ch "(") (string-equal ch "[")) (string-equal ch "{")) (progn (forward-sexp) (backward-char 1)) (if (or (or (string-equal ch ")") (string-equal ch "]")) (string-equal ch "}")) (progn (forward-char 1) (backward-sexp 1)) (message (concat "'" ch "' is not a valid paren"))))) ) (global-set-key "\M-[" 'goto-match-paren) ;; Insert an empty function -- {}; ;;;###autoload (defun insert-empty-function () "Insert empty function for C++" (interactive) (insert "{};\n") ) (global-set-key "\M-]" 'insert-empty-function) ;; Insert/Remove a ruler into the current buffer ;; [stolen from Tim Frenz, LMC M&DS, written 8 Dec 1993] ;;;###autoload (defun insert-ruler () "Insert a ruler into the current buffer (on the next line)" (interactive) (let* ((digits "012345678") (num-digits (1- (length digits))) (pos 0)) (save-excursion (forward-line 1) (while (< pos num-digits) (progn (insert (concat (substring digits pos (1+ pos)) "....|....")) (setq pos (1+ pos)) ) ) ; end of while more digits (insert (substring digits pos (1+ pos))) (insert "\n") ) ) ) ;;;###autoload (defun delete-ruler () "Delete a ruler from the current buffer" (interactive) (save-excursion (goto-char (point-min)) (if (re-search-forward "^0....|....1....|...." nil t) (progn (beginning-of-line) (kill-line 1)) (message "No ruler exists in the current buffer") ) ) ) (global-set-key "\M-_i" 'insert-ruler) (global-set-key "\M-_d" 'delete-ruler) ;; Count the number of lines in the current buffer ;; [stolen from Tim Frenz, LMC M&DS, written 8 Dec 1993] ;;;###autoload (defun lines-in-buffer () "Count number of lines in the current buffer" (interactive) (save-excursion (beginning-of-line) (message "\"%s\" has %d lines" (if (buffer-file-name) (buffer-file-name) (buffer-name)) (1+ (count-lines (point-min) (point-max)))) ) ) (global-set-key "\M-#" 'lines-in-buffer) ;;;; List the fonts that Emacs knows about ;;;; -- from Elijah Daniel, Email #9774 in NTEmacs group, 18 Nov 1999 ;;;; www.egroups.com/group/ntemacs-users ;;;; Modified to use temp-buffer ;;;;;###autoload ;;;;(defun display-fonts () ;;;; "Display all the fonts that emacs knows about" ;;;; (interactive) ;;;; (with-output-to-temp-buffer "*FONTS*" ;;;; (save-excursion ;;;; (set-buffer standard-output) ;;;; (setq truncate-lines t) ;;;; (mapcar (lambda (font) (insert font "\n")) (x-list-fonts "*")) ;;;; (goto-char (point-min))) ;;;; (print-help-return-message))) ;;;; ;;;;(define-key-after facemenu-menu ;;;; [display-fonts] '("Display Fonts" . display-fonts) t) ;; ;;;; List the fonts used by the defined faces ;;;; -- based on list-faces-display in faces.el ;;;;;###autoload ;;;;(defun display-face-font () ;;;; "Displays the font associated with each of the defined faces" ;;;; (interactive) ;;;; (let ((faces (sort (face-list) (function string-lessp))) ;;;; (face nil) ;;;; (face-name-max-length ;;;; (car (sort (mapcar (function string-width) ;;;; (mapcar (function symbol-name) (face-list))) ;;;; (function >))))) ;;;; (with-output-to-temp-buffer "*FONT FACES*" ;;;; (save-excursion ;;;; (set-buffer standard-output) ;;;; (setq truncate-lines t) ;;;; (while faces ;;;; (setq face (car faces)) ;;;; (setq faces (cdr faces)) ;;;; (setq font (face-font face)) ;;;; (let ((beg (point))) ;;;; (insert (format ;;;; (format "%%-%ds " ;;;; face-name-max-length) ;;;; (symbol-name face))) ;;;; (put-text-property beg (1- (point)) 'face face)) ;;;; (insert (format "%s" font)) ;;;; (insert "\n")) ;;;; (goto-char (point-min))) ;;;; (print-help-return-message)))) ;;;; ;;;;(define-key-after facemenu-menu ;;;; [display-face-font] '("Display Face Fonts" . display-face-font) t) ;; MACROS (fset 'fixkw [?\C-s ?\C-s home S-down S-down S-down delete down S-down delete]) (global-set-key [M-f8] 'fixkw)