Skip to content

Instantly share code, notes, and snippets.

@sluchin
Created April 9, 2013 06:04
Show Gist options
  • Save sluchin/5343311 to your computer and use it in GitHub Desktop.
Save sluchin/5343311 to your computer and use it in GitHub Desktop.
;; 標準タグ検索 (etags)
;; M-. 検索, M-* 戻る
(defun exec-tags-command (exec &rest options)
"Execute etags or ctags command."
(if (and (executable-find "find")
(executable-find exec))
(let ((lst '(("l" "[l]isp" "\\(el\\|cl\\)")
("c" "[c],c++" "\\(h\\|c\\|hh\\|cc\\|cpp\\)")
("j" "[j]ava" "java")
("js" "[js]cript" "js")
("p" "[p]erl" "perl")
("py" "[py]thon" "py")
("r" "[r]uby" "rb")
("s" "[s]hell" "sh")
("t" "[t]cl/tk" "\\(tcl\\|tk\\)")
("y" "[y]acc" "\\(y\\|yy\\)")
("h" "[h]tml" "*.html")))
(select "Select language: "))
(dolist (l lst)
(setq select (concat select (car (cdr l)) " ")))
(let* ((default default-directory)
(dir (read-string "Directory: "
default nil default))
(result (read-string select nil nil nil))
(ext (car (cdr (cdr (assoc-string result lst))))))
(if (and (file-directory-p dir) (file-readable-p dir))
(if ext
(let (option-string)
(dolist (option options)
(setq option-string (concat option-string " " option)))
(let (out (cmd (concat
"find " dir
" -type f -regex " "\".*\\." ext "$\"" " | "
exec option-string
(when (string= ext "\\(el\\|cl\\)")
" --exclude=*/undohist/*"))))
(setq out (shell-command-to-string cmd))
(message "%s" cmd)
(unless (string= out "") (message "%s" out))))
(message "no such language"))
(message "no such directory: %s" dir))))
(message "not found %s" exec)))
;; etags
;; タグファイル作成するコマンド (etags)
(defun make-etags ()
"Make etags file."
(interactive)
(exec-tags-command "etags" "-"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment