;; * add-to-list-x (defun add-to-list-x (LIST-VAR &rest REST) "See also `add-to-list-l' `add-to-list-p' \(add-to-list-x 'load-path init-dir (expand-file-name \"_misc/\" init-dir) )" (mapc (lambda(ELEMENT) (add-to-list LIST-VAR ELEMENT)) REST)) (defun add-to-list-l (LIST-VAR LIST) "See also `add-to-list-x'" (apply 'add-to-list-x LIST-VAR LIST)) ;; 第二个参数是列表,方便自己对参数进行处理 ;(add-to-list-l 'load-path ;或者;(apply 'add-to-list-x 'load-path ; (mapc fn list) ;) (defun add-to-list-p (LIST-VAR &optional BASE &rest REST) "See also `add-to-list-x'" (mapc (lambda(ELEMENT) (add-to-list LIST-VAR (expand-file-name ELEMENT BASE))) REST)) ;; 这个和上面的那个差不多,是路径专用的,用于一些特殊情况。比如 ;; init-dir 里面有一个 cedet 目录,里面又有 "common" "eieio" "semantic" ;; "srecode" "ede" 等子目录,要把这些目录添加到 load-path,可以这样 ;; (add-to-list-p 'load-path (expand-file-name "cedet/" init-dir) ;; "" ;; 添加 init-dir/cedet/ 目录本身 ;; "common" "eieio" "semantic" "srecode" "ede") ;; 如果用 add-to-list-x 的话,就得这样 ;; (add-to-list-x 'load-path ;; "init-dir/cedet/" ;; "init-dir/cedet/common" ;; "init-dir/cedet/eieio" ;; "init-dir/cedet/semantic" ;; "init-dir/cedet/srecode" ;; "init-dir/cedet/ede" ;; ) ;; * require-x (defun require-x (action lst) "(require-x 'require '(aaa bbb ccc ...))" (mapcar (lambda(ext) (funcall action ext)) lst)) ;; * define-key-s (defun define-key-s (keymap key-defs &optional group) "(define-key-s 0 '(\"key\" def \"key\" def ...)) \(define-key-s 0 '(\"a\" \"b\" \"c\" ...) 'self-insert-command) If keymap is 0, run as global-set-key If keymap is 1, run as local-set-key If keymap is xxx-mode-map, run as define-key xxx-mode-map See also `def-key-s'." (let ((map (cond ((eq keymap 0) (current-global-map)) ((eq keymap 1) (current-local-map)) (t keymap)))) (while (car key-defs) (let* ((key (pop key-defs)) (def (if (eq group nil)(pop key-defs) group))) (define-key map (eval `(kbd ,key)) def) )))) ;(define-key-s 0 '( ;; 0 global-set-key ; 1 local-set-key ; mode map ;;;第一个参数为 1 的时候,可能有问题。懒得管了,不推荐用这个参数,可以指定具体的 mode map ; "C-x C-j" ido-execute-extended-command ; "C-o" set-mark-command ; "C-w" backward-kill-word-or-kill-region ; "C-c C-v" view-mode ; "C-." redo ; "C-;" toggle-comment-region ;)) (defun def-key-s (keymap &rest key-defs) "(def-key-s map \"key\" 'def \"key\" 'def ...) See also `define-key-s'." (define-key-s keymap key-defs) ) ;;;把 define-key-s 包装了一下,参数不需要是列表。 ;;但是 elisp 会先对表达式中的参数部分求值……你懂得 ;;命令前面需要加单引号,一般定义的内容较少的时候用 ;(def-key-s view-mode-map ; "p" 'View-scroll-page-backward ; "n" 'View-scroll-page-forward ; "k" 'View-scroll-line-backward ; "j" 'View-scroll-line-forward ; "f" 'View-search-last-regexp-forward ; "b" 'View-search-last-regexp-backward ; ) ;; * backward-kill-word-or-kill-region ;; 选择区域的时候删除区域,否则回删单词 ;; * backward-kill-word-or-kill-region (defun backward-kill-word-or-kill-region () (interactive) (if mark-active (call-interactively 'kill-region) (call-interactively 'backward-kill-word))) ;; * toggle-comment-region (defun toggle-comment-region (beg end &optional n) "Comment the lines in the region if the first non-blank line is commented, and conversely, uncomment region. If optional prefix arg N is non-nil, then for N positive, add N comment delimiters or for N negative, remove N comment delimiters. Uses `comment-region' which does not place comment delimiters on blank lines." (interactive "r\nP") (if n (comment-region beg end (prefix-numeric-value n)) (save-excursion (goto-char beg) (beginning-of-line) ;; skip blank lines (skip-chars-forward " \t\n") (if (looking-at (concat "[ \t]*\\(" (regexp-quote comment-start) "+\\)")) (uncomment-region beg end) (comment-region beg end)))))