2012-04-09から1日間の記事一覧
princとは、エコーエリアに出力する標準出力関数のこと。 引数オブジェクトを文字列として書き出す。 Welcome to IELM *** Type (describe-mode) for help. ELISP> (princ "Hello world!") "Hello world!" ELISP> (princ (format "Emacs version is %s" emac…
(defun hello-world() (interactive) ;; このおまじないで関数をコマンドにする (message "%s" "Hello, world!")) ;; 文字列をエコーエリアに表示するmessage関数を利用している (defun testint-b (arg) (interactive "b既存バッファ: ") (message "%s" arg)…
;; 今度は&restをつける (defun rest-arg (a &optional b &rest c) (list a b c)) (rest-arg 1) ; => (1 nil nil) (rest-arg 1 2) ; => (1 2 nil) (rest-arg 1 2 3) ; => (1 2 (3)) (rest-arg 1 2 3 4) ; => (1 2 (3 4)) Emacs Lispテクニックバイブル作者: …
;; aは必須引数で、bとcは省略可能関数(&optionalをつける) (defun optional-arg (a &optional b c) (setq c (or c 20)) ; デフォルト引数もどき (list a b c)) (optional-arg 1) ; => (1 nil 20) (optional-arg 1 2) ; => (1 2 20) (optional-arg 1 2 3) ; …
バッファを見ながら対話的に正規表現を組み立てる機能。
(dolist (ループ変数 リスト式) フォーム1 フォーム2 ...) ;; 返り値: nilwhileよりループのほうが、リストの各要素に対してアクセスするので、 抽象度がワンランク上がっていることに留意する。 ;;; whileをdolistに置き換える (let ((lst '(1 2 3)) result…
public class FileNotFoundException extends IOException指定されたパス名で示されるファイルが開けなかったことを通知する。
;; and 返り値は最後に評価したフォームで、いずれかが偽ならばnil (and t t) ; => t (and nil t) ; => nil (and 1 2) ; => 2 (if 1 2) ; => 2 (and 1 2 3) ; => 3 ;; or 返り値は最後に評価したフォームで、すべて偽ならばnil (or nil nil) ; => nil (or ni…
ifは1つのフォームしか置けないので、prognと併用することで 複数のフォームを置けるが、 if+prognよりも、condを使ったほうがスマート。 (cond (条件式 真フォーム1 真フォーム2 ..) (t 偽フォーム1 偽フォーム2 ..)) 返り値は、最後に評価したフォーム;;if…
(when 条件 真フォーム1 真フォーム2 ..) 最後に評価した真フォーム・条件を満たさないときはnil(unless 条件 偽フォーム1 偽フォーム2 ..) 最後に評価した偽フォーム・条件を満たしたときはnil;;; whenの中が実行される例 (let (msg) (when (= 0 (% 6 2)) ;…
使い捨てコード用のファイルを開く - (rubikitch loves (Emacs Ruby CUI Books))install-elisp-from-emacswikiとかからopen-junk-file.elをインストールして 以下を設定ファイルに記述したらいいと思うよ。 ;;;試行錯誤用ファイルを開くための設定 (require …
list、consか、クオートの3つの方法でリストを作る。 ;;; リストを作る (cons 1 (cons 2 (cons 3 nil))) ; => (1 2 3) (list 1 2 3) ; => (1 2 3) '(1 2 3) ; => (1 2 3) ;; リストに要素を追加するときは前から追加される (setq l (cons 3 nil)) ; => (3) (…