📄 namazu.el
字号:
(beginning-of-line 2) (let ((start-point (point))) (re-search-forward "^$" nil t) (forward-line -1) ;; there is URL or file name (if (looking-at namazu-output-url-pattern) (forward-line -1)) ;; there is description (if (> (point) start-point) (save-excursion (while (> (point) start-point) (forward-line -1) (insert namazu-header-prefix) (beginning-of-line)) )) ;; there is description (let ((fill-column default-fill-column) (fill-prefix namazu-fill-prefix) (enable-kinsoku nil)) (insert namazu-fill-prefix) (fill-region (point) (save-excursion (forward-line 1) (point)))) ;; $BM>J,$J6u9T$r$H$C$Q$i$&$?$a$NEXNO(B (re-search-forward "^$" nil t) (while (looking-at "^$") (delete-char 1) (forward-line 1)) )))(defun namazu-re-search (&optional key) "$B8=:_$N8!:w%-!<$rJQ99$7$?>e$G:F8!:w$7$^$9!#(B" (interactive (list (save-excursion (read-from-minibuffer "Enter Keyword: " (cons (car namazu-keyword-history) 1) namazu-minibuffer-field-map nil 'namazu-keyword-history)))) (namazu 0 namazu-last-dir key))(defun namazu-next-page () "$B<!$N%Z!<%8$N8!:w7k2L$X0\F0$7$^$9!#(B" (interactive) (if (< namazu-current-page namazu-max-page) (namazu (+ 1 namazu-current-page) namazu-last-dir (car namazu-keyword-history)) t))(defun namazu-prev-page () "$BA0$N%Z!<%8$N8!:w7k2L$X0\F0$7$^$9!#(B" (interactive) (if (> namazu-current-page 0) (namazu (+ -1 namazu-current-page) namazu-last-dir (car namazu-keyword-history)) t))(defun namazu-dir-complete () "$B%G%#%l%/%H%jL>$^$?$O(B namazu-dir-alist $B$+$i$N(B$BJ8;zNsJd40$r9T$$$^$9!#(B" (interactive) (let ((input (buffer-substring 1 (point))) (alist namazu-dir-alist) dir file files compl all sub-input mb) (if (string-match "\\(^\\|\\(\\\\\\\\\\)*[^\\\\] \\)\\(\\(\\(\\\\\\\\\\)*\\\\ \\|[^ ]\\)*/\\)?\\([^/]*\\)$" input) (progn (setq mb (match-end 1)) (save-match-data (setq sub-input (namazu-unescape-dir (substring input mb (match-end 6))))) (save-match-data (setq dir (namazu-unescape-dir (substring input mb (match-beginning 6))))) (setq file (substring input (match-beginning 6) (match-end 6))) ;; HOME $B$+$i$NAjBP%Q%9$N=hM}(B (if (and (string= dir "") (string-match "^~" file)) (progn (setq dir file) (setq file ""))) ;; $B%G%#%l%/%H%j$N>l9g$N=hM}(B (setq files (and (file-exists-p dir) (file-directory-p dir) (directory-files dir t "^[^.]"))) (while files (if (file-directory-p (car files)) (setq alist (append alist (list (cons (concat (car files) "/") (car files)))))) (setq files (cdr files))) ;; Completion-List $B$N:n@.(B (setq compl (or (try-completion sub-input alist) (try-completion (expand-file-name sub-input) alist))) (setq all (or (all-completions sub-input alist) (all-completions (expand-file-name sub-input) alist))) (cond ((stringp compl) (delete-region (+ mb 1) (point-max)) (insert (namazu-escape-dir compl)) (with-output-to-temp-buffer "*Completions*" (display-completion-list all))) (compl nil) (t (beep))) ) (beep))))(defun namazu-escape-dir (dir) "$B%G%#%l%/%H%jCf$N(B \"\\\" $B$H(B \" \" $B$r%(%9%1!<%W$7$^$9!#(B" (let ((tmpdir1 dir) (tmpdir2 "")) (while (string-match "\\([ \\]\\)" tmpdir1) (setq tmpdir2 (concat tmpdir2 (substring tmpdir1 0 (match-beginning 0)) "\\" (substring tmpdir1 (match-beginning 1) (match-end 1)))) (setq tmpdir1 (substring tmpdir1 (match-end 0)))) (concat tmpdir2 tmpdir1)))(defun namazu-unescape-dir (dir) "$B%G%#%l%/%H%jCf$N(B \"\\\" $B$H(B \" \" $B$r%(%9%1!<%W$7$^$9!#(B" (let ((tmpdir1 dir) (tmpdir2 "")) (while (string-match "\\\\\\([ \\]\\)" tmpdir1) (setq tmpdir2 (concat tmpdir2 (substring tmpdir1 0 (match-beginning 0)) (substring tmpdir1 (match-beginning 1) (match-end 1)))) (setq tmpdir1 (substring tmpdir1 (match-end 0)))) (concat tmpdir2 tmpdir1)))(defun namazu-split-dir (dirs) "$B%$%s%G%C%/%9%G%#%l%/%H%jJ8;zNs$rJ,3d$7!"(B\"~\" $B$J$I$rE83+$7$^$9!#(B" (let ((tmpdir1 dirs) (dir-list (list)) (nmz-expand-filename (function (lambda (f) (expand-file-name (namazu-unescape-dir (or (cdr (assoc f namazu-dir-alist)) f))))))) (while (string-match "\\([^\\\\]\\) " tmpdir1) (save-match-data (setq dir-list (append dir-list (list (funcall nmz-expand-filename (substring tmpdir1 0 (match-end 1))))))) (setq tmpdir1 (substring tmpdir1 (match-end 0)))) (if dirs (append dir-list (list (funcall nmz-expand-filename tmpdir1))) dir-list)))(defun namazu-expand-dir-alias (dir) "$B%$%s%G%C%/%9%G%#%l%/%H%jJ8;zNsCf$N%(%$%j%"%9$rE83+$7$^$9!#(B" (and dir namazu-dir-alist (let ((alist namazu-dir-alist)) (while alist (while (string-match (concat "\\(^\\| \\|\t\\)\\(" (regexp-quote (car (car alist))) "\\)\\( \\|\t\\|$\\)") dir) (setq dir (concat (substring dir 0 (match-beginning 2)) (cdr (car alist)) (substring dir (match-beginning 3))))) (setq alist (cdr alist))))) dir)(defun namazu-field-complete () "+to:field $B$NJd40$r$7$^$9!#(B" (interactive) (goto-char (point-max)) (let ((p (point)) (alist (namazu-make-field-completion-alist namazu-last-dir)) (completion-buffer "*Completions*") word start result) (save-excursion (if (re-search-backward "\\+[^ \t]*" nil t) (progn (setq start (match-beginning 0)) (setq word (match-string 0)) (setq result (try-completion word alist))))) (cond ((eq result t) (ding)) ((eq result nil) (ding)) ((string= result word) (with-output-to-temp-buffer completion-buffer (display-completion-list (all-completions word alist)))) (t (delete-region start p) (insert result) (if (eq t (try-completion result alist)) () (ding))))))(defun namazu-make-field-completion-alist (namazu-dirs) "make \'+files:\' completion alist." (let (dir flist fields fname el (dirs (namazu-split-dir (or namazu-dirs namazu-default-dir (setq namazu-default-dir (namazu-get-default-index-dir)))))) (while (setq dir (car dirs)) (if (file-exists-p dir) (setq flist (append (directory-files dir) flist))) (setq dirs (cdr dirs))) (while (setq fname (car flist)) (and (string-match "NMZ.field.\\([^.]+\\)\\'" fname) (setq el (list (format "+%s:" (substring fname (match-beginning 1) (match-end 1))))) (if (not (member el fields)) (setq fields (append (list el) fields)))) (setq flist (cdr flist))) fields))(defun namazu-search-config-file () "Search namazu-config-file-path for a Namazu configuration file.Return the abosolute file name of the configuration. When the file isnot found, return nil " (let ((config-file-list namazu-config-file-path) config-file) (setq config-file-list (delq nil config-file-list)) (if (catch 'found (while config-file-list (setq config-file (expand-file-name (car config-file-list))) (and (file-exists-p config-file) (throw 'found t)) (setq config-file-list (cdr config-file-list)))) config-file nil)))(defun namazu-read-config-file (file) "Read a namazu configuration file and return an alist of directiveand value(s) pairs.FILE indicates the absolute file name of the configuration file. FILEmust exists." (let* (conf-alist (buffer (get-file-buffer file)) (buffer-already-there-p buffer)) (or buffer-already-there-p (setq buffer (find-file-noselect file))) (unwind-protect (save-excursion (set-buffer buffer) (goto-char (point-min)) (let (directive value1 value2) (while (re-search-forward "\\(^[ \t]*\\(INDEX\\|BASE\\|\LOGGING\\|LANG\\|SCORING\\)[ \t]+\\([^ \t\n#]+\\)\\)\\|\\\(^[ \t]*\\(REPLACE\\)[ \t]+\\([^ \t\n#]+\\)[ \t]+\\([^ \t\n#]+\\)\\)" nil t) (cond ((match-string 1) ; only 1 value (setq directive (match-string 2)) (setq value1 (match-string 3)) (setq conf-alist (delete (assoc directive conf-alist) conf-alist)) (setq conf-alist (cons (cons directive value1) conf-alist))) ((match-string 4) ; 2 values (setq directive (match-string 5)) (setq value1 (match-string 6)) (setq value2 (match-string 7)) (setq conf-alist (delete (assoc directive conf-alist) conf-alist)) (setq conf-alist (cons (list directive value1 value2) conf-alist))))))) (if (not buffer-already-there-p) (kill-buffer buffer))) conf-alist))(defun namazu-get-default-index-dir () "Get a Namazu default index directory from a Namazu configuration file.Return \"/usr/local/namazu/index\" if the configuration file is notfound." (let (config-file conf-alist cell dir) (setq config-file (namazu-search-config-file)) (if config-file (progn (setq conf-alist (namazu-read-config-file config-file)) (setq cell (assoc "INDEX" conf-alist)) (and cell (setq dir (cdr cell))) dir) "/usr/local/namazu/index")))(defun namazu-mode () "Namazu $B$N8!:w7k2L$r1\Mw$9$k$?$a$N%b!<%I$G$9!#(Bbinding key------- ---$BA0$N%Z!<%8(B P / h / [left]$BA0$N9`L\(B p / [BkSp] / k / [up] / M-[Tab]$B8e$N9`L\(B n / [Space] / j / [down] / [Tab]$B8e$N%Z!<%8(B N / l / [right]$B%Z!<%8$N@hF,$X(B <$B%Z!<%8$NKvHx$X(B >$BJ8=q$r;2>H(B g / [Enter]$B:F8!:w(B r / f$B8!:w7k2L>C5n(B qNamazu $B=*N;(B Q$B%X%k%WI=<((B ?mouse $B$N??$sCf$N%\%?%s$r2!$9$H!"2!$7$?0LCV$K$h$C$F!"(B\"$BJ8>O$r;2>H(B\"$B!"(B\"$BA0$N%Z!<%8(B\"$B!"(B\"$B8e$m$N%Z!<%8(B\" $B$N$I$l$+$N=hM}$r<B9T$7$^$9!#(B" (interactive) (save-excursion (if (eq major-mode 'namazu-mode) () (kill-all-local-variables) (use-local-map namazu-mode-map) (setq mode-name "Namazu") (setq major-mode 'namazu-mode) (run-hooks 'namazu-mode-hook))))(defun namazu-jump-next () "$B8!:w7k2L$N<!$N9`L\$X0\F0$7$^$9!#(B" (interactive) (let ((pos (point))) (forward-line 1) (if (re-search-forward namazu-output-url-pattern nil t) (beginning-of-line) (goto-char pos) (if (and namazu-auto-turn-page (< namazu-current-page namazu-max-page)) (progn (namazu-next-page) (namazu-jump-next))))))(defun namazu-jump-prev () "$B8!:w7k2L$N0l$DA0$N9`L\$X0\F0$7$^$9!#(B" (interactive) (if (re-search-backward namazu-output-url-pattern nil t) (if (save-excursion (let ((ws (window-start))) (if (re-search-backward "^$" nil t) (and (>= ws (point)) (< 1 (count-lines ws (point)))) nil))) (recenter)) (if (and namazu-auto-turn-page (> namazu-current-page 0)) (progn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -