Gnu Emacs æ¡å¼µã¬ã¤ã: Emacs Lispããã°ã©ãã³ã°ãã¾ã¨ã
GNU Emacsæ¡å¼µã¬ã¤ãã¯æ¢ã«çµ¶çããæ¬ãããã§ãããä¸å¹´ãããAmazonã®ãã¼ã±ãããã©ã¤ã¹ã§è²·ã£ã¦,æ¬ã®å
容ãè²ã
ã¨è¨å®ããå¾ãã°ããã®éæ¾ç½®ãã¦ããã®ã§ããä¹
ã
ã«è¦ã¤ããã®ã§ãªãã¨ãªãã¾ã¨ãã¦ã¿ã¾ããå
容ã¯Emacs Lispã®å®è·µçãªtipséã¨ã§ãããã¹ãã. ãããä¸éãèªãã°Emacs Lispã®ã½ã¼ã¹ãèªãã + ãã¤ãã¼ã¢ã¼ã or ã¡ã¸ã£ã¼ã¢ã¼ããä½ãããããã«ã¯ãªããã¨æãã¾ããå¤ãæ¬ã§ããã¾ããªããªãå
容ã¯ããããããªããã¨ã
ã¨ããããå§ãã«ç®æ¬¡ã¨æ¦è¦ã«ã¤ãã¦è§¦ãã¨ãã¾ã
- 1ç« Emacsãã«ã¹ã¿ãã¤ãºãã
- ç°¡åãªã«ã¹ã¿ãã¤ãº + aproposã³ãã³ãéè¦ã¨ããå 容
- 2ç« ç°¡åãªã³ãã³ããä½ã
- ç°¡åã ããã©ãé常ã«å½¹ã«ç«ã¤ã³ãã³ãã®ä½æ. Lispã®è§£èª¬ããã¤ã¤å®è£ . å®éãã®æã®ã³ãã³ãã¯ãã¾ãè¦ãããªããçµæ§ä¾¿å©.
- 3ç« ã³ãã³ãéã®å¼·èª¿
- è¦ããã«undoã£ã½ãäºãããããã¨ããæããunscroll
- 4ç« ãããã¡ã®ãªããæ¤ç´¢ãå¤æ´ãã
- 4ç« ããããããæ¬æ ¼çå 容ã«ãªã£ã¦ãããbufferã®ä¸ãæ¤ç´¢ãããæ¡ä»¶ãæºãããç®æã«ãããã¿ã¤ã ã¹ã¿ã³ãã®æ´æ°ãè¡ãã¨ããæãã®å 容ã save-excursion, save-restriction, save-match-data, search-forward, Lispã«ãããæ£è¦è¡¨ç¾ã®ä½¿ãæ¹ã«é¢ãã説æãªã©ã
- 5ç« Lispãã¡ã¤ã«
- 4ç« ã®å 容ãè¸ã¾ããå 容. 4è³ã§ä½ã£ãå 容ãtimestam.elã¨ãããã¡ã¤ã«ã«ã¾ã¨ããããããè¸ã¾ãã¦ãLispãã¡ã¤ã«ã®ä½ãæ¹ + load, require, autoload, eval-after-loadã®éãã«é¢ãã説æ + ãã¤ãã³ã³ãã¤ã«ã«ã¤ãã¦ã®èª¬æããªããã¦ããã
- 6ç« ãªã¹ã
- ãªã¹ãã®èª¬æã Lispãããããç¥ã£ã¦ããå ´åã¹ã«ã¼å¯
- 7ç« ãã¤ãã¼ã¢ã¼ã
- 7ç« ä»¥éã¯ä½ããã®ã¢ã¼ããå®è£ ããã¨ããå 容ã«ãªã£ã¦ãã¾ãã 7ç« ã§ã¯ã¢ã¼ãã«é¢ãã説æ + refillã¢ã¼ãã¨ãã段è½ã®è¡è©°ãããããã¤ãã¼ã¢ã¼ããå®éã«å®è£ ãã¦ããããã¾ãã
- 8ç« ãè©ä¾¡ã¨ã¨ã©ã¼å¦ç
- 7ç« ã®å 容ãè¸ã¾ããå 容save-excursionã¯çµæ§éãå¦çãããã®ã§limited-excursionã¨ãããã¯ããå®è£ ããããã¯ãã®èª¬æãå¤ãã
- 9ç« ã¡ã¸ã£ã¼ã¢ã¼ã
- ã¡ã¸ã£ã¼ã¢ã¼ãã®èª¬æã¨quip-mode(åè¨ç·¨éã¢ã¼ã)ã®å®è£ .ããã¼ã¤ã³ã°ã¨æ´¾çã¢ã¼ãã®èª¬æãªã©
- 10ç« ç·åçãªä¾
- ããã¾ã§ã®å¿ç¨ã¨ããããã§ã¯ãã¹ã¯ã¼ãããºã«ã£ã½ãã¡ã¸ã£ã¼ã¢ã¼ããä½ãã¾ãã
以éã¯å
·ä½çãªå
容ã«ãªãã¾ã
1ç« Emacsãã«ã¹ã¿ãã¤ãºãã
ç¹ã«ãªã, aproposéè¦
2ç« ä¾¿å©ãªã³ãã³ããä½æãã
ã¿ã¤ãã«ã®éã便å©ãªã³ãã³ããä½ã£ã¦ãã
- ãã®ï¼ other-window-backward
- other-windowã¨ããã³ãã³ãã¯æ¨æºã§æè¼ããã¦ãããother-window-backwardã¯ãªãã®ã§ããã®å®è£ ãè¡ã
å ·ä½çã«ã¯ä»¥ä¸ã®ãããªå®è£ ããã
(defun other-window-backward (&optional n) "Select nth previous window." (interactive "P") (other-window (- (prefix-numeric-value n)))) ;; key settings (global-set-key "\C-x\C-p" 'other-window-backward) (global-set-key "\C-xp" 'other-window-backward)
other-window-backwardã¯ä»¥ä¸ã®ããã«ãããããEmacs Lispçã«ã¯ä¸è¨ã®ã³ã¼ãã®æ¹ãè¯ãã¨ã®äºãå®éEmacs Lispã®ã½ã¼ã¹ã¯(interactive "p")ã§ã¯ãªã(interactive "P")ã使ã£ã¦ããå¾åãããæ°ããã
(defun other-window-backward (&optional n) "Select nth previous window." (interactive "p") (other-window (- (or n 1))))
- ãã®2ãä¸åã«ä¸è¡ã®ã¹ã¯ãã¼ã«
å
容çã«ã¯vimã®
(defalias 'scroll-ahead 'scroll-up) (defalias 'scroll-behind 'scroll-down) (defun scroll-n-lines-ahead (&optional n) "Scroll ahead N lines." (interactive "P") (scroll-ahead (prefix-numeric-value n))) (defun scroll-n-lines-behind (&optional n) "Scroll behind N lines." (interactive "P") (scroll-behind (prefix-numeric-value n))) (global-set-key "\C-q" 'scroll-n-lines-ahead) (global-set-key "\C-z" 'scroll-n-lines-behind)
- ãã®3 ãã®ä»ã®ã«ã¼ã½ã«ç§»åã³ãã³ã
ãã®2以å¤ã®ã«ã¼ã½ã«ç§»åã³ãã³ãã以ä¸ã®è¨å®ã¯ããããçµæ§ä¾¿å©ã§ãã
ã¨ããããå®è¡ãã¦ã¿ãã¨ããããããªãã§ããã
(defun point-to-top() "put point on top line of window" (interactive) (move-to-window-line 0)) (global-set-key "\M-," 'point-to-top) (defun point-to-bottom() "put point at beginning of last visible line." (interactive) (move-to-window-line -1)) (global-set-key "\M-." 'point-to-bottom) (defun line-to-top() "Move current line to top of window" (interactive) (recenter 0)) (global-set-key "\M-!" 'line-to-top) (global-set-key "\C-ct" 'line-to-top)
- ãã®4 ã·ã³ããªãã¯ãä¸æ¸ã
- ãã¡ã¤ã«ãèªã¿è¾¼ãã æã«ãããã·ã³ããªãã¯ãªã³ã¯ãªããããã¡ãèªã¿è¾¼ã¿å°ç¨ã«ãã¦"File is a symlink"ã¨ããmessageãéãã¨ãã趣æ¨
(defun read-only-if-symlink () (if (file-symlink-p buffer-file-name) (progn (setq buffer-read-only t) (message "File is a symlink")))) (add-hook 'find-file-hooks 'read-only-if-symlink)
以ä¸ã¯ã·ã³ããªãã¯ãªã³ã¯ãæ±ãããã®äºç¨®é¡ã®é¢æ°ã
(defun visit-target-instead () "Replace this buffer with a buffer visiting the link target." (interactive) (if buffer-file-name (let ((target (file-symlink-p buffer-file-name))) (if target (find-alternate-file target) (error "Not visiting a symlink"))) (error "Not visiting a file"))) (defun clobber-symlink() "Replace symlink with a copy of the file." (interactive) (if buffer-file-name (let ((target (file-symlink-p buffer-file-name))) (if target (if (yes-or-no-p (format "Replace %s with %s? " buffer-file-name target)) (progn (delete-file buffer-file-name) (write-file buffer-file-name))) (error "Not visiting a symlink"))) (error "Not visiting a file"))) (global-set-key "\C-xt" 'visit-target-instead) (global-set-key "\C-x1" 'clobber-symlink)
- ãã®5 ãã®æ¬¡ã¯ãããã¡ã®åæ¿æã«ã¢ããã¤ã¹ãä¸ããã¨ããå 容,
- defadviceã使ç¨ãããdefadviceã¯ããé¢æ°ãå®è¡ãããåãå¾ã«å®è¡ããããã°ã©ã ãæå®åºæ¥ãã¨ããæ©è½ãã¾ãããªã¬ã¼ã§ãããå称è¬
- ããããäºã¯bufferåæ¿æã«ç¾ç¶åå¨ããªãbufferãèªã¿è¾¼ã¾ãªãããã«ããã¨ãããã®ã ã½ã¼ã¹ã¯ä»¥ä¸ã®éãã
(defadvice switch-to-buffer (before existing-buffer activate compile) "when interactive, switch to existing buffers only, unless given a prefix argument." (interactive (list (read-buffer "Switch to buffer:" (other-buffer) (null current-prefix-arg)))))
ã¾ããããã便å©ã
3ç« ã³ãã³ãéã®å調
undoã£ã½ãäºãå®è£ ãããã§ãã,ãã¾ãå¿ è¦ãªããããã¾ããã£ãããã£ãã§ä¾¿å©ã¨ããã°ä¾¿å©
ééãã¦scroll-upãªã©ãå®è¡ããã¨ãã«å ã®å ´æã«æ»ãã³ãã³ãã欲ããã¨ããæãã®è¶£æ¨ã
ã¾ãåãæ¢ãããã£ã¨ã§ã¦ããElispãè¼ãã¦ããã¾ããæçµåã ããªã®ã§ããªãç¥ãã¨ãã¾ã
(defvar unscroll-point (make-marker) "Cursor position for next call to 'unscroll'.") (defvar unscroll-window-start (make-marker) "Window start for next call to 'unscroll'.") (defvar unscroll-hscroll nil "Hscroll for next call to 'unscroll'.") (defadvice scroll-up (before remember-for-unscroll activate compile) "Remember where we started from, for 'unscroll'." (unscroll-maybe-remember)) (defadvice scroll-down (before remember-for-unscroll activate compile) "Remember where we started from, for 'unscroll'." (unscroll-maybe-remember)) (defadvice scroll-left (before remember-for-unscroll activate compile) "Remember where we started from, for 'unscroll'." (unscroll-maybe-remember)) (defadvice scroll-right (before remember-for-unscroll activate compile) "Remember where we started from, for 'unscroll'." (unscroll-maybe-remember)) (put 'scroll-up 'unscrollable t) (put 'scroll-down 'unscrollable t) (put 'scroll-left 'unscrollable t) (put 'scroll-right 'unscrollable t) (defun unscroll-maybe-remember () (if (not (get last-command 'unscrollable)) (progn (set-marker unscroll-point (point)) (set-marker unscroll-window-start (window-start)) (setq unscroll-hscroll (window-hscroll))))) (defun unscroll () "Revert to 'unscroll-point', 'unscroll-window-start' and 'unscroll-hscroll'." (interactive) (goto-char unscroll-point) (set-window-start nil unscroll-window-start) (set-window-hscroll nil unscroll-hscroll))
3ç« ã®tipsçãªå 容ã¯ä»¥ä¸ã®éã
- defvarã«ã¤ãã¦ãããã
- defvarã§ã¯defunã®ããã«å¤æ°ã«èª¬æãã¤ãããã¨ãåºæ¥ãã
- å¤æ°ã«ããã©ã«ãå¤ãä¸ããäºãåºæ¥ã
- ã¿ã°é¢ä¿ã®ã³ãã³ãã§å¤æ°å®£è¨ãè¦ã¤ãããã¨ãåºæ¥ã
- ããã°ã©ã ããã¤ãã³ã³ãã¤ã«ããædefvarã§å®£è¨ãã¦ããªãå¤æ°ãè¦ã¤ããã¨è¦åãçºããã
- goto-char, set-window-start, set-window-hscrollã¯ããããã«ã¼ã½ã«ã®ä½ç½®ã®è¨å®ãã¦ã¤ã³ãã¦ã®éå§ä½ç½®ã®è¨å®ãæ°´å¹³æ¹åã®ã¹ã¯ãã¼ã«ç¶æ ãè¨å®åºæ¥ãã
- point, window-start, window-hscrollã¯ããããç¾å¨ã®ä½ç½®ãã¦ã¤ã³ãã¦ã®ä½ç½®ãæ°´å¹³æ¹åã®ä½ç½®ãä¿æãã¦ããã°ãã¼ãã«å¤æ°
- å¤æ°ãé¢æ°ã«ã·ã³ãã«å±æ§ãã¤ãã¦ããã¨ä¾¿å©ãªäºããããè¨å®ã¯put, åå¾ã¯get
- last-commandã¯ååå®è¡ããã³ãã³ããè¨æ¶ãã¦ããå¤æ°, this-commandã¯ç¾å¨å®è¡ãã¦ããã³ãã³ãã®å 容ãä¿æãã¦ããå¤æ°ã§ããã
- ãã¸ã·ã§ã³é¢é£ã®æä½ãããéã«ã¯ãã¼ã«ã¼ã¯ä¾¿å©ããªããªããããã¡ã®ç·¨éãèæ ®ãã¦ãããããã
ã¾ããããªã¨ããã
4ç« ãããã¡ã®ãªããæ¤ç´¢ãå¤æ´ããã
- æå»ã«é¢ããã®ããé¢æ°ã®èª¬æ + ãããã¡ãæ¤ç´¢ãã¦æ£è¦è¡¨ç¾ãå©ç¨ãã¦ããæ¡ä»¶ãæºãããç®æã«ç¾å¨æå»ãå ããã¨ããå
容ããããããªãã¯ããã¯ã®è§£èª¬ãç¹ã«æ£è¦è¡¨ç¾ã
- ãã¡ã¤ã«ãæ°ãã«æ´æ°ãã度ã«ã©ã¤ãã¹ã¿ã³ããæ´æ°ãããã
ã¨ããããé çªã«ã¿ã¦ããã¾ãã
以ä¸ã¯åã«ç¾å¨ã®æå»ãæ¸ãå ããã³ãã³ããé¢æ°ã«åºã¦ãã(interactive "*")ã®æå³ã¯ãããã«ã¬ã³ããããã¡ãèªã¿è¾¼ã¿å°ç¨ãªãé¢æ°ã®å®è¡ãä¸æ¢ããã¨ããäºã
(defun insert-current-time() "Insert the current time" (interactive "*") (insert (current-time-string)))
次ã«å¤æ°ã®å®ç¾©ã注ç®ãã¹ãäºã¨ãã¦ã¯ãdefvarã®å®ç¾©ã«ããã¦*ãå§ãã«ããå ´åã¯ãã®å¤æ°ã対話çã«å¤æ´åºæ¥ãã¨ããç¹ã\\[insert-time]ã¯ãã®ã¾ã¾æååã¨ãã¦ç¾ãããã¨ã¯ãªãinsert-timeã®ãã¼ãããã«ç½®ãæããããã¨ããç¹ãããããã¾ãããã¼ãå²ãå½ã¦ããã¦ãªãå ´åã«ã¯M-x insert-timeã使ããã¾ãã
(defvar insert-time-format "%H:%M" "*Format for \\[insert-time] (c.f. 'format-time-string').") (defvar insert-date-format "%m-%d" "*Format for \\[insert-date] (c.f. 'format-time-string').")
次ã«insert-time, insert-dateãä½æãã
(defun insert-time () "Insert the current time according to insert-time-format." (interactive "*") (insert (format-time-string insert-time-format (current-time)))) (defun insert-date () "Insert the current date according to insert-time-format." (interactive "*") (insert (format-time-string insert-date-format (current-time))))
- 次ã«ã©ã¤ãã¹ã¿ã³ãã¨ããé¢æ°ãå®è£
ãã¾ãããã½ã¼ã¹ã¯ä»¥ä¸ã®éãã
- (add-hook 'local-write-file-hooks 'update-writestamps)ã«ããããã¡ã¤ã«ãã»ã¼ããã度ã«'update-writestampsãå¼ã°ããããã¾ãã
(defvar writestamp-format "%Y-%m-%d %H:%M" "*Format for writestamps (c.f. 'format-time-string').") (defvar writestamp-prefix "WRITESTAMP((" "*Unique string identifying start of writestamp.") (defvar writestamp-suffix "))" "*String that terminates a writestamp.") (add-hook 'local-write-file-hooks 'update-writestamps) (defun update-writestamps () "Find writestamps and replace them with the current time." (save-excursion (save-restriction (save-match-data (widen) (goto-char (point-min)) (let ((regexp (concat "^" (regexp-quote writestamp-prefix) "\\(.*\\)" (regexp-quote writestamp-suffix) "$"))) (while (re-search-forward regexp nil t) (replace-match (format-time-string writestamp-format (current-time)) t t nil 1)))))) nil)
次ã«ã¢ãã£ãã¡ã¤ã¹ã¿ã³ãã¨ããç©ãä½ãã¾ããããã¯ããã¡ã¤ã«ãæå¾ã«å¤æ´ãããæå»ãè¨æ¶ããã©ã¤ãã¹ã¿ã³ãã§ããã¾ãã
ä½æ¥ã®æµãã¯ä»¥ä¸ã®éãã§ãã
- ææ³ãã®ï¼ first-change-hookã®å©ç¨
- ãããã¡ãåå¾ã«ä¿åããã¦ä»¥æ¥å§ãã¦ãããã¡ãå¤æ´ãããå ´åã¯ãã¤ãfirst-change-hookã®ãªãã®é¢æ°ãå®è¡ãããã®ã§ãããå©ç¨ãã
- åé¡ç¹ã¯ãã¡ã¤ã«ãä¿åããåã«ããããå¤æ´ãå ããå ´åãæåã®å¤æ´æéãé©ç¨ãããã¨ããç¹ã«ããã¾ãã
(make-local-hook 'first-change-hook) (defvar modifystamp-format "%Y-%m-%d %H:%M" "*Format for writestamps (c.f. 'format-time-string').") (defvar modifystamp-prefix "WRITESTAMP((" "*Unique string identifying start of writestamp.") (defvar modifystamp-suffix "))" "*String that terminates a writestamp.") (defun update-modifystamps () "Find writestamps and replace them with the current time." (interactive) (save-excursion (save-restriction (save-match-data (widen) (goto-char (point-min)) (let ((regexp (concat "^" (regexp-quote writestamp-prefix) "\\(.*\\)" (regexp-quote writestamp-suffix) "$"))) (while (re-search-forward regexp nil t) (replace-match (format-time-string writestamp-format (current-time)) t t nil 1)))))) nil) (add-hook 'first-change-hook 'update-modifystamps)
- ææ³ãã®ï¼ local-write-file-hooksã®å©ç¨
- ãããã¡ãä¿åããã度ã«ä½¿ãããlocal-write-file-hooksãå©ç¨ãããã©ã¤ãã¹ã¿ã³ãã§å®è¡æ¸ã¿
- ãã®ææ³ã®åé¡ç¹ã¯ãã¡ã¤ã«ãä¿åãããã¾ã§æçµæå»ãå¤æ´ãããªãç¹ã«ããã¾ãã
(defun maybe-update-modifystamps () "Call 'update-modifystamps' if the buffer has been modified." (if (buffer-modified-p) (update-modifystamps))) (add-hook 'local-write-file-hooks 'maybe-update-modifystamps)
- ææ³ãã®ï¼ è³¢ãæ¹æ³
- è³¢ãããããã¾ã§å°éããã«ã¯è²ã ã¨èããå¿ è¦ããããã
- è²ããªã¨ãã»ã³ã¹ãå縮ããã¦ãæãã
(make-local-hook 'after-change-functions) (defvar last-change-time nil "Time of last buffer modification.") (make-variable-buffer-local 'last-change-time) (defun remember-change-time (&rest unused) "Store the current time in 'last-change-time'." (setq last-change-time (current-time))) (add-hook 'after-change-functions 'remember-change-time) (defun maybe-update-modifystamps () "Call 'update-modifystamps' if the buffer has been modified." (if last-change-time (update-modifystamps))) (add-hook 'local-write-file-hooks '(lambda () (if last-change-time (update-modifystamps last-change-time)))) (defun update-modifystamps (time) "Find writestamps and replace them with the current time." (interactive) (save-excursion (save-restriction (save-match-data (widen) (goto-char (point-min)) (let ((regexp (concat "^" (regexp-quote writestamp-prefix) "\\(.*\\)" (regexp-quote writestamp-suffix) "$"))) (while (re-search-forward regexp nil t) (replace-match (format-time-string writestamp-format time) t t nil 1)))))) (setq last-change-time nil) nil)
ãã®ç« ã«ãããtipsã«ã¤ãã¦ã¯ä»¥ä¸ã«ã¾ã¨ãã¦ããã¾ãã
- ãããã¡ä¿åã«é¢ããhookã¨ãã¦ã¯write-file-hooks, local-write-file-hooks, write-contents-hooksãªã©ããã
- æååå ã§,\\[insert-date]ã¨ããã®ã¯insert-dateã«å²ãæ¯ããã¦ããã³ãã³ãã表示ãããå ´åã«ä½¿ã
- (interactive '*')ã¯ã«ã¬ã³ããããã¡ãèªã¿è¾¼ã¿å°ç¨ãªãé¢æ°ã®å®è¡ãä¸æ¢ãã
- save-excursionã¯ã«ã¼ã½ã«ã®ä½ç½®ãè¦ã,å¼æ°ã¨ãã¦ã®å¦çãè©ä¾¡ããå¾,å ã®ä½ç½®ã«æ»ã
- save-restrictionã¯ããã¼ã¤ã³ã°(ããbufferã«ããã¦ä¸é¨ã®bufferã®ã¿ãå¦çããå ´åã«ä½¿ã) ç¶æ ãè¦ãã¦ããã¦,æçµçã«å ã®ããã¼ã¤ã³ã°ã«æ»ãã(widen)ã¨ãã¨ä½µç¨ãããäºãå¤ãã
- save-matchã¯æ¤ç´¢çµæãä¿æãã
- save-excursion, save-restriction, save-matchã¯çµå±ã®æ,å¦çå 容ã¯é常ã«è¯ãä¼¼ã¦ãããããã
- Lispã®æ£è¦è¡¨ç¾ã¯ä»ã®è¨èªã¨ã¯å°ãéã. regexp-quoteã使ãã¨ä¾¿å©
5ç« Lispãã¡ã¤ã«
load, require, auto-load, eval-after-load,ãã¤ãã³ã³ãã¤ã«ãªã©ã®èª¬æ
以ä¸ã«å 容ãã¾ã¨ãã¦ããã¾ãã
- load
- æ示çãªload. ã©ããã¦ããã¼ããå¿ è¦ãªæã«ä½¿ã. æ» å¤ã«ä½¿ãããªãã
- require
ã¡ãªã¿ã«ä»¥ä¸ã®å¼ã¯å義ã«ãªãã¾ã
(require 'timestamp) (require 'timestamp "timestamp")
- auto-load
- ãã¡ã¤ã«ã®ãã¼ãããããå¿ è¦ãªæã«ãªãã¾ã§é ãããäºãåºæ¥ããé¢æ°ã¨ä½µç¨ããã
- eval-after-load
- ããã使ããã¨ã§ããã³ã¼ãã®å®è¡ãç¹å®ã®ãã¡ã¤ã«ããã¼ããããã¾ã§é ãããäºãå¯è½ã
ãã¡ã¤ã«ã®ãã¼ãã®é çªã¯ä»¥ä¸ã®éã.ä¾ãã°(require 'test)ã¯ä»¥ä¸ã®ãããªé çªã§æ¤ç´¢ãã,å®è¡ããããtest.elcsããã£ãå ´åã¯test.elã¯èªã¿è¾¼ã¾ããªãã
- test.elcâtest.elâtest
- ãã¡ã¤ã«ã®ãã¼ããããéã«ã¯.el,.elcãªã©ã¨ããæ¡å¼µåã¯ãªãã¹ãä»ããªããã¨
6ç« ãªã¹ã
Listå¦ç. ç¹çãããã¨ã¯ç¡ãã®ã§ã¹ã«ã¼
7 ãã¤ãã¼ã¢ã¼ã
- refill-modeãä¾ã¨ãããã¤ãã¼ã¢ã¼ãã®ä½æãè¡ãã¾ãã
- refill.elã¨ãããã®ãä½æããã(refill.elã£ã¦Emacsã«æ¨æºæè¼ããã¦ããããã¾ãããããã¾ããæã¯ãªãã£ãããããªããã¨)
- ã¡ã¸ã£ã¼ã¢ã¼ãã¨ãã¤ãã¼ã¢ã¼ãã¯ä½µç¨ããã(C-h mãå®è¡ããæã«Topã«åºã¦ããEnabled minor modesãããã«ä»ãªããªã)ããã¤ãã¼ã¢ã¼ãã«ã¯ä¾ãã°ä»¥ä¸ã®ãããªãã®ããããç¡æèã®å
ã«ä½¿ã£ã¦ããã®å¤ãã
- auto-save-mode
- font-lock-mode
- line-number-mode
- ãã¤ãã¼ã¢ã¼ãã«å¿
è¦ãªæ§æè¦ç´ ã¯(defvar refill-mode nil)ã¨(defun refill-mode ...)㨠(defun refill ...)ã®3ã¤ã®ã¿ã ã£ãããã¾ãããã¨ã¯minor-mode-alistã«refill-modeã追å ããã¨ããä½æ¥ãå¿
è¦ã«ãªãã¾ãã
- ãã®ç« ã§ã¯ãã¤ãã¼ã¢ã¼ãã®ä½ãæ¹ã®æµããå§ãã«èª¬æãã(defun refill...)ãä½ã£ã¦ã¯æ¹è¯ãä½ã£ã¦ã¯æ¹è¯ãã¨ããä½æ¥ãè¡ãã¾ãã
- å§ãã«ç°¡åãªæµããè¦ã¦ã¿ã¾ãã
- ååã®ä½æ
- refill-modeã¨ããåã®å¤æ°ãå®ç¾©ããããããããã¡ãã¼ã«ã«ã«ãã
(defvar refill-mode nil "Mode variable for refill minor mode.") (make-variable-buffer-local 'refill-mode)
- refill-modeã®ä½æ
(defun refill-mode (&optional arg) "Refill minor mode." (interactive "P") (setq refill-mode (if (null arg)) (not (refill-mode) (> (prefix-numeric-value arg) 0))) (make-local-hook 'after-change-functions) (if refill-mode (add-hook 'after-change-functions 'refill) (remove-hook 'after-change-functions 'refill)))
- refillé¢æ°ã®ä½æ
(defun refill (start end len) "After a text change, refill the current paragraph." (let ((left (if (zerop len) start (save-excursion (goto-char start) (end-of-line 0) (point)))) (save-excursion (fill-region left end nil nil t)))))
- minor-mode-alistã«refill-modeã追å
- '(refill-mode " Refill")ã«ãããRefillã¯ã¢ã¼ãã©ã¤ã³ã«è¡¨ç¤ºããçãæã®ãã¨ã§ãã空ç½ã§å§ããå¿ è¦ãããã¾ãã
(if (not (assq 'refill-mode minor-mode-alist)) (setq minor-mode-alist (cons '(refill-mode " Refill") minor-mode-alist)))
- refillãprovideãã¦refill.elã®ä½æçµäº
(provide 'refill)
- åºæ¬çã«ã¯ä¸è¨ã®æµãã¨ãªãã¾ãããã¨ã¯refillé¢æ°ãä¿®æ£ããã¨ããä½æ¥ãç¶ããæãã§ããã
- éä¸skipãã¦last verã®refillé¢æ°ã¨refillé¢æ°å ã§å¿ è¦ã¨ãªãé¢æ°ã®å®è£ é¨åãè¼ã£ãã¦ããã¾ãã
- skip-chars-forwardã¯ä¾¿å©ã§ãã¨ã
(defun before-2nd-word-p (pos) "Does Pos lie before the second word on the line?" (save-excursion (goto-char pos) (beginning-of-line) (skip-syntax-forward (concat "^ " (char-to-string (char-syntax ?\n)))) (skip-syntax-forward " ") (< pos (point)))) (defun same-line-p (start end) "Are START and END on the same line?" (save-excursion (goto-char start) (end-of-line) (<= (point)))) (defun short-line-p (pos) "Does line containing POS stya within 'fill-column?" (save-excursion (goto-char pos) (end-of-line) (<= (current-column) fill-column))) ;; ver last refill
æçµçãªrefillé¢æ°ã¯ä»¥ä¸ã®ãããªæãã«ãªãã¾ãããã
(defun refill (start end len) "After a text change, refill the current paragraph." (let ((left (if (or (zerop len) (not (before-2nd-word-p start))) start (save-excursion (max (progn (goto-char start) (end-of-line 0) (point)) (progn (goto-char start) (backward-paragraph 1) (point))))))) (if (or (and (zerop len) (same-line-p start end) (short-line-p end)) (and (eq (char-syntax (preceding-char)) ?\ ) (looking-at "\\s *$"))) nil (save-excursion (fill-region left end nil nil t)))))
ã¾ããã¤ãã¼ã¢ã¼ãã®æµãã¨ã¡ãã£ã¨ããtipsã®ç´¹ä», ããã«é¢æ°ã®ä¿®æ£ä½æ¥ã®æµããè¦ãã¨ããæãã®å
容ã§ããã
8ç« è©ä¾¡ã¨ã¨ã©ã¼å¦ç
7ç« ã®å 容ãè¸ã¾ãsave-excursionãæ¹è¯ããã¨ããç« ããã¯ã解説ããã¯ããå©ç¨ããlimited-save-excursionã®å®è£ +limited.elã®ä½æã¨ããå 容
ãã¯ãç¥ã£ã¦ããã°ååã®å 容ã¯ã¹ã«ã¼ãã¦ãå¯è½ãæçµçã«ã¯ä»¥ä¸ã®ãããªlimited.elãåºæ¥ä¸ãã£ã¦ããã å¾ã¯7ç« ã«ãããsave-excursionã(require 'limited)ãå®è¡ãlimited-excursionã«å¤æ´ããäºã§refill-modeãå®æãã
ã¡ãªã¿ã«limited-save-excursionãã¯ãã«åºã¦ããunwind-protectã®æå³ã¯éä¸ã§ä¾å¤å¦çãããã¦ã(goto-char ,orig-point-symbol)ã¯å®è¡ãããã¨ããæå³ã
>|lisp||
;; limited.el
(defmacro limited-save-excursion (&rest subexprs)
"Like save-excursion, but only restores point."
(let ((orig-point-symbol (make-symbol "orig-point")))
`(let ((,orig-point-symbol (point-marker)))
(unwind-protect
(progn ,@subexprs)
(goto-char ,orig-point-symbol)))))
(provide 'limited)
|
- .emacsã«ä»¥ä¸ã®æ§ãªå 容ãå ãã¦ããã°refillãrefill-modeãèµ·åããã¾ã§ãã¼ããããªããªãã¨ã®äº
(autoload 'refill-mocde "refill" "Refill minor mode." t)
9ç« ã¡ã¸ã£ã¼ã¢ã¼ã
quip-modeã¨ãããã®ãä½ãããã¡ã¸ã£ã¼ã¢ã¼ãã®æ§é ã®èª¬æ + ããã¼ã¤ã³ã°ã®èª¬æ + æ´¾çã¢ã¼ãã®èª¬æ(derived !!)ã¨ãã£ãæãã§ããã
- quip-modeã¨ããã®ã¯åè¨ãç·¨éããããã®ã¢ã¼ãã®ãã¨
ã¡ã¸ã£ã¼ã¢ã¼ãã®æ§é ã¯ä»¥ä¸ã®ãããªæãã§ããã¨ããããquip-modeãä½ãäºãä¾ã¨ãã¾ãã
- ã¡ã¸ã£ã¼ã¢ã¼ãã®ä½ãæ¹ã®æµã
- ååãèãã
- quip.elã¨ãããã¡ã¤ã«ãä½ã
- quip-mode-hookã¨ããååã®å¤æ°ã®å®ç¾©
- å¿ è¦ãªãåºæã®ãã¼ããããå®ç¾©ãã
- å¿ è¦ãªãã·ã³ã¿ãã¯ã¹ãã¼ãã«ãå®ç¾©ãã
- å¿ è¦ãªãã¢ã¼ãã®ç¥ç§°ãã¼ãã«ãå®ç¾©ãã
- quip-modeã¨ããã³ãã³ãã®å®ç¾©ããã
- kill-all-local-variablesã§å ¨ã¦ã®ãããã¡ãã¼ã«ã«å¤æ°ãåãé¤ã
- ã¡ã¸ã£ã¼ã¢ã¼ããqup-modeã«ãã
- ã¢ã¼ãã表ãæååãmode-nameã«è¨å®ãã
- å¿ è¦ãªãã¢ã¼ãåºæã®ãã¼ããããã¤ã³ã¹ãã¼ã«ãã
- ã¦ã¼ã¶ã¼ã®ããã¯é¢æ°ãå®è¡ãã
- quipãprovideãã
æ¦è¦ã¯ä»¥ä¸ã®ãããªæãã§ã. ã¨ããããå§ãã¯æä½éã®è¨å®ã«ãã¦ããã¾ãã
(defvar quip-mode-hook nil "*List of functions to call when entering Quip mode.") (defun quip-mode() "Major mode for editing Quip files." (interactive) (kill-all-local-variables) (setq major-mode 'quip-mode) (setq mode-name "Quip") (run-hook 'quip-mode-hook)) (provide 'quip)
次ã«quip-modeã«ããã段è½ã®å®ç¾©ãè¡ãã¾ãã
(make-local-variable 'paragraph-start) (make-local-variable 'paragraph-separate) (make-local-variable 'page-delimiter) (setq paragraph-start "%%\\|[ \t\n^L]") (setq paragraph-separate "%%$\\|[ \t\n^L]*$") (setq page-delimiter "^%%$")
- 次ã«ãã¼ãããã®è¨å®ãè¡ãã¾ãã
- ã¡ã¸ã£ã¼ã¢ã¼ãã«ããããã¼è¨å®ãããéã«,ãã¾ãè¨å®ãããã®ããªãå ´åã«ã¯make-sparse-keymapãå©ç¨ãã¾ãã
- å®å ¨ãªãã¼ããããå¿ è¦ãªå ´åã«ã¯make-keymapãå©ç¨ãã¾ããmake-keymapã¯ããã¼ã¹ä»¥ä¸ã®è¨å®ãããå ´åã«æ¼ãã¦ä½¿ãã¹ãã¨ã®ãã¨ã
å§ãã«ãã¼ãããã®è¨å®ãè¡ãåã«Quipã¢ã¼ãç¨ã«ã³ãã³ããdefaliasãã¾ãã
(defalias 'backward-quip 'backward-page) (defalias 'forward-quip 'forward-page) (defalias 'narrow-to-quip 'narrow-to-page) (defalias 'what-quip 'what-page)
次ã«ãã¼ãããã®è¨å®ãæãã¨ãã¦ã¯ä»¥ä¸ã®éã
(if quip-mode-map nil (setq quip-mode-map (make-sparse-keymap)) (define-key quip-mode "\C-x[" 'backward-quip) (define-key quip-mode "\C-x]" 'forward-quip) (define-key quip-mode "\C-xnq" 'narrow-to-quip))
- åå¨ããquipã®æ°ãæ°ããããã®ã³ãã³ãã®å®ç¾©
- ããã§ã¯ããã¼ã¤ã³ã°ã«ã¤ãã¦èããå¿ è¦ãããã¾ããããã¼ã¤ã³ã°ã¨ã¯ãããã¡ã®ç·¨éãªã©ãããéã«ä¸é¨ã®ãããã¡ã®ã¿ã«ç¹åãã¦è¡¨ç¤ºããããã¨ãã«ä½¿ãã¾ãã
- quipã®æ°ãæ°ããããã«ã¯ç¾å¨ã®ãããã¡ãããã¼ã¤ã³ã°ããã¦ããå ´åã«ã対å¿ããã³ã¼ããæ¸ãå¿ è¦ãããã¾ãã
以ä¸ã¯çµæ§é »ç¹ã«ä½¿ãããã³ã¼ãããã£ã¦ããäºã¯ç¾å¨ã®ãããã¡ã®ããã¼ã¤ã³ã°ã®ç¶æ ãè¦ãã¦ããã(widen)ã§å ¨ä½ãããã¡ã«ã¢ã¯ã»ã¹åºæ¥ãããã«ããå¾ãå度å ã®ããã¼ã¤ã³ã°ã®ç¶æ ã«æ»ãã¨è¨ã£ããã¨ããã¦ãã¾ãã
(save-restriction (widen) ...)
- ã³ã¼ãã®å®è£ ã¯ä»¥ä¸ã®ãããªæãã«ãªãã¾ã
(defun count-quips() "Count the quips in the buffer." (interactive) (save-excursion (save-restriction (widen) (goto-char (point-min)) (count-matches "^%%$"))))
- ã¨ã¾ãããã¾ã§è²ã ã¨å®è£ ãã¦ãã訳ã§ãããquip-modeã¯å®éã®ætext-modeã«+αå¦çãä»ãå ããæããªã®ã§ããå®å ¨ã«text-modeã®å 容ãè¸è¥²ããããã«ã¯syntax-tableãªã©ãcopyããå¿ è¦ãããã¾ã
- define-derived-modeã¨ããæ¢ã«å®ç¾©ãããã¢ã¼ãããæ°ããã¢ã¼ããæ´¾çããäºãã§ããããã±ã¼ã¸ããã(derivedããã±ã¼ã¸)ï¼ï¼ ããã使ãäºã«ãããtext-modeã®å 容ãç¶æããã¾ã¾quip-modeãä½ããã¨ãã§ãã¾ããå 容ã¯ä»¥ä¸ã®éã
quip.el(derivedããã±ã¼ã¸ã使ã£ãä¾)
(require 'derived) (define-derived-mode quip-mode text-mode "Quip" "Major mode for editing Quip files. Special commands: \\quip-mode-map" (make-local-variable 'paragraph-separate) (make-local-variable 'paragraph-start) (make-local-variable 'page-delimiter) (setq paragraph-start "%%\\|[ \t\n\^L]") (setq paragraph-separate "%%\\|[ \t\^L]*$") (setq page-delimiter "^%%$")) ;; defalias parts (defalias 'backward-quip 'backward-page) (defalias 'forward-quip 'forward-page) (defalias 'narrow-to-quip 'narrow-to-page) (defalias 'what-quip 'what-page) ;; function definition parts (defun count-quips() "Count the quips in the buffer." (interactive) (save-excursion (save-restriction (widen) (goto-char (point-min)) (count-matches "^%%$")))) ;; mapping parts (if quip-mode-map nil (setq quip-mode-map (make-sparse-keymap))) (define-key quip-mode-map "\C-x[" 'backward-quip) (define-key quip-mode-map "\C-x]" 'forward-quip) (define-key quip-mode-map "\C-xnq" 'narrow-to-quip) (define-key quip-mode-map "\C-cw" 'what-quip)) (provide 'quip)
10ç« ç·åçãªä¾
ã¯ãã¹ã¯ã¼ãããºã«ãç·¨éããããã®ã¡ã¸ã£ã¼ã¢ã¼ãã®ä½æ
- 9ç« ã®å¿ç¨ã¨ãã£ãæãã§ãããããçµæ§é·ãã®ã¡ã¸ã£ã¼ã¢ã¼ãã®ä½æ + è²ã ãªãã¯ããã¯ã®è§£èª¬ã¨ãã£ãæããããã¦ã¹ã³ãã³ãã¨ã(interactive "@e")ã¨ãéåæegrepã¨ããªãã¨ã
- ã½ã¼ã¹æã¡è¾¼ã¿ã¯é·ããã§æ¢ãã¾ããï½ãã¾ãæ¬ã«ããã³ã¼ããããã¾çºã¾ã£ã¦ããªãã£ã¦ã®ãçç±ã«ãªãã®ã§ããããã
ã¨ã¾ããããªã¨ãã§ããããªããªãããæãã®å
容ã Common Lispã¨ãSchemeã¨ãç¥ã£ã¦ããªãåé¡ãªãåããã¨æãã¾ãããLispãã®ãã®ãç¥ããªãå ´åããé£ããã®å
容ããããã¾ãããã¾ãå
容ãå¤ããã§çµæ§å¤ãæãã®ã³ã¼ããªãã§ããã©(defgroupã¨ããªãããã)ä½ãããå½¹ã«ç«ã¤ã®ã§ã¯ãªããã¨ã