1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 | ;;; -*-emacs-lisp-*- ;;; $Id: dot-emacs.el,v 1.00 2008-05-15 ;;; ;;; (setq load-path (cons (expand-file-name "~/.emacs.d/") load-path)) (defmacro setq-if-equal (symbol old-value new-value &optional nowarn) "setq-if-equal set SYMBOL to NEW-VALUE iff it has OLD-VALUE. It compare the old value with OLD-VALUE using `equal' then set it to NEW-VALUE if the old value matched. If NOWARN is nil, and the old value is not matched with the supplied one, a warning message is generated." `(progn (if (equal ,symbol ,old-value) (setq ,symbol ,new-value) (if (not ,nowarn) (progn (message "%s has unexpected value `%S'" (symbol-name ',symbol) ,symbol) ,old-value))))) (defun move-key (keymap old-key new-key) "Move the key definition from OLD-KEY to NEW-KEY in KEYMAP." (let ((def (lookup-key keymap old-key)) (alt (lookup-key keymap new-key))) (define-key keymap new-key def) (define-key keymap old-key nil) alt)) ;;; Set up the keyboard so the delete key on both the regular keyboard ;;; and the keypad delete the character under the cursor and to the right ;;; under X, instead of the default, backspace behavior. ;; (global-set-key [delete] 'delete-char) ;; (global-set-key [kp-delete] 'delete-char) ;;; This sets up the coding mode for linux kernel sources. ;;; (originally obtained from Documentation/CodingStyle in Linux kernel tree) (defun linux-c-mode () "C mode with adjusted defaults for use with the Linux kernel." (interactive) (c-mode) (if (>= emacs-version 22) (c-set-style "linux") ; After version ??, we have "linux" mode! (progn (c-set-style "K&R") (setq c-basic-offset 8)))) (add-to-list 'auto-mode-alist '("/linux.*/.*\\.[ch]$" . linux-c-mode)) (setq-default make-backup-files nil) ;;; Buffer Menu ;;; Sort by the 2nd column (buffer name) in Buffer list (setq Buffer-menu-sort-column 2) ;;; for wheel mouse ;;; ;;; http://www.inria.fr/koala/colas/mouse-wheel-scroll/#gnuemacs ;;; ;;(defun up-slightly () (interactive) (scroll-up 5)) ;;(defun down-slightly () (interactive) (scroll-down 5)) ;;(global-set-key [mouse-4] 'down-slightly) ;;(global-set-key [mouse-5] 'up-slightly) ;;(defun up-one () (interactive) (scroll-up 1)) ;;(defun down-one () (interactive) (scroll-down 1)) ;;(global-set-key [S-mouse-4] 'down-one) ;;(global-set-key [S-mouse-5] 'up-one) (cond (window-system (mwheel-install) )) ;;; ;;; Force mouse yanks at point not at cursor. ;;; (setq mouse-yank-at-point t) ;; frame title : set to buffer name ;;(setq frame-title-format "Emacs - %f ") (setq frame-title-format (if window-system "%F - %f" "Emacs - %f")) (setq icon-title-format "%b") ;;(defun up-a-lot () (interactive) (scroll-up)) ;;(defun down-a-lot () (interactive) (scroll-down)) ;;(global-set-key [C-mouse-4] 'down-a-lot) ;;(global-set-key [C-mouse-5] 'up-a-lot) ;;; ;;; If you want to scroll by half a page instead of only 5 lines as above, ;;; John Rowe sent this GNU Emacs code: ;;; ;;(defun scroll-up-half () ;; "Scroll up half a page." ;; (interactive) ;; (scroll-up (/ (window-height) 2))) ;; ;;(defun scroll-down-half () ;; "Scroll down half a page." ;; (interactive) ;; (scroll-down (/ (window-height) 2))) ;; ;;(global-set-key [(mouse-5)] 'scroll-up-half) ;;(global-set-key [(mouse-4)] 'scroll-down-half) ;;; ;;; If you are intended BS (backspace) key to work ;;; correctly on some terminals, uncomment one of below s-exp. ;;; -- cinsk ;;(global-set-key [C-?] 'backward-delete-char) ;;(global-set-key [C-h] 'backward-delete-char); ;;; ;;; To use function keys, mouse button, or non-ASCII character such ;;; as `C-=' or `H-a', use a vector(`[..]') to specify the key sequence. ;;; ;;; - If a vector element is a character, use the Lisp character constant, ;;; `?'. e.g. `?\C-=' ;;; - For example, below two statements are the same: ;;; (global-set-key "\C-x\e\e" 'repeat-complex-command) ;;; (global-set-key [?\C-x ?\e ?\e] 'repeat-complex-command) ;;; ;;; Lisp Symbols for the function keys: ;;; `left', `up', `right', `down' ;;; Cursor arrow keys. ;;; ;;; `begin', `end', `home', `next', `prior' ;;; Other cursor repositioning keys. ;;; ;;; `select', `print', `execute', `backtab' ;;; `insert', `undo', `redo', `clearline' ;;; `insertline', `deleteline', `insertchar', `deletechar' ;;; Miscellaneous function keys. ;;; ;;; `f1', `f2', ... `f35' ;;; Numbered function keys (across the top of the keyboard). ;;; ;;; `kp-add', `kp-subtract', `kp-multiply', `kp-divide' ;;; `kp-backtab', `kp-space', `kp-tab', `kp-enter' ;;; `kp-separator', `kp-decimal', `kp-equal' ;;; Keypad keys (to the right of the regular keyboard), with names or ;;; punctuation. ;;; ;;; `kp-0', `kp-1', ... `kp-9' ;;; Keypad keys with digits. ;;; ;;; `kp-f1', `kp-f2', `kp-f3', `kp-f4' ;;; Keypad PF keys. ;;; (global-set-key "\C-cc" 'compile) (global-set-key "\C-cd" 'unicode-shell) (global-set-key [(control ?c) (control ?d)] 'zap-to-nonspace) (global-set-key [?\C-.] 'find-tag-other-window) ; C-x o ;; C-c C-l is used for c-toggle-electric-state ;(global-set-key [(control c) ?l] 'goto-line) ; M-g M-g is binded to goto-line (global-set-key [(control c) ?i] 'indent-region) ;;; C-x C-v is binded find-alternate-file by default. (global-set-key "\C-x\C-v" 'view-file) ;;;(defun my-c-mode-hook () ;;; (local-set-key "\C-cc" 'compile) ;;; (local-set-key "\C-cs" 'shell)) ;;; ;;;(add-hook 'c-mode-hook 'my-c-mode-hook) (define-abbrev-table 'c-mode-abbrev-table ;; I don't know why `@' for abbreviation doesn't work. ;; So I choose `$' for that. '(("$niy" "/* TODO: Not Implemented Yet. */" nil 0)) (add-hook 'c-mode-hook (function (lambda nil (abbrev-mode 1)))) ;;; imenu mode ;;;(add-hook 'c-mode-hook (function (lambda nil (imenu-add-to-menubar)))) ;;;(add-hook 'c++-mode-hook (function (lambda nil (imenu-add-to-menubar)))) ;;; which-function mode ;;;(add-hook 'c-mode-hook (function (lambda nil (which-function-mode)))) ;;;(add-hook 'c++-mode-hook (function (lambda nil (which-function-mode)))) (which-function-mode 1) ; display function names in mode-line ;;; ;;; Switching between buffers using iswitchb ;;; (iswitchb-mode 1) ; smart buffer switching mode (setq iswitchb-default-method 'maybe-frame) ; ask to use another frame. (global-font-lock-mode 1) ; every buffer uses font-lock-mode (line-number-mode 1) ; show line number in mode-line (column-number-mode 1) ; show column number in mode-line (setq resize-minibuffer-mode t) ; ensure all contents of mini ; buffer visible (tool-bar-mode -1) ; hide tool bar ;;(when window-system ;; (setq special-display-buffer-names ;; '("*Completions*" "*grep*" "*Buffer List*"))) (setq-default indent-tabs-mode nil) ; do not insert tab character. (defun source-untabify () "Stealed from Jamie Zawinski's homepage, http://www.jwz.org/doc/tabs-vs-spaces.html Remove any right trailing whitespaces and convert any tab character to the spaces" (save-excursion (goto-char (point-min)) (while (re-search-forward "[ \t]+$" nil t) (delete-region (match-beginning 0) (match-end 0))) (goto-char (point-min)) (if (search-forward "\t" nil t) (untabify (1- (point)) (point-max)))) nil) (add-hook 'c-mode-hook '(lambda () (make-local-variable 'write-contents-hooks) (add-hook 'write-contents-hooks 'source-untabify))) (add-hook 'c++-mode-hook '(lambda () (make-local-variable 'write-contents-hooks) (add-hook 'write-contents-hooks 'source-untabify))) (defun zap-to-nonspace () "Delete all whitespace up to the next non-whitespace char." (interactive) (save-excursion (let ((start (point)) (end (point-max))) (if (re-search-forward "[^ \n\t\v]" nil t) (setq end (min (1- (point)) end))) (kill-region start end)))) (when nil ;; Support for GNU global, the source code tag system (load-library "gtags") (add-hook 'c-mode-hook '(lambda () (gtags-mode 1))) (add-hook 'c++-mode-hook '(lambda () (gtags-mode 1)))) ;;; ;;; Colors ;;; ;;;(set-background-color "rgb:0000/1500/8000") ;;;(set-foreground-color "white") ;;;(set-cursor-color "") ;;;(set-mouse-color "") ;;;(set-face-foreground 'highlight "white") ;;;(set-face-background 'highlight "slate blue") ;;;(set-face-background 'region "slate blue") ;;;(set-face-background 'secondary-selection "turquoise") ;;; ;;; emacs server ;;; ;;;(load "/usr/share/emacs/21.2/lisp/gnuserv") (server-start) ;;;(load "gnuserv") ;;;(gnuserv-start) ;;; ;;; I prefer case-sensitive search & replace ;;; (setq-default case-fold-search nil) (setq-default tags-case-fold-search nil) (fset 'find-next-tag "\C-u\256") ; macro for C-u M-. (fset 'find-prev-tag "\C-u-\256") ; macro for C-u - M-. (global-set-key "\M-]" 'find-next-tag) (global-set-key "\M-[" 'find-prev-tag) ;(global-set-key [up] '(lambda () (interactive) (scroll-down 1))) ;(global-set-key [down] '(lambda () (interactive) (scroll-up 1))) (fset 'scroll-other-frame "\C-xo\C-v\C-xo") ; C-x o C-v C-x o (fset 'scroll-other-frame-down "\C-xo\366\C-xo") ; C-x o M-v C-x o (global-set-key [(meta shift prior)] 'scroll-other-frame-down) (global-set-key [(meta shift next)] 'scroll-other-frame) ;;; ;;; navigation customization ;;; (require 'cc-mode) (when (locate-library "cc-subword") (require 'cc-subword) (define-key c-mode-base-map [(meta ?F)] 'c-forward-subword) (define-key c-mode-base-map [(meta ?B)] 'c-backward-subword) (define-key c-mode-base-map [(meta ?D)] 'c-kill-subword)) (add-hook 'c-mode-common-hook (lambda () (cwarn-mode 1))) (define-key c-mode-base-map [(meta ?{)] 'c-beginning-of-defun) (define-key c-mode-base-map [(meta ?})] 'c-end-of-defun) (define-key c-mode-base-map [(control meta ?{)] 'c-up-conditional-with-else) (define-key c-mode-base-map [(control meta ?})] 'c-down-conditional-with-else) ;;; ;;; Prompt for arguments to the preprocessor for `c-macro-expand' ;;; (setq c-macro-prompt-flag t) (defun reverse-other-window (arg) "Reverse `other-window' with no argument" (interactive "p") (other-window (- arg))) (defun first-window () "Select the first window of the current frame." (let ((window nil)) (mapcar '(lambda (w) (let ((edges (window-edges w))) (and (eql (car edges) 0) (eql (cadr edges) 0) (setq window w)))) (window-list)) window)) (defun abs-other-window (index) "Same as \\[other-window] except the base is the first window not the current window" (interactive "p") (select-window (first-window)) (other-window index)) (global-set-key [(control x) ?w ?0] '(lambda () (interactive) (abs-other-window 0))) (global-set-key [(control x) ?w ?1] '(lambda () (interactive) (abs-other-window 1))) (global-set-key [(control x) ?w ?2] '(lambda () (interactive) (abs-other-window 2))) (global-set-key [(control x) ?w ?3] '(lambda () (interactive) (abs-other-window 3))) (global-set-key [(control x) ?w ?4] '(lambda () (interactive) (abs-other-window 4))) (global-set-key [(control x) ?w ?5] '(lambda () (interactive) (abs-other-window 5))) (global-set-key [(control x) ?w ?6] '(lambda () (interactive) (abs-other-window 6))) (global-set-key [(control x) ?w ?7] '(lambda () (interactive) (abs-other-window 7))) (global-set-key [(control x) ?w ?8] '(lambda () (interactive) (abs-other-window 8))) (global-set-key [(control x) ?w ?9] '(lambda () (interactive) (abs-other-window 9))) ;(global-set-key [C-tab] 'other-window) ; C-x o ;(global-set-key [S-iso-lefttab] 'reverse-other-window) ;(global-set-key [(backtab)] 'reverse-other-window) (global-set-key [(control tab)] 'smart-other-window) (global-set-key [(control x) ?w ?n] 'other-window) (global-set-key [(control x) ?w ?o] 'other-window) (global-set-key [(control x) ?w ?p] 'reverse-other-window) (global-set-key [(control x) ?w ?k] 'delete-window) (global-set-key [(control x) ?w ?K] 'delete-other-window) (defun smart-other-window () "This calls `other-window' if there are more than one window, otherwise calls `iswitchb'" (interactive) (if (one-window-p t 1) (call-interactively 'iswitchb-buffer) (call-interactively 'other-window))) (defun smart-other-frame (arg) "This calls `other-frame' if there are more than one frame, otherwise calls `other-window'" (interactive "p") (if (> (length (frame-list)) 1) (other-frame arg) (other-window arg))) (defun reverse-smart-other-frame (arg) "This calls `other-frame' if there are more than one frame, otherwise calls `other-window'" (interactive "p") (if (> (length (frame-list)) 1) (other-frame (- arg)) (other-window (- arg)))) (global-set-key [(control x) ?o] 'smart-other-frame) (global-unset-key [(control x) ?f]) (global-set-key [(control x) ?f ?f] 'new-frame) (global-set-key [(control x) ?f ?k] 'delete-frame) (global-set-key [(control x) ?f ?K] 'delete-other-frames) (global-set-key [(control x) ?f ?n] 'smart-other-frame) (global-set-key [(control x) ?f ?o] 'smart-other-frame) (global-set-key [(control x) ?f ?p] 'reverse-smart-other-frame) (defun run-command-other-frame (command) "Run COMMAND in a new frame." (interactive "CC-x 5 M-x ") (select-frame (new-frame)) (call-interactively command)) (global-set-key "\C-x5\M-x" 'run-command-other-frame) ;;; ;;; Quick Frame Configuration Load/Save ;;; (global-set-key [(control f2)] '(lambda () "Quick frame load" (interactive) (jump-to-register ?\x3) (message "Load saved frame configuration"))) (global-set-key [(control f3)] '(lambda () "Quick frame save" (interactive) (frame-configuration-to-register ?\x3) (message "Frame configuration saved"))) ;(require 'autofit-frame) ;(add-hook 'after-make-frame-functions 'fit-frame) ; ;(add-hook 'temp-buffer-show-hook ; 'fit-frame-if-one-window 'append) ;;; ;;; Emacs Lisp Mode ;;; (add-hook 'emacs-lisp-mode-hook '(lambda () (let ((tagfile "/usr/share/emacs/TAGS")) (and (file-readable-p tagfile) (visit-tags-table "/usr/share/emacs/TAGS"))))) (eval-after-load "lisp-mode" '(progn (define-key emacs-lisp-mode-map [f5] 'eval-buffer) (define-key emacs-lisp-mode-map [(control c) ?|] 'eval-region))) ;;; ;;; Common Lisp Mode -- from clisp-2.38/editors.txt ;;; ;;; It seems that Emacs already have `lisp-eval-last-sexp' that has ;;; the same feature of ` (setq inferior-lisp-program "clisp -I -q -E utf-8") (defun lisp-macroexpand-region (start end &optional and-go) "Macroexpand the current region in the inferior Lisp process. Prefix argument means switch to the Lisp buffer afterwards." (interactive "r\nP") (comint-send-string (inferior-lisp-proc) (format "(macroexpand-1 (quote %s))\n" (buffer-substring-no-properties start end))) (if and-go (switch-to-lisp t))) (defun lisp-macroexpand-sexp (&optional and-go) "Macroexpand the next sexp in the inferior Lisp process. Prefix argument means switch to the Lisp buffer afterwards." (interactive "P") (lisp-macroexpand-region (point) (scan-sexps (point) 1) and-go)) (eval-after-load "inf-lisp" '(define-key inferior-lisp-mode-map [(control ?x) (control ?m)] 'lisp-macro-expand-sexp)) (define-key lisp-mode-map [(control ?x) (control ?m)] 'lisp-macro-expand-sexp) ;;; ;;; psgml mode setup ;;; ;(autoload 'sgml-mode "psgml" "Major mode to edit SGML files." t) ;(autoload 'xml-mode "psgml" "Major mode to edit XML files." t) (defun lzx-nxml-mode () "OpenLaszlo XML Mode" (interactive) (nxml-mode) (make-local-variable 'nxml-child-indent) (setq nxml-child-indent 4)) (when (locate-library "rng-auto") (load (locate-library "rng-auto")) ;; `sgml-mode' adds an entry to `magic-mode-alist' so that ;; `auto-mode-alist' to `nxml-mode' might not work. To work around ;; this, define an alias for `xml-mode' to `nxml-mode'. (defalias 'xml-mode 'nxml-mode) ;(autoload 'nxml-mode "nxml-mode" "new XML major mode" t) (setq auto-mode-alist (cons '("\\.\\(xml\\|pvm\\|rss\\)\\'" . nxml-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.lzx\\'" . lzx-nxml-mode) auto-mode-alist))) ;;; ;;; nxml mode ;;; ;; Make a slash automatically completes the end-tag (eval-after-load "nxml-mode" '(progn (setq nxml-slash-auto-complete-flag t) (define-key nxml-mode-map [(control ?c) (control ?e)] 'nxml-enclose-paragraph))) (defun nxml-enclose-paragraph (start end prefix) "Enclose each paragraph with the element in the region. By default, <para> element is used. A prefix argument will give you a chance to change the name of the element." (interactive "*r\nP") (let (curpos (done nil) (elname "para")) (if (not (eq (prefix-numeric-value prefix) 1)) (setq elname (read-string "Element name: " "para" 'docbook-element-name-history))) (save-excursion (save-restriction (narrow-to-region start end) (goto-char (point-min)) (while (not done) (setq curpos (point)) (forward-paragraph) ;(message (format "curpos(%d) point(%d)" curpos (point))) (if (>= curpos (point)) (progn (setq done t))) (backward-paragraph) (if (eq (char-after) ?\n) (goto-char (1+ (point)))) (if (not done) (progn (insert (concat "<" elname ">\n")) (forward-paragraph) (insert (if (eq (char-before) ?\n) (concat "</" elname ">\n") (concat "\n</" elname ">"))) ;(message (format "pt(%d) pt-max(%d)" (point) (point-max))) (if (>= (point) (1- (point-max))) (setq done t)) ))))))) ;;; ;;; Dired and dired-x setting ;;; (require 'dired-x) (add-hook 'dired-load-hook (lambda () ;; Set dired-x global variables here. For example: ;; (setq dired-guess-shell-gnutar "gtar") ;; Bind dired-x-find-file. (setq dired-x-hands-off-my-keys nil) ;; Make sure our binding preference is invoked. (dired-x-bind-find-file) )) (add-hook 'dired-mode-hook (lambda () ;; Set dired-x buffer-local variables here. For example: (dired-omit-mode 1) )) (setq auto-mode-alist (cons '("[^/]\\.dired$" . dired-virtual-mode) auto-mode-alist)) (setq-if-equal dired-omit-files "^\\.?#\\|^\\.$\\|^\\.\\.$" (concat dired-omit-files ;; Omit RCS files "\\|^RCS$\\|,v\\'" ;; Omit CVS and Bitkeeper files "\\|^CVS$\\|^BitKeeper\\'" ;; Omit dot files "\\|^\\..+\\'" ;; Omit .o, .lo, .Po, .Plo, .a, .la files "\\|.+\\.\\(o\\|lo\\|Po\\|Plo\\|a\\|la\\)\\'")) (setq-if-equal dired-garbage-files-regexp "\\.\\(?:aux\\|bak\\|dvi\\|log\\|orig\\|rej\\|toc\\)\\'" (format "\\(?:%s\\|%s\\)\\'" "aux\\|bak\\|dvi\\|log\\|orig\\|rej\\|toc" ; TeX related "\\`\.#.*[0-9]")) ; VC related ;(define-key global-map "\C-x\C-j" 'dired-jump) ;(define-key global-map "\C-x4\C-j" 'dired-jump-other-window) (defun dired-jump-other-frame () "Like `dired-jump-other-window' but in other frame." (interactive) (let* ((file buffer-file-name) (dir (if file (file-name-directory file) default-directory))) (dired-other-frame dir))) (global-set-key [(control x) ?f ?j] 'dired-jump-other-frame) (defun dired-find-file-other-frame (&optional arg) (interactive "p") (let ((buffer (get-file-buffer (dired-get-file-for-visit))) (frame (next-frame (selected-frame) 'visible))) (and (not buffer) (setq buffer (find-file-noselect (dired-get-file-for-visit) nil nil nil))) (and (or (not frame) (eq frame (selected-frame))) (setq frame (make-frame))) (set-window-buffer (get-lru-window frame) buffer) (and (< arg 0) (select-frame-set-input-focus frame)))) (eval-after-load "dired" '(define-key dired-mode-map [(control return)] 'dired-find-file-other-frame)) ;;; ;;; Launch view-mode when visiting other's file. ;;; (defun file-uid (filename) (caddr (file-attributes (expand-file-name filename)))) (defun smart-view-mode () (let ((file (buffer-file-name))) (and (not (eq (file-uid file) (user-uid))) (view-mode 1)))) ;(add-hook 'find-file-hook 'smart-view-mode) ;;; ;;; cscope binding ;;; ;;; You need to install cscope(1) and xcscope.el to use below bindings ;;; Read xcscope.el packaged in cscope source tarball. It can be obtained ;;; from http://cscope.sourceforge.net/ ;;; (when (locate-library "xcscope") (require 'xcscope)) ;;; ;;; Version Control ;;; (global-set-key [(control x) (control q)] 'vc-toggle-read-only) ;;(when window-system (when nil (setq same-window-buffer-names (append '(;"*compilation*" "*Process List*") same-window-buffer-names)) (setq special-display-regexps '(("\\*Buffer List\\*" (font . "fixed") (left . 0) ; in pixels (top . -30) (auto-raise . t) (width . 70) (height . 10) ; in characters (vertical-scroll-bars . nil) (tool-bar-lines . nil) (menu-bar-lines . nil)) (("\\*Completions\\*" (font . "fixed") (left . 0) ; in pixels (top . -30) (auto-raise . f) (width . 70) (height . 10) ; in characters (vertical-scroll-bars . nil) (tool-bar-lines . nil) (menu-bar-lines . nil)) ("\\*cscope\\*" (font . "fixed") (left . 0) (top . 0) (auto-raise . t) (width . 80) (height . 20) (vertical-scroll-bars . nil) (tool-bar-lines . nil) (menu-bar-lines . nil)) ("\\*.*\\*" (tool-bar-lines . nil) (menu-bar-lines . nil)) )))) ;;(load "~/.emacs.d/theme") ;;(split-window-horizontally) ;; ;; Make the inferior shell a login shell. ;; (setq explicit-bash-args (quote ("--noediting" "-i" "-l"))) (setq gnus-select-method '(nntp "news.kornet.net")) (defmacro save-font-excursion (face &rest body) "Save the :font property of given FACE during the execution of BODY." (declare (indent 1) (debug t)) `(let ((oldfont (face-attribute ,face :font)) ret) (setq ret (progn ,@body)) (or (string= oldfont (face-attribute ,face :font)) (set-face-attribute ,face nil :font oldfont)) ret)) ;;; ;;; color-theme settings ;;; (setq color-theme-history-max-length 32) (defvar color-theme-favorites '(color-theme-deep-blue color-theme-cinsk-wood color-theme-charcoal-black color-theme-clarity color-theme-comidia color-theme-dark-blue2 color-theme-dark-laptop color-theme-taylor color-theme-robin-hood) "My favorite color theme list") (defun color-theme-select-random () "Select random color theme" (interactive) (let ((sym (car (nth (random (length color-themes)) color-themes)))) (funcall sym) (message "%s installed" (symbol-name sym))) (if nil ;; Below code was my first creation. Don't know which is better yet. (progn (random t) (let* ((index (+ (random (- (length color-themes) 2)) 2)) (theme (nth index color-themes))) (save-font-excursion 'default (funcall (car theme))) (message "%s installed" (symbol-name (car theme))))))) (defun color-themes-next-symbol (theme) "Return the next color-theme symbol of THEME" (let ((found 0) (next nil)) (catch 'found (mapcar (lambda (entry) (if (and (= found 1) (null next)) (progn (setq next (car entry)) (throw 'found t))) (if (eq (car entry) theme) (setq found 1))) color-themes)) (if (and (= found 1) (null next)) (setq next (car (caddr color-themes))) next))) (defun color-theme-apply (&optional arg) "Apply the color theme. If the argument is :random, this applies any color theme randomly, or if the argument is :next, this applies the next color theme in the installed color theme list. or if the argument is a symbol indicates the color-theme function, it applies that color theme." (cond ((fboundp arg) (apply arg nil)) ((eq arg :random) (color-theme-select-random)) ((eq arg :next) (let ((theme (color-theme-next-symbol))) (apply theme nil) (message "%s installed" (symbol-name theme)))) (t (error "Wrong type of argument")))) (defun color-theme-next-symbol () "Return the next color-theme symbol of the last applied color theme. This function works iff color-theme-history-max-length is not NIL" (if (null color-theme-history) (car (car color-themes)) (color-themes-next-symbol (car (car color-theme-history))))) (defun set-frame-color-theme (frame) (select-frame frame) (color-theme-select-random)) (when (and window-system (locate-library "color-theme")) (require 'color-theme) (color-theme-initialize) (and (locate-library "pink-bliss") (require 'pink-bliss)) (and (locate-library "cinsk-wood") (require 'cinsk-wood)) (global-set-key [(control f1)] 'color-theme-select-random) (global-set-key [(control f2)] '(lambda () (interactive) (color-theme-apply :next))) (add-hook 'after-make-frame-functions 'set-frame-color-theme) ;; color-theme-* is frame-local from now. (setq color-theme-is-global nil) ;; Select random color theme from my favorite list (let ((theme (nth (random (length color-theme-favorites)) color-theme-favorites)) (buf "*scratch*")) (funcall theme)) ;(set-face-font 'default "fontset-etl14") ) (autoload 'css-mode "css-mode" "CSS editing major mode" t) (eval-after-load "css-mode" '(setq cssm-indent-function #'cssm-c-style-indenter)) (add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode)) ;;; ;;; Calender ;;; (setq calendar-date-display-form '(year "-" month "-" day (if dayname (concat ", " dayname)))) (setq mark-holidays-in-calendar t) (setq mark-diary-entries-in-calendar t) (add-hook 'diary-display-hook 'fancy-diary-display) ;;; ;;; Org mode ;;; ;; org-hide-leading-stars should be set before loading org-mode. (setq org-hide-leading-stars t) (setq org-odd-levels-only t) (setq org-agenda-include-diary t) (add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) (global-set-key [(control c) ?a] 'org-agenda) (global-set-key [(control c) ?l] 'org-store-link) (eval-after-load "org" '(progn (define-key outline-mode-map [(control down)] 'outline-next-visible-heading) (define-key outline-mode-map [(control up)] 'outline-previous-visible-heading) (define-key outline-mode-map [(control shift down)] 'outline-forward-same-level) (define-key outline-mode-map [(control shift up)] 'outline-backward-same-level) ;; Rebind `org-force-cycle-archived' from "C-<TAB>" to "C-x C-<TAB>" ;; since I use "C-<TAB>" for `smart-other-window'. (move-key org-mode-map [(control tab)] [(control x) (control tab)]))) ;;; Emacs-wiki support ;;; ;(require 'emacs-wiki) ;;; ;;; ispell(aspell) configuration ;;; ;;; Currently neither of them provides Korean dictionary. ;;; Currently, ispell complained that it does not have proper dictionary in ;;; Korean language environment. (eval-after-load "ispell" '(progn (setq ispell-dictionary "english"))) ;;; ;;; Ediff customization ;;; (eval-after-load "ediff" '(progn ;; ignore whitespaces and newlines (setq ediff-ignore-similar-regions t) ;; do not create new frame for the control panel (setq ediff-window-setup-function 'ediff-setup-windows-plain) )) ;;; ;;; Do not display splash screen on startup ;;; ;;(when window-system ;; (fancy-splash-screens)) ;;(setq initial-buffer-choice t) ;;(setq inhibit-splash-screen t) (setq initial-buffer-choice t) ;;; ;;; ERC (IRC client) settings ;;; (when (locate-library "erc") (eval-after-load "erc" '(progn (setq erc-default-coding-system '(cp949 . undecided)) (setq erc-nick '("cinsk" "cinsky" "cinsk_" "cinsk__")) (setq erc-user-full-name "Seong-Kook Shin") (setq erc-server "localhost:8668")))) ;;; ;;; CLISP -- See doc/editors.txt in the CLISP package. ;;; (setq inferior-lisp-program "clisp -I -q -E utf-8") (defun lisp-macroexpand-region (start end &optional and-go) "Macroexpand the current region in the inferior Lisp process. Prefix argument means switch to the Lisp buffer afterwards." (interactive "r\nP") (comint-send-string (inferior-lisp-proc) (format "(macroexpand-1 (quote %s))\n" (buffer-substring-no-properties start end))) (if and-go (switch-to-lisp t))) (defun lisp-macroexpand-sexp (&optional and-go) "Macroexpand the next sexp in the inferior Lisp process. Prefix argument means switch to the Lisp buffer afterwards." (interactive "P") (lisp-macroexpand-region (point) (scan-sexps (point) 1) and-go)) (eval-after-load "inf-lisp" '(progn (define-key lisp-mode-map [(control ?x) (control ?m)] 'lisp-macroexpand-sexp) (define-key inferior-lisp-mode-map [(control ?x) (control ?m)] 'lisp-macroexpand-sexp))) ;;; ;;; python-mode ;;; (when (locate-library "python-mode") (setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist)) (setq interpreter-mode-alist (cons '("python" . python-mode) interpreter-mode-alist)) (autoload 'python-mode "python-mode" "Python editing mode." t)) (eval-after-load "python-mode" '(progn ;; python-mode uses `C-c C-c' for `py-execute-buffer' where most ;; major modes uses that for `comment-region'. Thus, I'll uses ;; `C-c C-e' bindings for py-execute-buffer. It makes sense ;; because cc-mode uses this for `c-macro-expand'. (define-key py-mode-map [(control ?c) (control ?c)] 'comment-region) (define-key py-mode-map [(control ?c) (control ?e)] 'py-execute-buffer) ;; python-mode uses `C-c C-d' for `py-pdbtrack-toggle-stack-tracking' (define-key py-mode-map [(control ?c) (control ?d)] 'zap-to-nonspace))) ;;; ;;; w3m ;;; (when (locate-library "w3m") (require 'w3m-load)) ;;; ;;; gnuplot ;;; (when (locate-library "gnuplot") (autoload 'gnuplot-mode "gnuplot" "gnuplot major mode" t) (autoload 'gnuplot-make-buffer "gnuplot" "open a buffer in gnuplot-mode" t) (setq auto-mode-alist (append '(("\\.gp$" . gnuplot-mode)) auto-mode-alist))) ;;; ;;; lua ;;; (when (locate-library "lua-mode") (autoload 'lua-mode "lua-mode" "Major mode for lua script") (add-to-list 'auto-mode-alist '("\\.lua\\'" . lua-mode))) ;;; ;;; ESS(Emacs Speaks Statistics) setting for R. ;;; (when (locate-library "ess-site") (require 'ess-site)) ;;; To save & load Emacs session, following lines should be the last line ;;; in this file. ;;; ;;; The first time you save the state of the Emacs session, you must do it ;;; manually, with the command `M-x desktop-save'. Once you have done that, ;;; exiting Emacs will save the state again--not only the present Emacs ;;; session, but also subsequent sessions. You can also save the state at ;;; any time, without exiting Emacs, by typing `M-x desktop-save' again. ;;; ;;; In order for Emacs to recover the state from a previous session, you ;;; must start it with the same current directory as you used when you ;;; started the previous session. This is because `desktop-read' looks in ;;; the current directory for the file to read. This means that you can have ;;; separate saved sessions in different directories; the directory in which ;;; you start Emacs will control which saved session to use. ;;(desktop-load-default) ;;(desktop-read) (put 'narrow-to-region 'disabled nil) (when nil (require 'kmacro) (fset 'next-visible-outline-other-window (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([C-tab 3 14 12 C-tab] 0 "%d")) arg))) (fset 'prev-visible-outline-other-window (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([C-tab 3 16 12 C-tab] 0 "%d")) arg))) (global-set-key [f3] 'prev-visible-outline-other-window) (global-set-key [f4] 'next-visible-outline-other-window)) (autoload 'calc "calc" "The Emacs Calculator" t) (global-set-key [f12] 'calc) (global-set-key [(control f12)] 'quick-calc) (add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) (global-set-key [f2] 'ff-find-other-file) (global-set-key [f3] 'dired-jump) ;;; ;;; ecb settings ;;; (when window-system (autoload 'ecb-activate "ecb" "Emacs Code Browser" t) (eval-after-load "ecb" '(progn (setq ecb-toggle-layout-sequence '("left3" "left-symboldef" "left8")) (setq ecb-tip-of-the-day nil) (set-face-font 'ecb-default-general-face "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*") ))) (defun ecb-next-action (arg) (interactive "P") (or (featurep 'ecb) (progn (require 'cedet) (require 'ecb))) ; load required packages (cond ((null ecb-minor-mode) (ecb-activate)) (t (if (null arg) (ecb-toggle-layout) (ecb-deactivate))))) (global-set-key [f11] 'ecb-next-action) (setq dired-recursive-copies 'always) (setq dired-recursive-deletes 'top) ;;; Local Variables: ;;; coding: utf-8 ;;; End: |
Category Archives: Emacs
Emacs Interact
How do you get user input (after displaying a prompt) in the command line?
One way is with (interactive), which is used to turn a function
into a command. As an example, look at
(defun irc-join (chan)
"join an IRC channel"
(interactive "sChannel to join: ")
(save-excursion
(setq irc-channel chan)
(irc-send-server (concat "JOIN " chan))))
Okay, what does this mean? When you want to define a function,
it begins with ‘defun’. Then next word, ‘irc-join’, is the name
of the function. Following that is ‘(chan)’, which is in
general the parameter list; this means that ‘chan’ is a
variable which is local to this function; if you want no parameters,
just put an empty list (). Following that is a description string
“join an IRC channel”; that string will show up whenever you do
M-x apropos on the function; that string is optional.
Finally, we get to the (interactive) part. What we are
concentrating on is the string: “sChannel to join: “, which has
a special format. The first character — ‘s’ in this case — specifies
the “type” of value to put in the first variable of the parameter
list. The character ‘s’ means “string”. So, now whenever somebody
calls your function with M-x irc-join, they would be prompted
to enter a string; the prompt will be “Channel to join: “. If you
wanted more parameters, it would be something like:
(defun function-name (stringparam numberparam)
(interactive "sPrompt here: \nnAnother prompt: ")
etc...
Note that each prompt string is separated by a newline character “\n”.
Also, ‘n’ means you want to get a number from the user. For more
info on these code characters, look under “defining commands”
section of the elisp docs.
You don’t necessarily have to use (interactive) to read in those
values, however. You could also do something like the following:
(defun irc-set-port ()
"set port number"
(interactive)
(let ((port
(read-string (concat "Port[" irc-port "]: ") "6667")))
(if (not (string-equal port ""))
(setq irc-port (string-to-number port)))))
This function has no parameters, and you notice (interactive)
also doesn’t have any prompt string. The main thing to look at
here is the ‘read-string’ function. This function takes one
argument which is a string for a prompt. Here I have shown a
little trick using the ‘concat’ function, which will let you
show a default value in the prompt.
You can find lots of information on functions like this by
using the apropos command: M-x apropos RET
Emacs Backup File Management
Set emacs so that all backups are directed into one folder:
(such as at a directory “~/myBackups”)
Use the following lisp code in init file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ; return a backup file path of a give file path ; with full directory mirroring from a root dir ; non-existant dir will be created (defun my-backup-file-name (fpath) “Return a new file path of a given file path. If the new path’s directories does not exist, create them.” (let (backup-root bpath) (setq backup-root “~/.emacs.d/emacs-backup”) (setq bpath (concat backup-root fpath “~”)) (make-directory (file-name-directory bpath) bpath) bpath ) ) (setq make-backup-file-name-function ‘my-backup-file-name) |
The above will mirror all directories at the given backup dir. For
example, if you are editing a file “/Users/jane/web/xyz/myfile.txt”,
and your backup root is “/Users/jane/.emacs.d/emacs-backup”, then the
backup will be at “/Users/jane/.emacs.d/emacs-backup/Users/jane/web/
xyz/myfile.txt~”.
If you want all backup to be flat in a dir, use the following:
1 | (setq backup-directory-alist ‘((”" . “~/.emacs.d/emacs-backup”))) |
This will create backup files flat in the given dir, and the backup
file names will have “!” characters in place of the directory
separator. For example, if you are editing a file at “/Users/jane/web/
xyz/myfile.txt”, and your backup dir is set at “/Users/jane/.emacs.d/
emacs-backup”, then the backup file will be at: “/Users/jane/.emacs.d/
emacs-backup/Users!jane!web!emacs!myfile.txt~”. If you use long file
names or many nested dirs, this scheme will reach file name length
limit quickly.
Emacs Cheats
Emacs tips
==========
Time-stamp: <2007-08-18 17:40:08 sjs>
Inside an incremental search:
* C-w pulls in the word under point
* C-y pulls in the rest of the line from point
* M-y yanks the last text from the kill ring
Keybinding Function Description
———- ——– ———–
==Help
| C-h c | describe-key-briefly | Display the name of the function bound to the given key sequence. |
| C-h k | describe-key | Display documentation for the function bound to the given key sequence. |
| C-h w | where-is | Display key sequences bound to the given command name. |
| C-h l | view-lossage | Display the last 100 keystrokes. |
| C-h m | describe-mode | Display documentation on the current major mode. |
** C-h after any prefix key will display all available shortcuts under that prefix. **
==General
word-search-{forward,backward} Search for sequences of words across newlines & puncuation.
C-x $ set-selective-display Hide lines indented greater than ARG levels (folding).
follow-mode Scroll windows of the same buffer in harmony.
C-x = what-cursor-position Display details about what’s under the cursor.
C-x z repeat Repeat the most recently executed command.
C-x ESC ESC repeat-complex-command Edit and re-evaluate the last complex command (or ARGth command).
list-history-command List commands available for repitition (via repeat-complex-command).
==Mark and point
M-r move-to-window-line nil ARG: Move to the middle of the window.
ARG > 0: Move point to the ARGth line.
ARG < 0: Move point to the |ARG|th line from the bottom.
C-x h mark-whole-buffer Mark the entire buffer.
C-x C-x exchange-mark-and-point Exchange mark and point, reactivating mark if required.
C-SPC set-mark-command Set and activate the mark, C-u C-SPC pops the mark ring.
C-x C-SPC pop-global-mark
A prefix of 0 (C-u 0) has a special meaning for the transpose family of functions. Since it would otherwise be meaningless
it transposes the chars/words/sexps/lines around the region specified by point and mark. It's best to try this one out to
see exactly how it works!
C-t transpose-chars
M-t transpose-words
C-M-t transpose-sexps
C-x C-t transpose-lines
** Mark and point can be treated as a rectangle, and are by certain functions. (see next section) **
==Rectangles
C-x r c clear-rectangle Replace text in the rectangle with spaces, blanking out the region destructively.
C-x r d delete-rectangle Delete text in the rectangle described by mark and point.
C-x r o open-rectangle Shift text in the rectangle right, blanking out the region non-destructively.
C-x r t string-rectangle Replace rectangle contents with the given string.
C-x r y yank-rectangle Yank back the last killed rectangle contents, top-left at point.
==Whitespace / cleaning up
C-x C-o delete-blank-lines Delete all but one of many consecutive blank lines.
fixup-whitespace Clean up space between objects around point.
M-\ delete-horizontal-space Delete all spaces & tabs around point.
M-SPC just-one-space Delete all spaces & tabs around point except for one (or N).
canonically-space-region Remove extra spaces between words in region.
delete-trailing-whitespace Delete all trailing whitespace in the current buffer.
==Shell mode
C-c C-n comint-next-prompt Move point to the next prompt.
C-c C-p comint-previous-prompt Move point to the previous prompt.
C-c RET comint-copy-old-input Copy the command input at point to the end of the buffer.
Variable Description
-------- -----------
track-eol If set next-line and previous-line will move to EOL if moving from EOL.
Slime mode
==========
Keybinding Function Description
---------- -------- -----------
==Compilation
C-c C-k slime-compile-and-load-file Compile and load the current buffer.
C-c M-k slime-compile-file Compile (but don't load) the current buffer.
C-c C-c slime-compile-defun Compile the top-level form at or around point.
M-n slime-next-note Move to the next compiler note.
M-p slime-previous-note Move to the previous compiler note.
C-c M-c slime-remove-notes Remove all annotations from the buffer.
==REPL
C-Return slime-repl-closing-return Close all open parentheses and evaluate the current line.
==Navigation
M-. slime-edit-definition Go to the definition of the symbol at point.
M-, slime-pop-find-definition-stack Go back from the definition found with slime-edit-definition.
==Evaluation
C-M-x slime-eval-defun Evaluate the top-level form.
(ARG inserts result into buffer)
C-x C-e slime-eval-last-expression Evaluate the last expression before point.
(ARG inserts result info buffer)
C-c C-p slime-pprint-eval-last-expression Evaluate the expression before point and pretty-print the result.
C-c C-r slime-eval-region Evaluate the region.
C-c : slime-interactive-eval Evaluate an expression read from the minibuffer.
slime-scratch Create a buffer like Emacs' *scratch*, eval expressions with C-j.
==Programming
C-c M-i slime-fuzzy-complete-symbol Presents a list of likely completions to choose from for an abbreviation
at point.
C-c C-s slime-insert-arglist Look up and insert the arg list for the function at point.
C-c C-m slime-macroexpand-1 Macroexpand the expression at point once. Use a prefix to call macroexpand
instead of macroexpand-1.
C-c C-t slime-toggle-trace-fdefinition Toggle tracing of the function at point.
C-c M-d slime-disassemble-symbol Dissassemble the function definition of the symbol at point.
==Debugging
[TODO clean this up, this is copied from the Emacs wiki]
The following commands invoke restarts:
* 0 .. 9 - Invoke a restart by number.
* q - Throw to the top-level.
* a - Invoke the ABORT restart.
* c - Invoke the CONTINUE restart.
There are also commands for poking around in the frame at point:
* v - Show the current frame's source expression in a buffer.
* t - Toggle verbose display of the frame at point. The verbose version includes all local variables and CATCH tags.
* l - Show local variables.
* e - Evaluate an expression from inside a frame.
* d - Evaluate an expression and display the result in an extra buffer.
* i - Evaluate an expression and inspect the result.
* : - Evaluate an expression (in the global environment).
* D - Disassemble the code of the current frame.
* r - Restart execution of the frame with the same arguments as it was called originally. (Not supported by all backends.)
* R - Return a value from the current frame. (Not supported by all backends.)
Motion between frames:
* n - Move to the next frame.
* p - Move to the previous frame.
* M-n - Detail-move to the next frame. This switches the current frame to a one-line summary, then moves to the next frame, displays it verbosely in the backtrace (as with t), and shows the corresponding source expression (as with v).
* M-p - Detail-move to the previous frame.
==Reference
C-c < slime-who-calls Reveal callers of the function at or around point.
C-c > slime-who-references Reveal references to the global variable at or around point.
C-c C-d is the prefix for the following help commands:
d slime-describe-symbol Describe the symbol at point.
a slime-apropos
z slime-apropos-all Includes internal symbols.
p slime-apropos-package
h slime-hyperspec-lookup Customize with common-lisp-hyperspec-root browse-url-browser-function.
~ common-lisp-hyperspec-format
Emacs Tagify
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | (defun wrap-region (left right) "Wrap the region in arbitrary text, LEFT goes to the left and RIGHT goes to the right." (interactive) (let ((beg (region-beginning)) (end (region-end))) (goto-char beg) (insert left) (goto-char (+ end (length left))) (insert right) (goto-char (+ end (length left) (length right))))) (defun tagify-region-or-insert-self (arg) "If there is a visible region, call `tagify-region-or-insert', otherwise call `self-insert-command' passing it any prefix arg given." (interactive "*P") (if (and mark-active transient-mark-mode) (call-interactively 'tagify-region-or-insert-tag) (self-insert-command (prefix-numeric-value arg)))) (defun tagify-region-or-insert-tag (tag) "If there is a visible region, wrap it in the given HTML/XML tag using `wrap-region'. If any attributes are specified then they are only included in the opening tag. Otherwise insert the opening and closing tags and position point between the two." (interactive "*sTag (including attributes): \n") (let* ((open (concat "<" tag ">")) (close (concat "</" (car (split-string tag " ")) ">"))) (if (and mark-active transient-mark-mode) (wrap-region open close) (insert (concat open close)) (backward-char (length close))))) (provide 'tagify) |
note:
now insert the opening and closing tags and sets point in between them. I have this bound to C-z t, as I use C-z as my personal command prefix.
< is bound to tagify-region-or-insert-self which really doesn’t warrant an explanation.
Adding a mode to emacs
How to add a new mode in gnu.emacs.help :
1. Put the .el file in the right directory.
2. Byte-compile the .el file, giving a .elc file which runs faster.
3. Put any setup stuff in ~/.emacs.
(1) Copy to right directory.
Type C-h v load-path RET to learn which directories are searched by
Emacs. A directory named site-lisp is for site-wide .el files and is
retained even after Emacs upgrades. If you don’t find a convenient
directory in this list, just add your own from ~/.emacs:
(add-to-list 'load-path (expand-file-name "~/lisp/"))
The copy operation itself should be obvious
(2) Byte-compile.
This one is easy: type M-x byte-compile-file RET, then enter the name
of the file (the copy in the site-lisp or ~/lisp directory or wherever
you put it).
(3) Setup stuff in ~/.emacs.
Usually, you will find a comment at the beginning of the .el file to
explain how to set it up. For matlab-mode.el, this does not seem to
be the case. Well, the easiest thing to do is to put the following
line in your .emacs file:
(require 'matlab-mode)
Then, you can load a matlab file then type M-x matlab-mode RET to
enter the right mode. Or you can tell Emacs to automatically enter
matlab-mode for files with certain suffixes:
(add-to-list 'auto-mode-alist '("\\.matlab\\'" . matlab-mode))
Or, you can put a line like the following in all matlab files:
/* -*- matlab-mode -*- */
Before the first “-*-” and after the second “-*-” you can put any
text, such as the comment characters defined for the mode. I used C
comment characters in my example, but you can use the ones that are
right for matlab files.