おもしろwebサービス開発日記

Ruby や Rails を中心に、web技術について書いています

find-library-file写経

入門GNU Emacsに書いてあった、load-pathに置いてあるファイルのソースを表示するライブラリを写経した。

(defun find-library-file (library)
  (interactive "sFind library file: ")
  (let ((path (cons "" load-path)) exact match elc test found)
    (while (and (not match) path)
      (setq test (concat (car path) "/" library)
	    match (if (condition-case nil
				     (file-readable-p test)
				     (error nil))
		      test)
	    path (cdr path)))
    (setq path (cons "" load-path))
    (or match
	(while (and (not elc) path)
	  (setq test (concat (car path) "/" library ".elc")
		elc (if (condition-case nil
			    (file-readable-p test)
			  (error nil))
			test)
		path (cdr path))))
    (setq path (cons "" load-path))
    (while (and (not match) path)
      (setq test (concat (car path) "/" library ".el")
	    match (if (condition-case nil
			  (file-readable-p test)
			(error nil))
		      test)
	    path (cdr path)))
    (setq found (or match elc))
    (if found
	(progn
	  (find-file found)
	  (and match elc
	       (message "(library file %s exists)" elc)
	       (sit-for 1))
	  (message "Found Library file %s" found))
      (error "Library file \"%s\" not found." library))))

なんとなくlispの書き方を理解。日本人が英語を勉強するときに、語順の違いに戸惑うのと同じ感じがした。

参考

入門 GNU Emacs 第3版

入門 GNU Emacs 第3版