emacs_lisp

Table of Contents

;;An Introduction to Programming in Emacs Lisp
;;********************************************
;;非プログラマーのための入門本。

1 Preface

  • GNU Emacs Lisp Reference Manualが次に読むべき本としてある。
  • M-.:find tag command C-h t:tutorial
  • M-C-\’ (‘indent-region’)などで<meta>keyが使えなければ代りに<esc>
    を押して離す。

2 1 .List Processing

2.1 Lisp Lists


'(rose violet daisy buttercup)

(+ 2 2)

'(this list has (a list inside of it))

2.1.1 Lisp Atoms

atom=分割できないものを言いあらわす。スペースで区切られ、括弧に接する
ことはできる。アトムとリストの表現をsymbolic expressionという。

There are many kinds of atom in nature but only a few in Lisp:
for example, "numbers", such as 37, 511, or 1729, and"symbols", such
as `+', `foo', or `forward-line'.

Text between double quotation marks–even sentences or paragraphs–is also
an atom. Here is an example:

'(this list includes "text between quotation marks.")

`''(quote)
これがなかった時、エラーでなければ最初のアトムはコマンド(関数)である。

2.1.2 white space in Lists

white space 量は問題にならない。

2.1.3 Gnu emacs helps you typing

  • <tab>:automatically indent,
  • M-C-\ :indent the region

2.2 Run a Program

  • quote,error, or do something
  • リストでないもの(変数)
  • +のようなsymbolはplusなどのように名前は色々あっても働きは1つ(emacsに
    属する定義)。関数はその定義、働きを変えうる。
  • emacs中‘C-x C-e’ でevaluateできる

2.3 Generate an Error Message

  • エラーメッセージはemacs-debuggerで生じqで抜ける.
  • 例 (fill-column) – void function error:関数定義が見つからない。
---------- Buffer: *Backtrace* ----------
 Debugger entered--Lisp error: (void-function fill-column)
  (fill-column)
  eval((fill-column))
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp)
---------- Buffer: *Backtrace* ----------
  • (+ 2 2) で+の直後でC-x C-eすると – void variabke error

2.4 Lisp Interpreterは

  • quoteがあったら単なるリストを与えそれがなかったらリストの最初の要
    素が関数定義か見てそうならinstruction(指図)する。そうでなければエ
    ラーメッセージ。
  • complications
    上記に加えて括弧も引用もないシンボルを変数とみなして評価できる
    special form と呼ばれる関数があり特殊な働き方をする。(defunなど)
    括弧内の最深部から、また左から順に実行する。
  • Byte-compiling
    例えばbyte-compile-fileコマンドなどで.elcのコード(読めるものは.el
    コード)とすることができてemacs/lisp directoryに置く。

2.5 evaluation

  • 式を評価し終えると、Lispインタープリタは、関数定義で与えられた命令列
    をコンピュータが実行した結果を返す(return)のが一般的。その際にカー
    ソルを動かすとかファイルをコピーするとか、他の事をするかもしれない。
    (side efefct)
  • 内部のリストを評価して値を返し、外のリストがこれを使うという順番。
    (+ 2 (+ 3 3))

2.6 variables

symbolは値を持つことも(変数)関数定義を持つこともできる。
fill-column ->‘C-x C-e' でこの変数の値(数字)が出る。

2.7 Arguments

(+ 2 2)で2と2は+の引数

2.7.1 message function

(message "The name of this buffer is: %s." (buffer-name))
"The name of this buffer is: scratch."
echo areaに"This…"と出るのはmessage return値がそれだからで、他のプロ
グラムのside effectではquote(")なしで出る。

(message "The value of fill-column is %d." fill-column)
"The value of fill-column is 70."

(message "There are %d %s in the office!"
(- fill-column 14) "pink elephants")
"There are 56 pink elephants in the office!"

(message "He saw %d %s"
(- fill-column 32)
(concat "red "
(substring
"The quick brown foxes jumped." 16 21)
" leaping."))
"He saw 38 red foxes leaping."

2.8 set,setq

  • symbol flowersに(set 'flowers '(rose violet daisy battercup)) で
    sideeffect でflowersが リストと結合して変数として見られうる。LISP関
    数はエラーがなければ値を返すがもし1になるようにデザインされていたら
    side effectのみ有する。
  • setqで引用が不要かつ複数の変数に値をセットできる。(setq trees '(pine
    fir oak maple) harbivores '(gazella antelope zebra))
  • counting
    (setq counter 0) ;initiator
    (setq counter (+ counter 1)) ;increment
    counter ;counter

3 2 . Practicing Evaluation

3.1 How to Evaluate

  • C-x C-e
  • C-u C-x C-eで結果を直後に表示

3.2 Buffer Names

  • (buffer-name) ;— 名前だけ
  • (buffer-file-name) ;–save先などのファイル

3.3 Getting Buffer

  • (current-buffer) ;—バッファそのものだが表示は名前だけ
  • (other-buffer) ;—非表示の中で最近のものを選ぶ

3.4 Swithing Buffers

  • C-x b = interactive function (switch-to-buffer (buffer-name))をお
    こす。
  • (switch-to-buffer (other-buffer)) 非表示
  • (switch-to-buffer (other-buffer (current-buffer) t) 表示している
    ものも含めてならこうする

3.5 Buffer size and the Location of point

  • (buffer-size)
  • (point)
  • (point-min) ;; minimum permissible value of point : narrowingなけ
    れば1 (point-max)

4 3. How to write function definitions

4.1 primitive functions

いくらかの関数はC言語でかかれているが違いを気にせず同じように扱う。

4.2 The `defun' Special form

defunに続いて
関数定義が結びつけられたシンボル名
引数リスト、なければ()
Documentation
関数をインタラクティブにする表現(M-x 関数名やキーコードを使えるようにする)オプショナル
本体

(defun multiply-by-seven (number)
     "Multiply NUMBER by seven."
     (* 7 number))

4.3  インストールする(C-x C-e)

(multipiy-by-seven 3) C-x C-e ->21

`C-h f' (`describe-function') and then the name of the function,
`multiply-by-seven'でdocumentation

4.4 An Interactive `multiply-by-seven' , An overview

(defun multiply-by-seven (number)       ; Interactive version.
   "Multiply NUMBER by seven."
   (interactive "p")
   (message "The result is %d" (* 7 number)))
  • C-x C-eでインストールしてC-u 数字(引数) M-x multiply-by-sevenで実行
    できる。
  • (interactive p)のpはprefix引数を関数が取る事を意味する。
  • message を先頭要素とする式 を評価したときには、 messageが返した値が
    エコー領域に表示されるが(""つき)、関数内で用いた場合には、副作用と
    してmessage が二重引用符なしでテキストを 表示する.
  • より一般的には(例:forward-sentence:M-eで)C-u 3 M-x forward-sentence
    or C-u 3 M-e とする。

4.5 Different Options for `interactive

(interactive "p\ncZap to char:")
  • p:prefix数として引数を関数にわたす。
  • c:character(ここまで削除すべき)名を関数に渡す。
  • 各部は\nで区切られている。
  • (interactive "r") (defun 関数名 (buffer start end) "説明文…"
(interactive "BAppend to buffer: \nr")関数の本体...

(interactive "P\nbFrobnicate buffer: ")
P:raw command prefix, bFrobnivate buffer:enter the name of an
 existing buffer 

(interactive "bBuffer to rename: \nsRename buffer %s to: ")
など

4.6 Install code Permanently

1 .emacsに関数定義として
2 ファイル中に入れてload関数を使う。
3 site-init-el file中に置く

4.7 let

local変数(let expressionの中でのみ値を保持する)の名前を作る

(let ((zebra 'stripes)
      (tiger 'fierce))
  (message "One kind of animal has %s and another is %s."
           zebra tiger))

"One kind of animal has stripes and another is fierce."

(let ((birch 3)
      pine
      fir
      (oak 'some))
  (message
   "Here are %d variables with %s, %s, and %s value."
   birch pine fir oak))

"Here are 3 variables with nil, nil, and some value."

4.8 The `if' special form

(defun type-of-animal (characteristic)
   "Print message in echo area depending on CHARACTERISTIC.
 If the CHARACTERISTIC is the symbol `fierce',
 then warn of a tiger."
   (if (equal characteristic 'fierce)
       (message "It's a tiger!")))

(type-of-animal 'fierce)
(type-of-animal 'zebra)

(defun type-of-animal (characteristic)  ; Second version.
   "Print message in echo area depending on CHARACTERISTIC.
 If the CHARACTERISTIC is the symbol `fierce',
 then warn of a tiger;
 else say it's not fierce."
   (if (equal characteristic 'fierce)
       (message "It's a tiger!")
     (message "It's not fierce!")))

(type-of-animal 'fierce)
(type-of-animal 'zebra)

4.9 Truth and Falsehood in Emacs Lisp

faise はnil,他のすべてはtrue.
emacs lisp でnilはempty listかfalseを意味する。

(if 4
    'true
  'false)

(if nil
    'true
  'false)

(> 5 4)
(> 4 5)

4.10 Save excursion

  • 3rd and final special form

4.10.1 point and mark

  • pointはカーソルの現位置、 markはバッファ上の他の位置。 `C-x C-x'で 
    ポイントとマークの入れ替え (`exchange-point-and-mark')できる。他のマー
    クをセットすると前のものはmark ringに入る。
  • セーブされたマーク (mark ringに入っている)にjumpするには`C-u
    C-<SPC>'をone or more times.何度かタイプする。
  • markとpointの間はregion
    center-region
    count-lines-region
    kill-region
    print-region
  • save-excursionはmarkとpoint位置をセーブしてリストアする

4.10.2 Template for a ‘save-excursion’ Expression

4.11 3.11 Review

In the last few chapters we have introduced a fair number of functions
and special forms. Here they are described in brief, along with a few
similar functions that have not been mentioned yet.

`eval-last-sexp'
Evaluate the last symbolic expression before the current location
of point. The value is printed in the echo area unless the
function is invoked with an argument; in that case, the output is
printed in the current buffer. This command is normally bound to
`C-x C-e'.

`defun'
Define function. This special form has up to five parts: the name,
a template for the arguments that will be passed to the function,
documentation, an optional interactive declaration, and the body
of the definition.

For example, in an early version of Emacs, the function definition
was as follows. (It is slightly more complex now that it seeks
the first non-whitespace character rather than the first visible
character.)

(defun back-to-indentation ()
   "Move point to first visible character on line."
   (interactive)
   (beginning-of-line 1)
   (skip-chars-forward " \t"))

`interactive'
Declare to the interpreter that the function can be used
interactively. This special form may be followed by a string with
one or more parts that pass the information to the arguments of the
function, in sequence. These parts may also tell the interpreter
to prompt for information. Parts of the string are separated by
newlines, .

Common code characters are:

`b' The name of an existing buffer.

`f' The name of an existing file.

`p' The numeric prefix argument. (Note that this `p' is lower
case.)

`r' Point and the mark, as two numeric arguments, smallest first.
This is the only code letter that specifies two successive
arguments rather than one.

*Note Code Characters for `interactive': (elisp)Interactive Codes,
for a complete list of code characters.

`let'
Declare that a list of variables is for use within the body of the
`let' and give them an initial value, either `nil' or a specified
value; then evaluate the rest of the expressions in the body of
the `let' and return the value of the last one. Inside the body
of the `let', the Lisp interpreter does not see the values of the
variables of the same names that are bound outside of the `let'.

For example,

(let ((foo (buffer-name))
       (bar (buffer-size)))
   (message
    "This buffer is %s and has %d characters."
    foo bar))

`save-excursion'
Record the values of point and mark and the current buffer before
evaluating the body of this special form. Restore the values of
point and mark and buffer afterward.

For example,

 (message "We are %d characters into this buffer."        
                   (- (point)                             
                      (save-excursion                     
                        (goto-char (point-min)) (point))))
                                                          

`if'
Evaluate the first argument to the function; if it is true,
evaluate the second argument; else evaluate the third argument, if
there is one.

The `if' special form is called a "conditional". There are other
conditionals in Emacs Lisp, but `if' is perhaps the most commonly
used.

For example,

  (if (= 22 emacs-major-version)                     
              (message "This is version 22 Emacs")   
            (message "This is not version 22 Emacs"))
                                                     

`<'
`>'
`<='
`>='
The `<' function tests whether its first argument is smaller than
its second argument. A corresponding function, `>', tests whether
the first argument is greater than the second. Likewise, `<='
tests whether the first argument is less than or equal to the
second and `>=' tests whether the first argument is greater than
or equal to the second. In all cases, both arguments must be
numbers or markers (markers indicate positions in buffers).

`='
The `=' function tests whether two arguments, both numbers or
markers, are equal.

`equal'
`eq'
Test whether two objects are the same. `equal' uses one meaning
of the word `same' and `eq' uses another: `equal' returns true if
the two objects have a similar structure and contents, such as two
copies of the same book. On the other hand, `eq', returns true if
both arguments are actually the same object.

`string<'
`string-lessp'
`string='
`string-equal'
The `string-lessp' function tests whether its first argument is
smaller than the second argument. A shorter, alternative name for
the same function (a `defalias') is `string<'.

The arguments to `string-lessp' must be strings or symbols; the
ordering is lexicographic, so case is significant. The print
names of symbols are used instead of the symbols themselves.

An empty string, `""', a string with no characters in it, is
smaller than any string of characters.

`string-equal' provides the corresponding test for equality. Its
shorter, alternative name is `string='. There are no string test
functions that correspond to >, `>=', or `<='.

`message'
Print a message in the echo area. The first argument is a string
that can contain `%s', `%d', or `%c' to print the value of
arguments that follow the string. The argument used by `%s' must
be a string or a symbol; the argument used by `%d' must be a
number. The argument used by `%c' must be an ASCII code number;
it will be printed as the character with that ASCII code.
(Various other %-sequences have not been mentioned.)

`setq'
`set'
The `setq' function sets the value of its first argument to the
value of the second argument. The first argument is automatically
quoted by `setq'. It does the same for succeeding pairs of
arguments. Another function, `set', takes only two arguments and
evaluates both of them before setting the value returned by its
first argument to the value returned by its second argument.

`buffer-name'
Without an argument, return the name of the buffer, as a string.

`buffer-file-name'
Without an argument, return the name of the file the buffer is
visiting.

`current-buffer'
Return the buffer in which Emacs is active; it may not be the
buffer that is visible on the screen.

`other-buffer'
Return the most recently selected buffer (other than the buffer
passed to `other-buffer' as an argument and other than the current
buffer).

`switch-to-buffer'
Select a buffer for Emacs to be active in and display it in the
current window so users can look at it. Usually bound to `C-x b'.

`set-buffer'
Switch Emacs' attention to a buffer on which programs will run.
Don't alter what the window is showing.

`buffer-size'
Return the number of characters in the current buffer.

`point'
Return the value of the current position of the cursor, as an
integer counting the number of characters from the beginning of the
buffer.

`point-min'
Return the minimum permissible value of point in the current
buffer. This is 1, unless narrowing is in effect.

`point-max'
Return the value of the maximum permissible value of point in the
current buffer. This is the end of the buffer, unless narrowing
is in effect.

5 4. A few Buffer-Related Functions

5.1 Finding More Information

  • ここは多分使わない。
  • find-tag を使うには‘M-.’
  • To create a ‘TAGS’ file in a specific directory, switch to that
    directory in Emacs using ‘M-x cd’ command, or list the directory
    with ‘C-x d’ (‘dired’). Then run the compile command,
    with‘etags *.el’ as the command to execute:
  • M-x compile RET etags *.el RET

5.2 A Simplified ‘beginning-of-buffer’ Definition

(defun simplified-beginning-of-buffer ()
   "Move point to the beginning of the buffer;
 leave mark at previous position."
   (interactive)
   (push-mark)
   (goto-char (point-min)))
  • 関数名、引数リスト、ドキュメント、インタラクティブ、本体より成る。
    本物はM-< にバインド

5.3 The Definition of `mark-whole-buffer

5.3.1 Emacs 22

(defun mark-whole-buffer ()
   "Put point at beginning and mark at end of buffer.
 You probably should not use this function in Lisp programs;
 it is usually a mistake for a Lisp function to use any subroutine
 that uses or sets the mark."
   (interactive)
   (push-mark (point))
   (push-mark (point-max) nil t)
   (goto-char (point-min)))
  • push-mark argumentはoptional(実は)
  • push-mark(point-max)のadditional arguments
    nil :Mark setと言うメッセージを表示。
    t :Transient mark modeが有効ならhighlited regionが見えるようにする.
    C-x hとバインド

5.4 The definition of `append-to-buffer'

  • `insert-bufer-substring'関数を使う。(この関数の設定が主)
(defun append-to-buffer (buffer start end)
       "Append to specified buffer the text of the region.
     It is inserted into that buffer before its point.

     When calling from a program, give three arguments:
     BUFFER (or buffer name), START and END.
     START and END specify the portion of the current buffer to be copied."
       (interactive
        (list (read-buffer "Append to buffer: " (other-buffer
                                                 (current-buffer) t))
              (region-beginning) (region-end)))
       (let ((oldbuf (current-buffer)))
         (save-excursion
           (let* ((append-to (get-buffer-create buffer))
                  (windows (get-buffer-window-list append-to t t))
                  point)
             (set-buffer append-to)
             (setq point (point))
             (barf-if-buffer-read-only)
             (insert-buffer-substring oldbuf start end)
             (dolist (window windows)
               (when (= (window-point window) point)
                 (set-window-point window (point))))))))
  • (interactive "BApppend to buffer:\nr")であったものを(list
    (read-buffer "—) (region-beginning) (region-end)とした。
  • read-bufferは"Append to buffer:"プロンプトの後に読むべきバッファ名、
    その値:(other-buffer(current-buffer) t)を読む。
  • プロンプト名で、現バッファ以外の、見えているものを含むものを読む(t)
    ということか。
  • (oldbuf (current-buffer))oldbuf値はcurrent-bufferとなり、ここからコピー。
  • save-excursionのbodyはただ1つのexpression let*を含む。
  • let*は各変数を順番に割り当てる。先に値を与えられた変数が後で使われる
    (3つ) let*の本体はset-bufferとinsert-buffer-substring(よそからこ
    こへコピー)を行う。

4.5 Review
========

Here is a brief summary of the various functions discussed in this
chapter.

`describe-function'
`describe-variable'
Print the documentation for a function or variable.
Conventionally bound to `C-h f' and `C-h v'.

`find-tag'
Find the file containing the source for a function or variable and
switch buffers to it, positioning point at the beginning of the
item. Conventionally bound to `M-.' (that's a period following the
<META> key).

`save-excursion'
Save the location of point and mark and restore their values after
the arguments to `save-excursion' have been evaluated. Also,
remember the current buffer and return to it.

`push-mark'
Set mark at a location and record the value of the previous mark
on the mark ring. The mark is a location in the buffer that will
keep its relative position even if text is added to or removed
from the buffer.

`goto-char'
Set point to the location specified by the value of the argument,
which can be a number, a marker, or an expression that returns
the number of a position, such as `(point-min)'.

`insert-buffer-substring'
Copy a region of text from a buffer that is passed to the function
as an argument and insert the region into the current buffer.

`mark-whole-buffer'
Mark the whole buffer as a region. Normally bound to `C-x h'.

`set-buffer'
Switch the attention of Emacs to another buffer, but do not change
the window being displayed. Used when the program rather than a
human is to work on a different buffer.

`get-buffer-create'
`get-buffer'
Find a named buffer or create one if a buffer of that name does not
exist. The `get-buffer' function returns `nil' if the named
buffer does not exist.

6 5 A Few More Complex Functions

6.1 The definition of `copy-to-buffer'(追加でなく置き換え)

  • The body of `copy-to-buffer' looks like this,
     ...                                                       
             (interactive "BCopy to buffer: \nr")             
             (let ((oldbuf (current-buffer)))                  
               (with-current-buffer (get-buffer-create buffer) 
                 (barf-if-buffer-read-only)                    
                 (erase-buffer)                                
                 (save-excursion                               
                 (insert-buffer-substring oldbuf start end)))))
  • バッファ(プロンプト)とリジョンを引数にとる。
  • (with-current-buffer という新しい関数はまず(B名のバッファを作りこれ
    について)
    (ROならエラーをだし)
    (消去し)
    (今の場所を確保し)
    (oldbufという名の今のバッファのレジョンを挿入する))

6.2 The definition of `insert-bufer' (逆向き、別バッファから現バッファへ)

  • 以前のコード
(defun insert-buffer (buffer)
   "Insert after point the contents of BUFFER.
 Puts mark after the inserted text.
 BUFFER may be a buffer or a buffer name."
   (interactive "*bInsert buffer: ")
   (or (bufferp buffer)
       (setq buffer (get-buffer buffer)))
   (let (start end newmark);各変数をnilにする
     (save-excursion
       (save-excursion
         (set-buffer buffer)
         (setq start (point-min) end (point-max)))
       (insert-buffer-substring buffer start end)
       (setq newmark (point)))
     (push-mark newmark)))
  • *は現バッファがROの時警告を出す。
  • 小文字のbは引数は既存である事(バッファあるいはバッファ名が既に在るこ)と
    を示す。
  • (or 部は
    (if (not (bufferp buffer)) ; if-part
    (setq buffer (get-buffer buffer))) ; then-part 
    と同じ
  • 内部save-excursion
    (save-excursion (set-buffer buffer)
    (setq start (point-min) end (point-max)))
  • emacsにコピー元バッファを注視させて、そのpoint-minとpoint-maxをstart
    とendとする。これが終わったら現ファイルの元の場所に戻る。
  • そして(insert-buffer-substring buffer start end)挿入する
  • がstartとendはまだコピー元のものであるから外部save-excursion
    (save-excursion (INNER-`save-excursion'-EXPRESSION
    (GO-TO-NEW-BUFFER-AND-SET-`start'-AND-`end')
    (insert-buffer-substring buffer start end) (setq newmark (point)))
  • 現バッファにコピー元バッファの全部を挿入し、挿入部の最後に(push-mark

newmwrk) で newmarkをセットして(その前のマークはC-u C-spcで参照できる)
元のバッファのpoint and markに戻る。

6.3 New Body for `insert-Buffer'(confusing)

  • 以前のものよりconfusing
     (defun insert-buffer (buffer)                          
            "Insert buffer after point"                     
            (interactive "*bInsert buffer: ")               
            (push-mark                                      
             (save-excursion                                
               (insert-buffer-substring (get-buffer buffer))
               (point)))                                    
               nil)                                         
                                                            
  • get-buffer関数は支給された名前のバッファを返す(get-buffer-createでな
    い)。返された存在するバッファすべてが(他に指定がない以上)insertされ
    る。バッファが挿入された場所はpush-markで記録される。そして関数はnil
    を返す。(insert-buffer functionはside-effectを生じるためだけにあり、
    値を何も返さない)

6.4 Complete definition of beginning-of-buffer

  • M-< or C-u 7 M-< (buufer中70%の所にカーソル移動)

  – <esc>-< しか働かないかも

  • optional argument(&optional=key word)
    `beginning-of-buffer' with Argument
  • The complete `beginning-of-buffer'
        (defun beginning-of-buffer (&optional arg)
           "Move point to the beginning of the buffer;
         leave mark at previous position.
         With \\[universal-argument] prefix,
         do not set mark at previous position.
         With numeric arg N,
         put point N/10 of the way from the beginning.
    
         If the buffer is narrowed,
         this command uses the beginning and size
         of the accessible part of the buffer.
    
         Don't use this command in Lisp programs!
         \(goto-char (point-min)) is faster
         and avoids clobbering the mark."
           (interactive "P")
           (or (consp arg)
               (and transient-mark-mode mark-active)
               (push-mark))
           (let ((size (- (point-max) (point-min))))
             (goto-char (if (and arg (not (consp arg)))
                            (+ (point-min)
                               (if (> size 10000)
                                   ;; Avoid overflow for large buffer sizes!
                                   (* (prefix-numeric-value arg)
                                      (/ size 10))
    x                             (/ (+ 10 (* size (prefix-numeric-value arg)))
                                    10)))
                          (point-min))))
           (if (and arg (not (consp arg))) (forward-line 1)))
    
  • "P" はinteractive表現でC-u 数字で、(もし数字でないものをタイプしたら
    defaults to a cons cell with a 4)
  • 大きなバッファサイズでは
    (goto-char (* (prefix-numeric-value arg)
    (/ size 10)))
  • 小さい時は
    (/ (+ 10 (* size (prefix-numeric-value arg))) 10))
    のようにする。
  • \\[universal-argument]は lisp interpreterに[…]が何と結ばれていよ
    うが、universal-argumentと置換するよう教える。(C-u )
  • (if (and arg (not (consp arg))) (forward-line 1))は(if
    arg(forward-line 1)の代替
  • (not (consp arg))部はC-uのあとが数字でないとき、ということは raw
    prefix argument が 単にcons cellであるとき、2行目に行かせる事をしな
    いということ。

6.5 5.4 Review

`or'
順次各引数を調べて、nilでない最初の値を返す。すべてnilならnilを
返す。
`and'
順次各引数を調べてすべてnilでなかったら最後の引数値を返す。1つで
もnilならnilを返す。
`&optional'
引数はoptionalである。
`prefix-numeric-value'
(interactive "P")で生じたraw prefix argumentをnumeric値に変換。
`forward-line'
Move point forward to the beginning of the next line, or if the
argument is greater than one, forward that many lines. If it
can't move as far forward as it is supposed to, `forward-line'
goes forward as far as it can and then returns a count of the
number of additional lines it was supposed to move but couldn't.
`erase-buffer'
Delete the entire contents of the current buffer.
`bufferp'
Return `t' if its argument is a buffer; otherwise return `nil'.

7 6 Narrowing and Widening

  • 初心者が混乱しないように通常はdisabled.
  • `narrow-to-region' is `C-x n n'で undo command(C-x u)で戻らない。
    `widen' is `C-x n w'を使って戻す。

7.1 The `save-restriction' special form

  • lisp interpreterはsave-restrictionのbody codeを実行し、このcodeが
    narrowing で生じた全変化をkeep trackする。
  • What-lineコマンドではsave-restrictionに続くwiden command でnarrowing
    がundo される。関数が完成される直前にoriginal narrowingが回復する。
  • save excursionのtogether use時にはsave-excursionを外側に使うべき(逆
    順ではnarrowing の記録を失なうかもしれない)
    (save-excursion
    (save-restriction
    BODY…))
  • 以下は良。(together useではない)
    (save-restriction
    (widen)
    (save-excursion
    BODY…))

7.2 What-line

(defun what-line ()
       "Print the current line number (in the buffer) of point."
       (interactive)
       (save-restriction
         (widen)
         (save-excursion
           (beginning-of-line)
           (message "Line %d"
                    (1+ (count-lines 1 (point)))))))
  • (count-lines 1 (point));1行からpointまでのラインを数える。

8 7 . `car', `cdr', `cons' : Fundamental Functions

8.1 `car' and `cdr'

  • `car'(contents od the adress part of the register) and `cdr'(content
    of the decrement part of the register)
  • (car '(rose violet daisy buttercup))->最初の要素(rose)
  • (cdr '(rose violet daisy buttercup))->残りのリスト(violet daisy buttercup)
  • (car '((lion tiger cheetah) (gazelle antelope zebra) (whale dolphin seal)))
    ->(lion tiger cheetah)
  • 両者ともリストを返すだけ

8.2 cons = constructionの略

  • car cdr の逆
    (cons 'pine '(fir oak maple)) => (pine fir oak maple)
    (cons 'buttercup ()) => (buttercup)
    (cons 'daisy '(buttercup)) => (daisy buttercup)
    (cons 'violet '(daisy buttercup)) => (violet daisy buttercup)
    (cons 'rose '(violet daisy buttercup)) => (rose violet daisy buttercup)

8.3 Find the Length of a List: `length'

(length ())
(length '(buttercup))
=> 1
(length '(daisy buttercup))
=> 2
(length (cons 'violet '(daisy buttercup)))
=> 3

8.4 nthcdr

(nthcdr 2 '(pine fir oak maple))
=> (oak maple)

8.5 nth

(nth 0 '("one" "two" "three"))
=> "one"
(nth 1 '("one" "two" "three"))
=> "two"

8.6 set car

(setq animals '(antelope giraffe lion tiger))
animals
(setcar animals 'hippopotamus)

8.7 setcdr

(setq domestic-animals '(horse cow sheep goat))
(setcdr domestic-animals '(cat dog))
domestic-animals

9 8. Cutting and Storing Text

9.1 Storing Text in a List

  • (cons "another piece" '("a piece of text" "previous piece"))
    =>("another piece" "a piece of text" "previous piece")
  • (car (nthcdr 1 '("another piece" "a piece of text" "previous piece")
    =>"a piece of text"
    のように(ただしもっと複雑)

9.2 zap-to-char

  • (kill-regionと言う他の関数を呼ぶ)
  • pointから特定のcharacterまで移動してkill-ringに付加する。
(defun zap-to-char (arg char)
  "Kill up to and including ARG'th occurrence of CHAR.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
Goes backward if ARG is negative; error if CHAR not found."
  (interactive "p\ncZap to char: ")
  (if (char-table-p translation-table-for-input)
      (setq char (or (aref translation-table-for-input char) char)))
  (kill-region (point) (progn
                         (search-forward (char-to-string char)
                                         nil nil arg)
                         (point))))

9.2.1 interactive expression

(interactive "p\ncZap to char: ")
       p:  processed prefix C-u-(or M-)を使う.(なければ1)
       cZap to char: promptで Zap to char: character を期待。

9.2.2 body

(if (char-table-p translation-table-for-input) (setq char (or
    	(aref translation-table-for-input char) char)))

    	(kill-region (point) (progn (search-forward
    	(char-to-string char) nil nil arg) (point)))
  • char-table-pは引数がcharacter tableであるか決めそれをzap-to-charに渡す。
    (非欧州圏の文字の場合に重要)arefは配列から要素を抽出.(–不要?)
  • pointは現カーソル位置。progno以下はsearch-forwardで。

9.2.3 search-forward

  • target stringは1文字でcharacterをstringとして扱うのでこの関数を使う。
  • searchが成功したらその文字の直後にポイントを置きtを返す。4つの引数をとる。
    1。標的文字(char-to-stringでstring formatに変換する)
    2。検索の境界(この場合バッファの終わりだからnil)
    3.検索失敗時にすること。nilはエラーを出す。
    4。検索の繰り返し回数。負の数字なら逆向き検索。

9.2.4 progn

  • the progn special form:引数を順番に評価していって最後の値を返す.
  • 最初はsearch-forwardで標的字の後ろにポイントを置く.次(最後)は
    (point)でポイントの値(位置)を返す.

9.3 kill-region

+‘condition-case’と ‘copy-region-as-kill’を使う。

(defun kill-region (beg end)
  "Kill (\"cut\") text between point and mark.
This deletes the text from the buffer and saves it in the kill ring.
The command \\[yank] can retrieve it from there. … "

  ;; • Since order matters, pass point first.
  (interactive (list (point) (mark)))
  ;; • And tell us if we cannot cut the text.
  ;; `unless' is an `if' without a then-part.
  (unless (and beg end)
    (error "The mark is not set now, so there is no region"))

  ;; • `condition-case' takes three arguments.
  ;;    If the first argument is nil, as it is here,
  ;;    information about the error signal is not
  ;;    stored for use by another function.
  (condition-case nil

      ;; • The second argument to `condition-case' tells the
      ;;    Lisp interpreter what to do when all goes well.

      ;;    It starts with a `let' function that extracts the string
      ;;    and tests whether it exists.  If so (that is what the
      ;;    `when' checks), it calls an `if' function that determines
      ;;    whether the previous command was another call to
      ;;    `kill-region'; if it was, then the new text is appended to
      ;;    the previous text; if not, then a different function,
      ;;    `kill-new', is called.

      ;;    The `kill-append' function concatenates the new string and
      ;;    the old.  The `kill-new' function inserts text into a new
      ;;    item in the kill ring.

      ;;    `when' is an `if' without an else-part.  The second `when'
      ;;    again checks whether the current string exists; in
      ;;    addition, it checks whether the previous command was
      ;;    another call to `kill-region'.  If one or the other
      ;;    condition is true, then it sets the current command to
      ;;    be `kill-region'.
      (let ((string (filter-buffer-substring beg end t)))
        (when string                    ;STRING is nil if BEG = END
          ;; Add that string to the kill ring, one way or another.
          (if (eq last-command 'kill-region)
              ;;    − `yank-handler' is an optional argument to
              ;;    `kill-region' that tells the `kill-append' and
              ;;    `kill-new' functions how deal with properties
              ;;    added to the text, such as `bold' or `italics'.
              (kill-append string (< end beg) yank-handler)
            (kill-new string nil yank-handler)))
        (when (or string (eq last-command 'kill-region))
          (setq this-command 'kill-region))
        nil)

    ;;  • The third argument to `condition-case' tells the interpreter
    ;;    what to do with an error.
    ;;    The third argument has a conditions part and a body part.
    ;;    If the conditions are met (in this case,
    ;;             if text or buffer are read-only)
    ;;    then the body is executed.
    ;;    The first part of the third argument is the following:
    ((buffer-read-only text-read-only) ;; the if-part
     ;; …  the then-part
     (copy-region-as-kill beg end)
     ;;    Next, also as part of the then-part, set this-command, so
     ;;    it will be set in an error
     (setq this-command 'kill-region)
     ;;    Finally, in the then-part, send a message if you may copy
     ;;    the text to the kill ring without signaling an error, but
     ;;    don't if you may not.
     (if kill-read-only-ok
         (progn (message "Read only text copied to kill ring") nil)
       (barf-if-buffer-read-only)
       ;; If the buffer isn't read-only, the text is.
       (signal 'text-read-only (list (current-buffer)))))

9.3.1 condition-case

  • (condition-case
    VAR ;–>-nill(error情報は他の関数に使われない–プログラム停止しない)
    BODYFORM
    ERROR-HANDLER…) と言う形。
  • 全体として
    IF NO ERRORS, RUN ONLY THIS CODE
    BUT, IF ERRORS, RUN THIS OTHER CODE. という格好。
  • `yank-handler' is an optional argument to `kill-region' that tells
    the`kill-append' and `kill-new' functions how deal with properties
    added to the text, such as `bold' or `italics'.

9.3.2 copy-region-as-kill

  • バッファから範囲をコピーして(kill-append or kill-newを介して)kill-ring
    にセーブする)
  • The complete `copy-region-as-kill' function definition
    (defun copy-region-as-kill (beg end)
      "Save the region as if killed, but don't kill it.
    In Transient Mark mode, deactivate the mark.
    If `interprogram-cut-function' is non-nil, also save the text for a window
    system cut and paste."
      (interactive "r")
      (if (eq last-command 'kill-region)
          (kill-append (filter-buffer-substring beg end) (< end beg))
        (kill-new (filter-buffer-substring beg end)))
      (if transient-mark-mode
          (setq deactivate-mark t))
      nil)
    
  • 関数が実行される時、emacsはthis-commandを実行中の関数名にする(この場
    合copy-region-as-kill) .同時にlast-commandをthis-commandの 前値にす
    る。これがkill-regionならすでにあるkill-ring のCARに連鎖させる
    (kill-append). さもなければkill-ringに新しいものを作る(kill-new).

9.3.3 kill-append

(defun kill-append (string before-p &optional yank-handler)
    "Append STRING to the end of the latest kill in the kill ring.
  If BEFORE-P is non-nil, prepend STRING to the kill.
  … "
    (let* ((cur (car kill-ring)))
      (kill-new (if before-p (concat string cur) (concat cur string))
                (or (= (length cur) 0)
                    (equal yank-handler
                           (get-text-property 0 'yank-handler cur)))
                yank-handler)))
  • let*(*は不要)でcurにkill-ringの最後を割り当て、
  • kill-newを使う。
  • yank-handler;properties such as ‘bold’ or ‘italics’を扱う。

(if before-p ; if-part
(concat string cur) ; then-part
(concat cur string)) ; else-part

If the region being killed is before the region that was killed in the
last command(< end beg), then it should be prepended before the
material that was saved in the previous kill; and conversely, if the
killed text follows what was just killed, it should be appended after
the previous text.

9.3.4 kill-new

(defun kill-new (string &optional replace yank-handler)
  "Make STRING the latest kill in the kill ring.
STRINGをkill-ringのlatest killとする

Set `kill-ring-yank-pointer' to point to it.
(bold、italicなどの propertiesを扱う変数)

If `interprogram-cut-function' is non-nil, apply it to STRING.
Optional second argument REPLACE non-nil means that STRING will replace
the front of the kill ring, rather than being added to the list.
…"
  (if (> (length string) 0)
      (if yank-handler
          (put-text-property 0 (length string)
                             'yank-handler yank-handler string))
    (if yank-handler
        (signal 'args-out-of-range
                (list string "yank-handler specified for empty string"))))
  (if (fboundp 'menu-bar-update-yank-menu)
      (menu-bar-update-yank-menu string (and replace (car kill-ring))))
  (if (and replace kill-ring)
      (setcar kill-ring string)
    (push string kill-ring)
    (if (> (length kill-ring) kill-ring-max)
        (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
  (setq kill-ring-yank-pointer kill-ring)
  (if interprogram-cut-function
      (funcall interprogram-cut-function string (not replace))))
  • The critical lines are these:
(if (and replace kill-ring);kill-ringが何かを持ち、replace変数
      ;がtrueの時真。即ちkill-appendがreplaceをセットし kill-ring
      ;が何か持っている場合setcar実行。
      (setcar kill-ring string)
  (push string kill-ring);stringをkill-ringにput

    (if (> (length kill-ring) kill-ring-max)
        ;; avoid overly long kill ring
        ;;kill-ringの最後の要素を0にする
        (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
  (setq kill-ring-yank-pointer kill-ring)
  (if interprogram-cut-function
      (funcall interprogram-cut-function string (not replace))))
  • 戻って
(if (fboundp 'menu-bar-update-yank-menu)
      (menu-bar-update-yank-menu string (and replace (car kill-ring))))

+‘menu-bar-update-yank-menu(menu中 select、 paste できるようにする関数
の1つ)が関数として在れば呼ぶ。

(if interprogram-cut-function
    (funcall interprogram-cut-function string (not replace))))
  • コピーされたstringsを別種プログラムでもコピーペーストできるようにする。

9.4 8.6 Review

Here is a brief summary of some recently introduced functions.

`car'
`cdr'
`car' returns the first element of a list; `cdr' returns the
second and subsequent elements of a list.

For example:

(car '(1 2 3 4 5 6 7))
=> 1
(cdr '(1 2 3 4 5 6 7))
=> (2 3 4 5 6 7)

`cons'
`cons' constructs a list by prepending its first argument to its
second argument.

For example:

(cons 1 '(2 3 4))
=> (1 2 3 4)

`funcall'
`funcall' evaluates its first argument as a function. It passes
its remaining arguments to its first argument.

`nthcdr'
Return the result of taking CDR `n' times on a list. The `rest of
the rest', as it were.

For example:

(nthcdr 3 '(1 2 3 4 5 6 7))
=> (4 5 6 7)

`setcar'
`setcdr'
`setcar' changes the first element of a list; `setcdr' changes the
second and subsequent elements of a list.

For example:

(setq triple '(1 2 3))

(setcar triple '37)

triple
=> (37 2 3)

(setcdr triple '("foo" "bar"))

triple
=> (37 "foo" "bar")

`progn'
Evaluate each argument in sequence and then return the value of the
last.

For example:

(progn 1 2 3 4)
=> 4

`save-restriction'
Record whatever narrowing is in effect in the current buffer, if
any, and restore that narrowing after evaluating the arguments.

`search-forward'
Search for a string, and if the string is found, move point. With
a regular expression, use the similar `re-search-forward'. (*Note
Regular Expression Searches: Regexp Search, for an explanation of
regular expression patterns and searches.)

`search-forward' and `re-search-forward' take four arguments:

  1. The string or regular expression to search for.
  2. Optionally, the limit of the search.
  3. Optionally, what to do if the search fails, return `nil' or an
    error message.
  4. Optionally, how many times to repeat the search; if negative,
    the search goes backwards.

`kill-region'
`delete-and-extract-region'
`copy-region-as-kill'
`kill-region' cuts the text between point and mark from the buffer
and stores that text in the kill ring, so you can get it back by
yanking.

`copy-region-as-kill' copies the text between point and mark into
the kill ring, from which you can get it by yanking. The function
does not cut or remove the text from the buffer.

`delete-and-extract-region' removes the text between point and mark
from the buffer and throws it away. You cannot get it back. (This is
not an interactive command.)

10 9. How Lists are Implemented

11 10. Loops and Recursion

11.1 while

  • (while TRUE-OR-FALSE-TEST;falseなら以後skip
    BODY…)

11.1.1

(setq animals '(gazelle giraffe lion tiger))
(while animals (setq animals (cdr animals))) nil

(defun print-elements-of-list (list)
       "Print each element of LIST on a line of its own."
       (while list
         (print (car list))
         (setq list (cdr list))))

(print-elements-of-list animals)

11.1.2 loop with incrementing counter

(defun triangle (number-of-rows)
  "Add row-number to total
increment row-number by 1"
  (let ((total 0) (row-number 1))
    (while (<= row-number number-of-rows)
      (setq total (+ total row-number))
      (setq row-number (1+ row-number)))
    total))

(triangle 7)

  • let()評価結果がdefunの返り値で、whileはnilを返すからletで始まるリス
    トの最後の要素としてそのシンボルを書けばよい(total)

11.1.3 loop with decrementing counter

(defun triangle (number-of-row)
  "decrement"
  (let ((total 0) (peddle number-of-row))
    (while (< 0 peddle)
      (setq total (+ total peddle))
      (setq peddle (1- peddle)))
    total)

(triangle 7)

11.2 Save your time :`dolist' and `dotimes'

  • 両者ともlisp macroである。
  • dolistはCDRでリストをたどる。
  • dotimesは規定の回数だけループする。

11.2.1 dolist macro

  • 1->2^>3を 3->2->1にする場合
    (setq animals '(gazelle giraffe lion tiger))
(defun reverse-list-with-while (list)
  "Using while, reverse the order of LIST."
  (let (value)  ; make sure list starts empty
    (while list
      (setq value (cons (car list) value))
      (setq list (cdr list)))
    value))

(reverse-list-with-while animals)

(defun reverse-list-with-dolist (list)
  "Using dolist, reverse the order of LIST."
  (let (value)  ; make sure list starts empty
    (dolist (element list value)
      (setq value (cons element value)))))

(reverse-list-with-dolist animals)

11.2.2 The ‘dotimes’ Macro

(let (value)      ; otherwise a value is a void variable
  (dotimes (number 3 value)
    (setq value (cons number value))))

⇒ (2 1 0)

number 0 -> value (0)
number 1 -> value (1 0)
number 2 -> value (2 1 0)

(defun triangle-using-dotimes (number-of-rows)
   "Using dotimes, add up the number of pebbles in a triangle."
 (let ((total 0))  ; otherwise a total is a void variable
   (dotimes (number number-of-rows total)
     (setq total (+ total (1+ number))))))

(triangle-using-dotimes 4)

12 11. Recursion

12.1 The Parts of a Recursive Definition

1.do-again-test(関数が再び呼ばれるかどうかの真偽テスト:再起条件)
2.関数名(名ば前が呼ばれると新しいインスタンスが呼ばれる)
3.next-step-expression:(関数が呼ばれた時違う値を返すような式:次段式)

(defun 再帰関数名 (引数リスト)
"DOCUMENTATION…"
(if 再起条件
本体…
(再帰関数名
次段式)))

12.2 Recursion with a List

(defun print-elements-recursively (list)
    "Print each element of LIST on a line of its own.
  Uses recursion."
    (when list                            ; do-again-test
          (print (car list))              ; body
          (print-elements-recursively     ; recursive call
           (cdr list))))                  ; next-step-expression

(setq animals '(gazelle giraffe lion tiger))
(print-elements-recursively animals)

12.3 Recursion in Place of a Counter(カウンタの代用としての再帰)

(defun triangle-recursively (number)
  "Return the sum of the numbers 1 through NUMBER inclusive.
Uses recursion."
  (if (= number 1)                    ; do-again-test
      1                               ; then-part
    (+ number                         ; else-part
       (triangle-recursively          ; recursive call
        (1- number)))))               ; next-step-expression
  • (triangle-recursively 3)=(+ 3 (triangle-recursively 2))=(+ 3 (2 +
    (triangle-recursively 1))) = 3 + (2 + 1) =6
    のように働く。

(triangle-recursively 3)

12.4 Recursion Example Using ‘cond'

  • template
    (cond
    (FIRST-TRUE-OR-FALSE-TEST FIRST-CONSEQUENT)
    (SECOND-TRUE-OR-FALSE-TEST SECOND-CONSEQUENT)
    (THIRD-TRUE-OR-FALSE-TEST THIRD-CONSEQUENT)
    …)
(defun triangle-using-cond (number)
 (cond ((<= number 0) 0)
       ((= number 1) 1)
       ((> number 1)
        (+ number (triangle-using-cond (1- number))))))

12.5 Recursive Patterns

12.5.1 Recursive Pattern: every

(defun square-each (numbers-list)
  "Square each of a NUMBERS LIST, recursively."
  (if (not numbers-list)                ; do-again-test
      nil
    (cons
     (* (car numbers-list) (car numbers-list))
     (square-each (cdr numbers-list))))) ; next-step-expression

(square-each '(1 2 3))

12.5.2 accumulate

(defun add-elements (numbers-list)
 "Add the elements of NUMBERS-LIST together."
 (if (not numbers-list)
     0
   (+ (car numbers-list) (add-elements (cdr numbers-list)))))

(add-elements '(1 2 3 4))

12.5.3 keep

(defun keep-three-letter-words (word-list)
  "Keep three letter words in WORD-LIST."
  (cond
   ;; First do-again-test: stop-condition
   ((not word-list) nil)

   ;; Second do-again-test: when to act
   ((eq 3 (length (symbol-name (car word-list))))
    ;; combine acted-on element with recursive call on shorter list
    (cons (car word-list) (keep-three-letter-words (cdr word-list))))

   ;; Third do-again-test: when to skip element;
   ;;   recursively call shorter list with next-step expression
   (t (keep-three-letter-words (cdr word-list)))))

t ?

(keep-three-letter-words '(one two three four five six))

12.5.4 No Deferment Solution(延期なし)

  • 2つの関数を使うパターン
    (defun triangle-initialization (number)
       "Return the sum of the numbers 1 through NUMBER inclusive.
     This is the `initialization' component of a two function
     duo that uses recursion."
       (triangle-recursive-helper 0 0 number))
    
    (defun triangle-recursive-helper (sum counter number)
        "Return SUM, using COUNTER, through NUMBER inclusive.
      This is the `helper' component of a two function duo
      that uses recursion."
        (if (> counter number)
            sum
          (triangle-recursive-helper (+ sum counter)  ; sum
                                     (1+ counter)     ; counter
                                     number)))        ; number
    

    (triangle-initialization 2)

13 12. Regular Expression Searches

  • forward-sentense,とforward-paragraph関数がある.

13.1 The regular expression for `sentence-end'

 [.?!] の1つで終わりその後に行末、タブ、スペース2つ即ち
\\($\\<tab>\\|<spc><spc>\\)等が付けばそれらしくなる
\\($\\| \\|  \\)  ;emacs では( と | の前に2つの\が必要(最初の\は次の\
を引用し2番目は(や|が特別な文字であることを示す。

が、他に複数のcarriage returnが続いて良い。
[
     ]*
[.?!]のみで終るのでなく下記がspaceの前にあっても終ることができる。
         ] " ' ) }  即ち   []\"')}]*
"が特殊でないことを示すために\を先行
で  sentence-end
    =>    "[.?!][]\"')}]*\\($\\|     \\|  \\)[
	  ]*"

13.2 re-search-forward

正規表現を探索する。見つかった文字列の最後の直後にポイントを置く(逆
向きでは最初の直前)。
真値としてTを返すよう指示できる。
引数
1.引数探索する正規表現"文字列”
2.探索する範囲(省略可)。バッファの位置で指定。
3.失敗 した場合の動作:nilを指示すると失敗した場合にエラーを
表示しそれ以外を指定すると、失敗したらnilを返し成功するとtを返
す。
4.(略可)繰り返し 回数(略可)

13.3 forward-sentenceのコード

(defun forward-sentence (&optional arg)
  "Move forward to next `sentence-end'.  With argument, repeat.
With negative argument, move backward repeatedly to `sentence-beginning'.

The variable `sentence-end' is a regular expression that matches ends of
sentences.  Also, every paragraph boundary terminates sentences as well."
  (interactive "p")
  (or arg (setq arg 1))
  (let ((opoint (point))
        (sentence-end (sentence-end)))
    (while (< arg 0)
      (let ((pos (point))
            (par-beg (save-excursion (start-of-paragraph-text) (point))))
       (if (and (re-search-backward sentence-end par-beg t)
                (or (< (match-end 0) pos)
                    (re-search-backward sentence-end par-beg t)))
           (goto-char (match-end 0))
         (goto-char par-beg)))
      (setq arg (1+ arg)))
    (while (> arg 0)
      (let ((par-end (save-excursion (end-of-paragraph-text) (point))))
       (if (re-search-forward sentence-end par-end t)
           (skip-chars-backward " \t\n")
         (goto-char par-end)))
      (setq arg (1- arg)))
    (constrain-to-field nil opoint t)))

13.3.1 この骨格は

(defun forward-sentence (&optional arg)
       "DOCUMENTATION…"
       (interactive "p")
       (or arg (setq arg 1))
       (let ((opoint (point)) (sentence-end (sentence-end)))
         (while (< arg 0)
           (let ((pos (point))
                 (par-beg (save-excursion (start-of-paragraph-text) (point))))
            REST-OF-BODY-OF-WHILE-LOOP-WHEN-GOING-BACKWARDS
         (while (> arg 0)
           (let ((par-end (save-excursion (end-of-paragraph-text) (point))))
            REST-OF-BODY-OF-WHILE-LOOP-WHEN-GOING-FORWARDS
         HANDLE-FORMS-AND-EQUIVALENT

13.3.2 while loops

  • 最初のものは後方探索
  • 次は前方探索
  • pはprefix number: default=1, non-interactivelyにprefixなしで起動さ
    れて、nilとなったときの処理がor …でnilのargを1にする。
  • 2番目のwhile
    (while (> arg 0)            ; true-or-false-test
      (let ((par-end
           (save-excursion (end-of-paragraph-text) (point))))
      (if (re-search-forward sentence-end par-end t)
          (skip-chars-backward " \t\n")
        (goto-char par-end)))
    
  • par-endはlimit to the search(ここで終わる)
  • end-of-paragraph-text関数は段落末にポイントを移す。
  • `re-search-forward’が文末を探す。見つけたら
     1そこにポイントを置く。
     2真値を返す。
  • then 空白文字部を飛ばして後ろに返る。通常は.まで。
  • else 段落末にポイント
  • (And if the text is in a form or equivalent, and point may not
    move fully, then the `constrain-to-field' function comes into play.)

13.3.3 The regular expression searc

  1. re-search-forward’ は 副作用を及ぼす(見つけた文字列の直後にポイン
    トを置く。)
  2. re-search-forward は真値を返す.これを‘if’が受けとり、探索成功と知
    る。-> then…
‘(skip-chars-backward " \t\n")
  • 見える文字が見付かるまで空白やタブやリ
  • ターンをとばしてその文字の直後にポイント移動する。
  • 失敗したら‘(goto-char par-end)’

13.4 forward-paragraph 関数の宝庫(M-}にバインド)

13.4.1 in brief

(defun forward-paragraph (&optional arg)
 "DOCUMENTATION…"
 (interactive "p")
 (or arg (setq arg 1))
 (let*
     VARLIST
   (while (and (< arg 0) (not (bobp)))     ; backward-moving-code
     …
   (while (and (> arg 0) (not (eobp)))     ; forward-moving-code
     …

13.4.2 fwd-para let

  • ‘let*’expressionは変数を順次セットでき、後の変数が前の変数を使う
    ことができる。この関数中では7つ‘opoint’, ‘fill-prefix-regexp’,
    ‘parstart’, ‘parsep’,sp-parstart’, ‘start’, and
    ‘found-start’

13.4.3 fwd-para while

  • ‘while’ loop
    ここは後日。

13.4.4 create your own `TAGS'file

  • `C-h f' (`describe-function')以外のソースを見る方法は type
    `M-.'(`find-tag')and the name of the function.
  • 場所が解らないのでホームにTAGSファイルを作った。
    M-x compile RET etags *.el RET
    M-x compile RET etags –help RET
    `M-x locate <RET> TAGS <RET>'

13.5 12.6 Review

Here is a brief summary of some recently introduced functions.

  • `while'
    body testが真であるかぎり本体を評価し、そしてnilを返す。
    For example:
(let ((foo 2))
(while (> foo 0)
(insert (format "foo is %d.\n" foo))
(setq foo (1- foo)))) 

=>      foo is 2.
foo is 1.
nil

(The `insert' function inserts its arguments at point; the
`format' function returns a string formatted from its arguments
the way `message' formats its arguments; `\n' produces a new line.)
  • `re-search-forward'
    Search for a pattern,を探し見つかったらその直後にポイント
    Takes four arguments, like `search-forward':
    1. A regular expression that specifies the pattern to search for.
      (Remember to put quotation marks around this argument!)
    2. Optionally, the limit of the search.
    3. Optionally, what to do if the search fails, return `nil' or an
      error message.
    4. Optionally, how many times to repeat the search; if negative,
      the search goes backwards.
  • `let*' :変数に値を結合させ残りの引数を評価して、最後の値を返す。先
    に結合させた変数値の使用可

    (let* ((foo 7)
    (bar (* 3 foo)))
    (message "`bar' is %d." bar))      
    => `bar' is 21.
    
  • `match-beginning'
    Return the position of the start of the text found by the last
    regular expression search.
  • `looking-at'
    Return `t' for true if the text after point matches the argument,
    which should be a regular expression.
  • `eobp'
    Return `t' for true if point is at the end of the accessible part
    of a buffer. The end of the accessible part is the end of the
    buffer if the buffer is not narrowed; it is the end of the
    narrowed part if the buffer is narrowed.

14 13 Counting: Repetition and Regexps

14.1 count-words-region設計

単語を構成する1個以上の文字の後に単語を構成しない文字が0個以上続く正規
表現  \w+\W*   ->  
(re-search-forward "\\w+\\W*")
\は次に来る文字は特殊に解釈される( \n :newlineのように) \の次の\は特殊
でないものとして 即ち\w,\Wを表すものとして解釈される。

;;; bugあり!

 ;;; First version; has bugs!
     (defun count-words-example (beginning end)
       "Print number of words in the region.
     Words are defined as at least one word-constituent
     character followed by at least one character that
     is not a word-constituent.  The buffer's syntax
     table determines which characters these are."
       (interactive "r")
       (message "Counting words in region ... ")

     ;;; 1. Set up appropriate conditions.
       (save-excursion
         (goto-char beginning)
         (let ((count 0))

     ;;; 2. Run the while loop.
           (while (< (point) end)
             (re-search-forward "\\w+\\W*")
             (setq count (1+ count)))

     ;;; 3. Send a message to the user.
           (cond ((zerop count)
                  (message
                   "The region does NOT have any words."))
                 ((= 1 count)
                  (message
                   "The region has 1 word."))
                 (t
                  (message
                   "The region has %d words." count))))))
   
 
(global-set-key "\C-c=" 'count-words-region)
でkeybinding installでき(or M-x count-words-example’)


         one   two  three

のregionで試す事ができる。(ただしorg-mode中では不可)

前方空白部でやると1語、後方でやるとseach failed となる。このbugは
while–でmarked regionを越えてword searchすること。re-search-forwardの
引数に end(ここまで) t(search failed のエラーメッセージを表示させない)
を加えるべし。だがwordが見つからない時無限ループに陥る。
true-or-false-test of the ‘while’ loop はsearch failsの時false にし
なければならない。(andを使う)

;;; Final version: `while'

;;; Final version: while
    (defun count-words-example (beginning end)
      "Print number of words in the region."
      (interactive "r")
      (message "Counting words in region ... ")

    ;;; 1. Set up appropriate conditions.
      (save-excursion
        (let ((count 0))
          (goto-char beginning)

    ;;; 2. Run the while loop.
          (while (and (< (point) end)
                      (re-search-forward "\\w+\\W*" end t))
            (setq count (1+ count)))

    ;;; 3. Send a message to the user.
          (cond ((zerop count)
                 (message
                  "The region does NOT have any words."))
                ((= 1 count)
                 (message
                  "The region has 1 word."))
                (t
                 (message
                  "The region has %d words." count))))))

14.2 Count Words Recursively

The recursive function:

     (defun recursive-count-words (region-end)
       "Number of words between point and REGION-END."

     ;;; 1. do-again-test
       (if (and (< (point) region-end)
                (re-search-forward "\\w+\\W*" region-end t))

     ;;; 2. then-part: the recursive call
           (1+ (recursive-count-words region-end))

     ;;; 3. else-part
         0))

The wrapper:

     ;;; Recursive version
     (defun count-words-example (beginning end)
       "Print number of words in the region.

     Words are defined as at least one word-constituent
     character followed by at least one character that is
     not a word-constituent.  The buffer's syntax table
     determines which characters these are."
       (interactive "r")
       (message "Counting words in region ... ")
       (save-excursion
         (goto-char beginning)
         (let ((count (recursive-count-words end)))
           (cond ((zerop count)
                  (message
                   "The region does NOT have any words."))
                 ((= 1 count)
                  (message "The region has 1 word."))
                 (t
                  (message
                   "The region has %d words." count))))))

15 14 Counting Words in a `defun'

C-M-hは(defunなど行の先頭の(を認識。

defun中の単語数のヒストグラムを作るプロジェクト

15.1 What to Count?

‘multiply-by-seven’のようなものを1語とするにはregexpは
"\\(\\w\\|\\s_\\)+[^ \t\n]*[ \t\n]": words(\w) と symbols(\s_)よりなり、
空白でない`)'等が付いたり付かなかったりしたあとに空白があるもの

15.1.1 ‘count-words-in-defun

+----------------------------------------------------------+
|(defun count-words-in-defun ()                            |
|      "Return the number of words and symbols in a defun."|
|      (beginning-of-defun)                                |
|      (let ((count 0)                                     |
|        (end (save-excursion (end-of-defun) (point))))    |
|        (while                                            |
|        (and (< (point) end)                              |
|             (re-search-forward                           |
|              "\\(\\w\\|\\s_\\)+[^ \t\n]*[ \t\n]*"        |
|              end t))                                     |
|          (setq count (1+ count)))                        |
|        count))                                           |
+----------------------------------------------------------+
  • `beginning-of-defun'は後方に opening delimiter such as a `(' at the
    beginning of a lineを探す。`end-of-defun'は定義の終わりを探す。
    interactiveでないこのプログラムを試すにはcount-words-regionと同じく
    次のラッパーがいる。
         ;;; Interactive version.
         (defun count-words-defun ()
           "Number of words and symbols in a function definition."
           (interactive)
           (message
            "Counting words and symbols in function definition ... ")
           (let ((count (count-words-in-defun)))
             (cond
              ((zerop count)
               (message
                "The definition does NOT have any words or symbols."))
              ((= 1 count)
               (message
                "The definition has 1 word or symbol."))
              (t
               (message
                "The definition has %d words or symbols." count)))))
       
    + 2ツの関数を評価して
       (global-set-key "\C-c=" 'count-words-defun)
        で使える。
    

15.2 Count Several `defuns' Within a File

  • 各ファイルのlengthsの統計をのみとるのが目的

15.3 Count Several ‘defuns’ Within a File

Here is what this fragment of code looks like:

  (goto-char (point-min))
  (while (re-search-forward "^(defun" nil t)
    (setq lengths-list
          (cons (count-words-in-defun) lengths-list)))

15.4 Find a File

(defun find-file (filename)                            
      "Edit file FILENAME.                             
         Switch to a buffer visiting file FILENAME,    
         creating one if none already exists."         
      (interactive "FFind file: ")                     
      (switch-to-buffer (find-file-noselect filename)))
  • C-x C-fにバインドしている
  • find-file-noselectでファイルをバッファに出し(しかしながらこれはバッ
    ファを選ばないので)switch-to-bufferで注意を向ける。ヒストグラムプロ
    ジェクトではこれはいらない。set-bufferで良い(screenには出さないで注
    視する)

15.5 ‘lengths-list-file’ in Detail

  • core function is while
    (defun lengths-list-file (filename)
      "Return list of definitions' lengths within FILE.
    The returned list is a list of numbers.
    Each number is the number of words or
    symbols in one function definit ion."
      (message "Working on `%s' ... " filename)
      (save-excursion
        (let ((buffer (find-file-noselect filename))
              (lengths-list))
          (set-buffer buffer)
          (setq buffer-read-only t)
          (widen)
          (goto-char (point-min))
          (while (re-search-forward "^(defun" nil t)
            (setq lengths-list
                  (cons (count-words-in-defun) lengths-list)))
          (kill-buffer buffer)
          lengths-list)))
    

    (lengths-list-file
    "/usr/local/share/emacs/22.1.1/lisp/emacs-lisp/debug.el")
    (75 41 80 62 20 45 44 68 45 12 34 235)の様になる。

15.6 Count Words in ‘defuns’ in Different Files

15.6.1 Determine the lengths of ‘defuns

  • 引数のリストが空の時はリストを縮める。
    ;;; Use ‘while’ loop.
       (defun lengths-list-many-files (list-of-files)
         "Return list of lengths of defuns in LIST-OF-FILES."
         (let (lengths-list)
    
       ;;; true-or-false-test
           (while list-of-files
    	 (setq lengths-list
    	       (append
    		lengths-list
    
       ;;; Generate a lengths’ list.
    		(lengths-list-file
    		 (expand-file-name (car list-of-files)))))
    
       ;;; Make files’ list shorter.
    	 (setq list-of-files (cdr list-of-files)))
    
       ;;; Return final value of lengths’ list.
           lengths-list))
    
  • `expand-file-name' 正式なpathnameにする。
    (append '(1 2 3 4) '(5 6 7 8)) -> (1 2 3 4 5 6 7 8)
    (cons '(1 2 3 4) '(5 6 7 8)) -> ((1 2 3 4) 5 6 7 8)とちがう

15.6.2 Recursively Count Words in Different Files

(defun recursive-lengths-list-many-files (list-of-files)
  "Return list of lengths of each defun in LIST-OF-FILES."
  (if list-of-files                     ; do-again-test
      (append
       (lengths-list-file
	(expand-file-name (car list-of-files)))
       (recursive-lengths-list-many-files
	(cdr list-of-files)))))

(sort '(4 8 21 17 33 7 21 7) '<) -> (4 7 7 8 17 21 21 33)

(sort
(recursive-lengths-list-many-files
'("./lisp/macros.el"
"./lisp/mailalias.el"
"./lisp/makesum.el"))
'<)
which produces:
(29 32 38 85 90 95 178 180 181 218 263 283 321 324 480)

15.6.3 Making a List of Files

(defun files-in-below-directory (directory)
  "List the .el files in DIRECTORY and in its sub-directories."
  ;; Although the function will be used non-interactively,
  ;; it will be easier to test if we make it interactive.
  ;; The directory will have a name such as
  ;;  "/usr/local/share/emacs/22.1.1/lisp/"
  (interactive "DDirectory name: ")
  (let (el-files-list
	(current-directory-list
	 (directory-files-and-attributes directory t)))
    ;; while we are in the current directory
    (while current-directory-list
      (cond
       ;; check to see whether filename ends in '.el'
       ;; and if so, add its name to a list.
       ((equal ".el" (substring (car (car current-directory-list)) -3))
	(setq el-files-list
	      (cons (car (car current-directory-list)) el-files-list)))
       ;; check whether filename is that of a directory
       ((eq t (car (cdr (car current-directory-list))))
	;; decide whether to skip or recurse
	(if
	    (equal "."
		   (substring (car (car current-directory-list)) -1))
	    ;; then do nothing since filename is that of
	    ;;   current directory or parent, "." or ".."
	    ()
	  ;; else descend into the directory and repeat the process
	  (setq el-files-list
		(append
		 (files-in-below-directory
		  (car (car current-directory-list)))
		 el-files-list)))))
      ;; move to the next filename in the list; this also
      ;; shortens the list so the while loop eventually comes to an end
      (setq current-directory-list (cdr current-directory-list)))
    ;; return the filenames
    el-files-list))

(sort
(files-in-below-directory "usr/local/share/emacs/22.1.1/lisp")
'string-lessp)
逆向きアルファベットを順向きにする

15.6.4 Counting function definitions

(defvar top-of-ranges
'(10 20 30 40 50
60 70 80 90 100
110 120 130 140 150
160 170 180 190 200
210 220 230 240 250
260 270 280 290 300)
"List specifying ranges for `defuns-per-range'.")

内部ループがrange内の定義数を数え、外側がtop-of-rangeのlowestから
higherへ続かせる

+-------------------------------------------------------------------------+
|(defun defuns-per-range (sorted-lengths top-of-ranges)                   |
|       "SORTED-LENGTHS defuns in each TOP-OF-RANGES range."              |
|       (let ((top-of-range (car top-of-ranges))                          |
|             (number-within-range 0)                                     |
|             defuns-per-range-list)                                      |
|                                                                         |
|         ;; Outer loop.                                                  |
|         (while top-of-ranges                                            |
|                                                                         |
|           ;; Inner loop.                                                |
|           (while (and                                                   |
|                   ;; Need number for numeric test.                      |
|                   (car sorted-lengths)                                  |
|                   (< (car sorted-lengths) top-of-range))                |
|                                                                         |
|             ;; Count number of definitions within current range.        |
|             (setq number-within-range (1+ number-within-range))         |
|             (setq sorted-lengths (cdr sorted-lengths)))                 |
|                                                                         |
|           ;; Exit inner loop but remain within outer loop.              |
|                                                                         |
|           (setq defuns-per-range-list                                   |
|                 (cons number-within-range defuns-per-range-list))       |
|           (setq number-within-range 0)      ; Reset count to zero.      |
|                                                                         |
|           ;; Move to next range.                                        |
|           (setq top-of-ranges (cdr top-of-ranges))                      |
|           ;; Specify next top of range value.                           |
|           (setq top-of-range (car top-of-ranges)))                      |
|                                                                         |
|         ;; Exit outer loop and count the number of defuns larger than   |
|         ;;   the largest top-of-range value.                            |
|         (setq defuns-per-range-list                                     |
|               (cons                                                     |
|                (length sorted-lengths)                                  |
|                defuns-per-range-list))                                  |
|                                                                         |
|         ;; Return a list of the number of definitions within each range,|
|         ;;   smallest to largest.                                       |
|         (nreverse defuns-per-range-list)))                              |
+-------------------------------------------------------------------------+

(nreverse '(1 2 3 4)) -> (4 3 2 1)

(car sorted-lengths)
(< (car sorted-lengths) top-of-range)) はエラーを避けるため

;; (Shorter list than we will use later.)
(setq top-of-ranges
'(110 120 130 140 150
160 170 180 190 200))

(setq sorted-lengths
'(85 86 110 116 122 129 154 176 179 200 265 300 300))

(defuns-per-range sorted-lengths top-of-ranges)

-> (2 2 2 0 0 1 0 2 0 0 4)

15.7 グラフの列表示

15.7.1 Printing the Columns of a Graph

(insert-rectangle '("first" "second" "third"))
(apply 'max '(4 8 5))
 
;;; First version.
(defun column-of-graph (max-graph-height actual-height)
"Return list of strings that is one column of a graph."
(let ((insert-list nil)
(number-of-top-blanks
(- max-graph-height actual-height)))

;; Fill in asterisks.
(while (> actual-height 0)
(setq insert-list (cons "*" insert-list))
(setq actual-height (1- actual-height)))

;; Fill in blanks.
(while (> number-of-top-blanks 0)
(setq insert-list (cons " " insert-list))
(setq number-of-top-blanks
(1- number-of-top-blanks)))

;; Return whole list.
insert-list))

15.7.2 The ‘graph-body-print’ Function

(defun graph-body-print (numbers-list)
"Print a bar graph of the NUMBERS-LIST.
The numbers-list consists of the Y-axis values."

(let ((height (apply 'max numbers-list))
(symbol-width (length graph-blank))
from-position)

(while numbers-list
(setq from-position (point))
(insert-rectangle
(column-of-graph height (car numbers-list)))
(goto-char from-position)
(forward-char symbol-width)
;; Draw graph column by column.
(sit-for 0)
(setq numbers-list (cdr numbers-list)))
;; Place point for X axis labels.
(forward-line height)
(insert "\n")
))

(defvar graph-symbol "*"
"String used as symbol in graph, usually an asterisk.")

(defvar graph-blank " "
"String used as blank in graph, usually a blank space.
graph-blank must be the same number of columns wide
as graph-symbol.")
;;; Second version.
(defun column-of-graph (max-graph-height actual-height)
"Return MAX-GRAPH-HEIGHT strings; ACTUAL-HEIGHT are graph-symbols.  
The graph-symbols are contiguous entries at the end
of the list.
The list will be inserted as one column of a graph.
The strings are either graph-blank or graph-symbol."

(let ((insert-list nil)
(number-of-top-blanks
(- max-graph-height actual-height)))

;; Fill in `graph-symbols'.
(while (> actual-height 0)
(setq insert-list (cons graph-symbol insert-list))
(setq actual-height (1- actual-height)))

;; Fill in `graph-blanks'.
(while (> number-of-top-blanks 0)
(setq insert-list (cons graph-blank insert-list))
(setq number-of-top-blanks
(1- number-of-top-blanks)))

;; Return whole list.
insert-list))
(defun graph-body-print (numbers-list)
"Print a bar graph of the NUMBERS-LIST.
The numbers-list consists of the Y-axis values."

(let ((height (apply 'max numbers-list))
(symbol-width (length graph-blank))
from-position)

(while numbers-list
(setq from-position (point))
(insert-rectangle
(column-of-graph height (car numbers-list)))
(goto-char from-position)
(forward-char symbol-width)
;; Draw graph column by column.
(sit-for 0)
(setq numbers-list (cdr numbers-list)))
;; Place point for X axis labels.
(forward-line height)
(insert "\n")
))
(graph-body-print '(1 2 3 4 6 4 3 5 7 6 5 2 3))        *   
*   **  
*  **** 
  *** **** 
  ********* *
  ************
  *************
  (defun recursive-graph-body-print (numbers-list)
  "Print a bar graph of the NUMBERS-LIST.
  The numbers-list consists of the Y-axis values."
  (let ((height (apply 'max numbers-list))
  (symbol-width (length graph-blank))
  from-position)
  (recursive-graph-body-print-internal
  numbers-list
  height
  symbol-width)))
  (defun recursive-graph-body-print-internal
  (numbers-list height symbol-width)
  "Print a bar graph.
  Used within recursive-graph-body-print function."

  (when numbers-list
  (setq from-position (point))
  (insert-rectangle
  (column-of-graph height (car numbers-list)))
  (goto-char from-position)
  (forward-char symbol-width)
  (sit-for 0)     ; Draw graph column by column.
  (recursive-graph-body-print-internal
  (cdr numbers-list) height symbol-width)))
  (recursive-graph-body-print '(3 2 5 6 7 5 3 4 6 4 3 2 1))    *       
  **   *   
  ****  *   
  **** ***  
  * ********* 
    ************
    *************
  (defcustom text-mode-hook nil
  "Normal hook run when entering Text mode and many related modes."
  :type 'hook
  :options '(turn-on-auto-fill flyspell-mode)
  :group 'data)

16 Your ‘.emacs’ File

初期化ファイル(.emacs/init.el)の書き方

16.1 defcustomを使用した変数の指定

  • customizeはdefcustom(マクロ)によって為される。これは4つの引数を取る。
    (変数名、初期値、documentation、types and options)

    (defcustom text-mode-hook nil
      "Normal hook run when entering Text mode and many related modes."
      :type 'hook
      :options '(turn-on-auto-fill flyspell-mode)
      :group 'wp)
    

    変数名 :‘text-mode-hook’
    変数初期値 :no default value;
    documentation :"Normal hook …."
    type :text-mode-hookのdata
    options :通常hookに適用される推奨
    group:which group the variable is located

  • この変数のカスタマイズは M-x customize するか(
    (custom-set-variables
     ;; custom-set-variables was added by Custom.
     ;; If you edit it by hand, you could mess it up, so be careful.
     ;; Your init file should contain only one such instance.
     ;; If there is more than one, they won't work right.
    '(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify))))
    

    と init.elに書かれる)

  • custom-set-… とは無関係なコードを使ってセットする。
    (emacsにより‘custom-set-…’でこれを評価して.init.elに書きだされる)

16.2 Beginning a ‘.emacs’ File(init.elの事だろう)

‘emacs -q’で始めない限り‘.emacs’ file をロードする。

16.3 Text and Auto Fill Mode

;;; Text mode and Auto Fill mode
;; The next two lines put Emacs into Text mode
;; and Auto Fill mode, and are for writers who
;; want to start writing prose rather than code.
(setq-default major-mode 'text-mode)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
  • setq..はEmacs Lisp expression。
  • また 最初の非空白行が ‘-*- C -*-’ならCモードにする。またはバッファ
    の 最後の行付近に“local variables list”を見る(あらば)。
  • add-hook は変数に‘turn-on-auto-fill’(program)を加える。よって

Text mode をonにする毎にhookedコマンドを走らせるから、Auto Fill modeも
onになる

16.4 Mail Aliases

;;; Mail mode
; To enter mail mode, type `C-x m'
; To enter RMAIL (for reading mail),
; type `M-x rmail'
(setq mail-aliases t)
  • aliasは‘~/.mailrc’に保存する。
    alias geo george@foobar.wiz.eduのように使う。

16.5 Indent Tabs Mode

16.6 Indent Tabs Mode

  • Tex やTexinfoで tabを無視するから
    ;;; Prevent Extraneous Tabs
    (setq-default indent-tabs-mode nil)
    とすることがあるが、setq-default は変数が own local valuesを持たない
    バッファのみでセットする。

16.7 Some Keybindings

;;; Compare windows
(global-set-key "\C-cw" 'compare-windows)

左右のwindowをマッチするかぎり比較させる粋なコマンド。

;;; Keybinding for `occur'
; I use occur a lot, so let's bind it to a key:
(global-set-key "\C-co" 'occur)
  • regexpでマッチ行を‘*Occur*’に示す。
;;; Unbind `C-x f'
(global-unset-key "\C-xf")
  • unbindする。
;;; Rebind `C-x C-b' for `buffer-menu'
(global-set-key "\C-x\C-b" 'buffer-menu)
  • rebindする。

16.8 Keymaps

Emacs uses "keymaps" to record which keys call which commands.

16.9 Loading Files

  • 例えば (load "~/emacs/slowsplit")とするが、次のマンドで‘~/emacs’を
    現在のロードパスに含めることができる。
;;; Emacs Load Path
(setq load-path (cons "~/emacs" load-path))

Author: ouryouji

Created: 2019-07-11 木 09:50

Emacs 24.5.1 (Org mode 8.2.10)

Validate