| 1 |
;; -*- Mode: Emacs-Lisp -*- |
| 2 |
;; |
| 3 |
;; Mule $B>e$G(B Namazu $B$rMxMQ$7$?8!:w$r9T$&$?$a$N(B elisp $B$G$9!#(B |
| 4 |
;; |
| 5 |
;; $Id: namazu.el,v 1.13 2000-02-24 06:48:33 kose Exp $ |
| 6 |
|
| 7 |
(defconst namazu-version "namazu.el 1.0.3") |
| 8 |
|
| 9 |
;; Namazu $B$K$h$k8!:w7k2L$,;X$9%I%-%e%a%s%H(B($BN`(B)$B$,(B |
| 10 |
;; $B%m!<%+%k%G%#%9%/>e$K$"$k>l9g$K$O$=$l$rD>@\;2>H$7!"(B |
| 11 |
;; $B%M%C%H%o!<%/>e$K$"$k>l9g$K$O(B brouse-url $B$N5!G=$rMQ$$$F(B |
| 12 |
;; $B$=$l$r;2>H$9$k$3$H$,$G$-$^$9!#(B |
| 13 |
;; |
| 14 |
;; $B%m!<%+%k%G%#%9%/>e$N%I%-%e%a%s%H(B($BN`(B)$B$,05=L$7$F$"$k>l9g!"(B |
| 15 |
;; jka-compr $B$N5!G=$rMQ$$$F$=$l$rE83+$7$h$&$H$7$^$9!#(B |
| 16 |
;; |
| 17 |
;; Namazu $B%b!<%I$G$O%m!<%+%k%G%#%9%/$K$J$$%U%!%$%k$X$N(B |
| 18 |
;; $B%"%/%;%9$K$D$$$F$O(B brouse-url $B$K0lG$$7$F$$$^$9!#(B |
| 19 |
;; $B$=$&$$$C$?$o$1$G$9$N$G(B browse-url-browser-function $B$K(B |
| 20 |
;; $BE,@Z$J@_Dj$r$7$F$*$+$J$$$H!"30It$K$"$k%j%=!<%9$r(B |
| 21 |
;; $B;2>H$9$k$3$H$O$G$-$^$;$s!#$?$H$($P$3$s$J@_Dj$r$7$^$9(B: |
| 22 |
;; |
| 23 |
;; (autoload 'namazu "namazu" nil t) |
| 24 |
;; (setq browse-url-browser-function 'browse-url-netscape) |
| 25 |
;; |
| 26 |
;; font-lock $B$d(B hilit19 $B$,%m!<%I$7$F$"$l$P(B |
| 27 |
;; $B8!:w7k2L$O(B($B$$$/$i$+(B)$B2Z$d$+$KI=<($5$l$k$G$7$g$&!#(B |
| 28 |
;; |
| 29 |
;; $BMQ0U$9$kI,MW$,$"$k$+$bCN$l$J$$$b$N(B: |
| 30 |
;; $BA0=R$NDL$j(B browse-url $B$,I,MW$G$9$,!"(B19.28 $B%Y!<%9$N(B Mule $B$K$O(B |
| 31 |
;; $B$3$l$,4^$^$l$F$$$J$$$h$&$G$9!#F1:-$N(B "browse-url-for-emacs-19.28.el" |
| 32 |
;; $B$r$*;H$$2<$5$$!#(B |
| 33 |
;; |
| 34 |
;; $B8!:wJ}K!(B: |
| 35 |
;; $B>e5-$N@_Dj$r=*$($?$i(B M-x namazu $B$H%?%$%W$7$F$/$@$5$$!#(B |
| 36 |
;; $B$9$k$H8!:w$N%-!<(B($B>r7o<0(B)$B$rJ9$$$F$-$^$9$N$G(B namazu $B$H$+(B |
| 37 |
;; ruby & perl $B$H$$$C$?8!:w%-!<$rF~NO$7$^$9!#(B |
| 38 |
;; $BF~NO$r=*$($k$H(B Namazu $B$,5/F0$5$l!"(B |
| 39 |
;; $B8!:w7k2L$rI=<($9$k%P%C%U%!$,:n$i$l$^$9!#(B |
| 40 |
;; $B$3$N%P%C%U%!Fb$G$O0J2<$N%-!<A`:n$,Dj5A$5$l$F$$$^$9!#(B |
| 41 |
;; |
| 42 |
;; $BA0%Z!<%8(B $BA09`(B $B<!9`(B $B<!%Z!<%8(B |
| 43 |
;; $BI8=`(B(1) P p n N |
| 44 |
;; $BI8=`(B(2) [BkSp] [Space] |
| 45 |
;; $BI8=`(B(3) M-[Tab] [Tab] |
| 46 |
;; vi $BIw(B h k j l |
| 47 |
;; $B%+!<%=%k(B [left] [up] [down] [right] |
| 48 |
;; |
| 49 |
;; $B%Z!<%8$N@hF,$X(B < |
| 50 |
;; $B%Z!<%8$NKvHx$X(B > |
| 51 |
;; $B%I%-%e%a%s%H$N;2>H(B g $B$^$?$O(B [Enter] |
| 52 |
;; $B>r7o$rDI2C$7$F:F8!:w(B r |
| 53 |
;; $B8!:w7k2L$N>C5n(B q |
| 54 |
;; namazu $B=*N;(B Q |
| 55 |
;; $B%X%k%WI=<((B ? |
| 56 |
;; |
| 57 |
;; $B$^$?!"(Bmouse $B$N$^$s$J$+$N%\%?%s$r2!$9$H!"2!$7$?0LCV$K$h$C$F!"(B |
| 58 |
;; "$B%I%-%e%a%s%H$N;2>H(B"$B!"(B"$BA0%Z!<%8(B"$B!"(B "$B<!%Z!<%8(B" $B$N$I$l$+$NF0:n$r9T$J(B |
| 59 |
;; $B$$$^$9!#(B |
| 60 |
;; |
| 61 |
;; $B%G%U%)%k%H0J30$N%$%s%G%C%/%9(B(NMZ.*)$B$r;HMQ$7$?$$>l9g$O!"(B |
| 62 |
;; C-u M-x namazu $B$H%?%$%W$9$k$3$H$G%$%s%G%C%/%9$NCV$$$F$"$k%G%#%l%/%H(B |
| 63 |
;; $B%j$r;XDj$9$k$3$H$b=PMh$^$9!#$^$?!"8D!9$N%G%#%l%/%H%j$KBP$7$FJLL>$r(B |
| 64 |
;; $BDj5A$9$k$3$H$b2DG=$G$9!#@_DjNc$J$I>\$7$$$3$H$O(B namazu-dir-alist $B$N(B |
| 65 |
;; $B@bL@$r;2>H$7$F$/$@$5$$(B :-P$B!#(B |
| 66 |
;; |
| 67 |
;; $B:G?7HG$NF~<j$K$D$$$F(B: |
| 68 |
;; namazu.el $B$N:G?7HG$O(B namazu $B$KIUB0$9$k$b$N$d!"(Bnamazu ML $B$J$I$G(B |
| 69 |
;; $BF~<j2DG=$G$9(B. |
| 70 |
;; |
| 71 |
;; $BG[I[>r7o$J$I(B: |
| 72 |
;; $B$3$l$O(B $B$^$D$b$H(B $B$f$-$R$m(B <[email protected]> $B$5$s$,:n@.$7!"(B |
| 73 |
;; $BF1;a$H(B $BGO>l(B $BH%(B <[email protected]> $B$5$s!"(B |
| 74 |
;; $B9bNS(B $BE/(B <[email protected]> $B$5$s!"(B |
| 75 |
;; Toshiaki Tanaka <[email protected]>$B$5$s!"(B |
| 76 |
;; $B1|@>(B $BF#OB(B <[email protected]> $B$5$s$N$46(NO$N2<$G(B |
| 77 |
;; $B$d$^$@(B $B$"$-$i(B <[email protected]> $B$5$s$,2~B$$r2C$($?$b$N$r!"(B |
| 78 |
;; $BEZ20(B $B2mL-(B <[email protected]> $B$5$s!"(B |
| 79 |
;; $BKY8}63B@O:(B <[email protected]> $B$5$sC#$N<8S#7cNe$K$h$j(B |
| 80 |
;; Namazu Project $B$,2~B$$7$F$$$k$b$N$G$9!#(B |
| 81 |
;; $B$$$+$J$k7A$G$NMxMQ!&:FG[I[$K$D$$$F$b8"Mx$NN`$O0l@Z<gD%$7$^$;$s!#(B |
| 82 |
;; $B<+M3$K07$C$F$b$i$C$F9=$$$^$;$s!#(B |
| 83 |
;; |
| 84 |
;; $B$*LsB+(B: |
| 85 |
;; $B$3$l$O2?$i$+$NJ]>Z$rH<$&$b$N$G$O$"$j$^$;$s!#(B |
| 86 |
;; $BDs6!$5$l$k5!G=$r;H$C$?7k2L!"MxMQ<T$,D>@\E*$"$k$$$O4V@\E*$K(B |
| 87 |
;; $BB;32$rHo$C$?$H$7$F$b!"$=$l$O:n<TC#$N4XCN$9$k$H$3$m$G$O$"$j$^$;$s!#(B |
| 88 |
;; $B$"$/$^$G(B at your own risk $B$G$4MxMQ2<$5$$!#(B |
| 89 |
;; |
| 90 |
|
| 91 |
;; CUSTOM emulation derived from BBDB and APEL. |
| 92 |
(eval-and-compile |
| 93 |
(condition-case () |
| 94 |
(require 'custom) |
| 95 |
(error nil)) |
| 96 |
(if (and (featurep 'custom) (fboundp 'custom-declare-variable)) |
| 97 |
nil ;; We've got what we needed |
| 98 |
;; We have the old custom-library, hack around it! |
| 99 |
(defmacro defgroup (&rest args) |
| 100 |
nil) |
| 101 |
(defmacro defcustom (var value doc &rest args) |
| 102 |
(` (defvar (, var) (, value) (, doc)))) |
| 103 |
(defmacro defface (var value doc &rest args) |
| 104 |
(` (make-face (, var)))) |
| 105 |
(defmacro define-widget (&rest args) |
| 106 |
nil))) |
| 107 |
|
| 108 |
(defgroup namazu nil |
| 109 |
"Namazu front-end for Emacs." |
| 110 |
:group 'external) |
| 111 |
|
| 112 |
(defcustom namazu-command "namazu" |
| 113 |
"*Namazu $B$N8!:wMQ%W%m%0%i%`L>$G$9!#(B |
| 114 |
$BDL>o$O(B namazu $B$J$I$G$7$g$&$,!"$=$&$G$O$J$$>l9g$d(B |
| 115 |
PATH $B$,DL$C$F$$$J$$>l9g$K$OE,Ev$J%W%m%0%i%`L>$r;XDj$7$^$9!#(B" |
| 116 |
:type 'string |
| 117 |
:group 'namazu) |
| 118 |
|
| 119 |
(defcustom namazu-search-num 30 |
| 120 |
"*Namazu $B$N8!:w7k2L$r0lEY$KI=<($9$k7o?t$G$9!#(B" |
| 121 |
:type 'integer |
| 122 |
:group 'namazu) |
| 123 |
|
| 124 |
(defcustom namazu-default-dir nil |
| 125 |
"*Namazu $B$,;2>H$9$k%$%s%G%C%/%9$NCV$$$F$"$k%G%#%l%/%H%jL>$G$9!#(B |
| 126 |
$BFC$K;XDj$7$J$1$l$P%G%U%)%k%H$N%$%s%G%C%/%9$r;2>H$7$^$9!#(B |
| 127 |
$BJ#?t$N%$%s%G%C%/%9$r;XDj$9$k>l9g$K$O$=$l$>$l$r6uGr$G6h@Z$C$F$/$@$5$$!#(B" |
| 128 |
:type '(choice |
| 129 |
(item :tag "Auto" :value nil) |
| 130 |
(directory :tag "Default Index")) |
| 131 |
:group 'namazu) |
| 132 |
|
| 133 |
(defcustom namazu-dir-alist nil |
| 134 |
"*$B%$%s%G%C%/%9$,CV$$$F$"$k%G%#%l%/%H%j$K(B |
| 135 |
$B%7%s%\%j%C%/$JL>A0$r$D$1$k$?$a$N(B alist $B$G$9!#(B |
| 136 |
'((\"Namazu\" . \"/usr/doc/namazu/index /var/lib/namazu/index\") |
| 137 |
(\"Ruby\" . \"/usr/doc/ruby/namazu\")) |
| 138 |
$B$J$I$N$h$&$K@_Dj$7$F$*$/$H!"8D!9$N%$%s%G%C%/%9%U%!%$%k$N$"$k(B |
| 139 |
$B%G%#%l%/%H%jL>$r;XDj$9$kBe$o$j$K(B Namazu $B$d(B Ruby $B$H$$$C$?(B |
| 140 |
$B$$$o$PJLL>$r;XDj$9$k$3$H$,$G$-$^$9!#(B |
| 141 |
$BJ#?t$N%$%s%G%C%/%9$r;XDj$9$k>l9g$K$O$=$l$>$l$r6uGr$G6h@Z$C$F$/$@$5$$!#(B" |
| 142 |
:type '(repeat (cons :format "%v" |
| 143 |
(string :tag "Alias") |
| 144 |
(string :tag "Index path"))) |
| 145 |
:group 'namazu) |
| 146 |
|
| 147 |
(defcustom namazu-always-query-index-directory nil |
| 148 |
"*nil $B0J30$NCM$r@_Dj$9$k$H!"?tCM0z?t$,$J$$$H$-$K(B |
| 149 |
$B%$%s%G%C%/%9%U%!%$%k$r;XDj$G$-!"?tCM0z?t$,$"$k$H$-$K(B |
| 150 |
$B%G%U%)%k%H$N%$%s%G%C%/%9$r;2>H$9$k$h$&$K$J$j$^$9!#(B |
| 151 |
$B>o$K%$%s%G%C%/%9%U%!%$%k$r;XDj$7$F8!:w$r9T$$$?$$(B |
| 152 |
$B>l9g$J$I$KJXMx$+$b$7$l$^$;$s!#(B" |
| 153 |
:type 'boolean |
| 154 |
:group 'namazu) |
| 155 |
|
| 156 |
(defcustom namazu-auto-turn-page nil |
| 157 |
"*nil $B0J30$NCM$r@_Dj$9$k$H!"<+F0E*$K%Z!<%8$a$/$j$r$7$^$9!#(B" |
| 158 |
:type 'boolean |
| 159 |
:group 'namazu) |
| 160 |
|
| 161 |
(defcustom namazu-mode-hook nil |
| 162 |
"*Namazu $B%b!<%I$r:n@.$9$k%?%$%_%s%0$G8F$P$l$k(B hook $B$G$9!#(B" |
| 163 |
:type 'hook |
| 164 |
:group 'namazu) |
| 165 |
|
| 166 |
(defcustom namazu-display-hook nil |
| 167 |
"*Namazu $B$N=PNO$rI=<($9$k$H$-$K8F$P$l$k(B hook $B$G$9!#(B" |
| 168 |
:type 'hook |
| 169 |
:group 'namazu) |
| 170 |
|
| 171 |
(defcustom namazu-url-regex "^\\(https?://\\|ftp://\\)" |
| 172 |
"*URL $B$H8+$J$9%U%!%$%kL>$N%Q%?!<%s$r@_Dj$7$^$9!#(B" |
| 173 |
:type 'regexp |
| 174 |
:group 'namazu) |
| 175 |
|
| 176 |
(defcustom namazu-view-function-alist |
| 177 |
'(("[^/]+\\.s?html?" . namazu-browse-url) |
| 178 |
("/Mail\\|News/.*/[1-9][0-9]*$" . namazu-view-msg) |
| 179 |
("man/man" . namazu-man) |
| 180 |
;; ("/usr/local/info/\\|\\.info" . namazu-info) ;; $BL$:n@.(B |
| 181 |
("." . namazu-view-file)) |
| 182 |
"*$B%U%!%$%kL>$N%Q%?!<%s$H$=$l$KBP1~$9$k1\Mw4X?t$r@_Dj$7$^$9!#(B" |
| 183 |
:type '(repeat (cons :format "%v" |
| 184 |
(regexp :tag "Filename Regexp") |
| 185 |
(symbol :tag "Function Name"))) |
| 186 |
:group 'namazu) |
| 187 |
|
| 188 |
(defcustom namazu-view-other-window nil |
| 189 |
"*If non-nil, make an other window when namazu-view." |
| 190 |
:type 'boolean |
| 191 |
:group 'namazu) |
| 192 |
|
| 193 |
(defcustom namazu-view-other-frame nil |
| 194 |
"*If non-nil, make an other frame when namazu-view." |
| 195 |
:type 'boolean |
| 196 |
:group 'namazu) |
| 197 |
|
| 198 |
(defcustom namazu-msg-visible-field (list "subject" "from" "to" "newsgroups" "date") |
| 199 |
"*Visible header list for namazu-view-msg." |
| 200 |
:type '(repeat (string :tag "Header")) |
| 201 |
:group 'namazu) |
| 202 |
|
| 203 |
(defcustom namazu-msg-highlight-function nil |
| 204 |
"*A function, view-msg highlight method. |
| 205 |
e.g. |
| 206 |
namazu-msg-highlight-mew -- use Mew functions(require Mew 1.94 or later)." |
| 207 |
:type '(radio (function-item :tag "use Mew functions" |
| 208 |
:format "%t\n" |
| 209 |
namazu-msg-highlight-mew) |
| 210 |
(function :tag "Other")) |
| 211 |
:group 'namazu) |
| 212 |
|
| 213 |
(defvar namazu-cs-write |
| 214 |
(if (memq system-type '(OS/2 emx windows-nt)) |
| 215 |
(if (> emacs-major-version 19) 'sjis-dos '*sjis*dos) |
| 216 |
(if (> emacs-major-version 19) 'euc-jp '*euc-japan*)) |
| 217 |
"*Coding system for namazu process (output).") |
| 218 |
|
| 219 |
(defvar namazu-cs-read |
| 220 |
(if (> emacs-major-version 19) 'undecided '*autoconv*) |
| 221 |
"*Coding system for namazu process (input).") |
| 222 |
|
| 223 |
(defvar namazu-config-file-path |
| 224 |
(list (getenv "NAMAZUCONFPATH") |
| 225 |
(getenv "NAMAZUCONF") ; obsolete? |
| 226 |
"./.namazurc" |
| 227 |
"~/.namazurc" |
| 228 |
"/usr/local/etc/namazu/namazurc" |
| 229 |
"/usr/local/namazu/lib/namazurc") ;obsolete? |
| 230 |
"*Search path for a Namazu configuration file.") |
| 231 |
|
| 232 |
(defvar namazu-argument "-H" |
| 233 |
"*Namazu $B$N8!:wMQ%W%m%0%i%`$r5/F0$9$k:]$K;XDj$9$k0z?t$G$9!#(B") |
| 234 |
|
| 235 |
;; |
| 236 |
;; $B$3$3$+$i@h$r$$$8$C$F!"AGE($K$J$C$?$i65$($F$/$@$5$$$M!#(B |
| 237 |
;; |
| 238 |
|
| 239 |
(defvar namazu-fill-prefix "\t") |
| 240 |
(defvar namazu-header-prefix " ") |
| 241 |
(defvar namazu-index-history '("")) |
| 242 |
(defvar namazu-keyword-history '("")) |
| 243 |
(defvar namazu-mode-map nil) |
| 244 |
(defvar namazu-minibuffer-map nil) |
| 245 |
(defvar namazu-minibuffer-field-map nil) |
| 246 |
(defvar namazu-buffer "*namazu*") |
| 247 |
(defvar namazu-last-dir nil |
| 248 |
"$B8=:_$N8!:w$G;2>H$7$F$$$k%$%s%G%C%/%9$N:_=h(B") |
| 249 |
(defvar namazu-current-page 0 |
| 250 |
"$B1\MwCf$N8!:w7k2L$N%Z!<%8HV9f(B") |
| 251 |
(defvar namazu-max-page 0 |
| 252 |
"$B8=:_$N8!:w7k2L$N:GBg%Z!<%8HV9f(B") |
| 253 |
(defvar namazu-output-title-pattern |
| 254 |
"^\\([0-9]+\\.\\) \\(.*\\) \\(([^)]*)\\)$" |
| 255 |
"$B8!:w7k2L$NCf$N%I%-%e%a%s%H$N%?%$%H%k$r<($99T$N%Q%?!<%s(B") |
| 256 |
(defvar namazu-output-header-pattern |
| 257 |
(format "^%s\\([^:]+:.*\\)$" namazu-header-prefix) |
| 258 |
"$B8!:w7k2L$NCf$N(B From$B!"(BDate $B%X%C%@$r<($9%Q%?!<%s(B") |
| 259 |
(defvar namazu-output-url-pattern |
| 260 |
"^\\(\\(~?/\\|[a-z]+:\\)[^ ]+\\) \\(.*\\)$" |
| 261 |
"$B8!:w7k2L$NCf$N%I%-%e%a%s%H$N:_=h(B(URL)$B$r<($99T$N%Q%?!<%s(B") |
| 262 |
(defvar namazu-output-current-list-pattern |
| 263 |
"^[^:]+: [0-9]+ - [0-9]+$" |
| 264 |
"$B8!:w7k2L$NCf$N$I$NItJ,$r1\MwCf$+$r<($99T$N%Q%?!<%s(B") |
| 265 |
(defvar namazu-output-pages-pattern |
| 266 |
"^[^:]+: \\(\\[[0-9]+\\]\\)*\\[\\([0-9]+\\)\\]$" |
| 267 |
"$B8!:w7k2L$N%Z!<%8?t$r<($99T$N%Q%?!<%s(B") |
| 268 |
(defvar namazu-view-vismark nil) |
| 269 |
|
| 270 |
(and (locate-library "browse-url") (require 'browse-url)) |
| 271 |
(and (locate-library "jka-compr") (require 'jka-compr)) |
| 272 |
(provide 'namazu) |
| 273 |
|
| 274 |
(defun namazu (&optional page-num namazu-dir key) |
| 275 |
"namazu-command $B$r5/F0$7$F8!:w$r9T$$$^$9!#(B" |
| 276 |
(interactive |
| 277 |
(list |
| 278 |
0 |
| 279 |
(if (or (and (not namazu-always-query-index-directory) current-prefix-arg) |
| 280 |
(and namazu-always-query-index-directory (not current-prefix-arg))) |
| 281 |
(read-from-minibuffer "Namazu index directory: " nil |
| 282 |
namazu-minibuffer-map nil 'namazu-index-history) |
| 283 |
nil) |
| 284 |
(read-from-minibuffer "Enter Keyword: " nil |
| 285 |
namazu-minibuffer-field-map nil 'namazu-keyword-history))) |
| 286 |
(let ((buffer (get-buffer-create namazu-buffer)) |
| 287 |
(dir (or namazu-dir |
| 288 |
(progn |
| 289 |
(or namazu-default-dir |
| 290 |
(setq namazu-default-dir (namazu-get-default-index-dir))) |
| 291 |
(expand-file-name namazu-default-dir)))) |
| 292 |
(arg-list (if (listp namazu-argument) |
| 293 |
namazu-argument (list namazu-argument)))) |
| 294 |
(setq arg-list (append |
| 295 |
arg-list |
| 296 |
(list "-n" (int-to-string namazu-search-num) |
| 297 |
"-w" (int-to-string (* page-num namazu-search-num)) |
| 298 |
key))) |
| 299 |
(if (and dir (not (string= dir "")) (string-match "[^ \t]" dir)) |
| 300 |
(setq arg-list (append arg-list |
| 301 |
(namazu-split-dir (namazu-expand-dir-alias dir))))) |
| 302 |
(set-buffer buffer) |
| 303 |
(setq buffer-read-only nil) |
| 304 |
(buffer-disable-undo (current-buffer)) |
| 305 |
(erase-buffer) |
| 306 |
(message "Namazu running ...") |
| 307 |
(let ((default-process-coding-system (cons namazu-cs-read namazu-cs-write)) |
| 308 |
(process-input-coding-system namazu-cs-read) |
| 309 |
(process-output-coding-system namazu-cs-write) |
| 310 |
(coding-system-for-read namazu-cs-read) |
| 311 |
(coding-system-for-write namazu-cs-write)) |
| 312 |
(apply (function call-process) namazu-command nil t nil arg-list)) |
| 313 |
(if (not (and buffer |
| 314 |
(get-buffer buffer) |
| 315 |
(buffer-name (get-buffer buffer)))) |
| 316 |
(message "Namazu exits with no output") |
| 317 |
(pop-to-buffer buffer) |
| 318 |
(goto-char (point-min)) |
| 319 |
(save-excursion |
| 320 |
(namazu-fill) |
| 321 |
(if (re-search-forward namazu-output-pages-pattern nil t) |
| 322 |
(setq namazu-max-page |
| 323 |
(+ -1 (string-to-int (buffer-substring |
| 324 |
(match-beginning 2) (match-end 2))))) |
| 325 |
(setq namazu-max-page 0))) |
| 326 |
|
| 327 |
;(goto-char (point-min)) |
| 328 |
(setq namazu-current-page page-num) |
| 329 |
(setq namazu-last-dir dir) |
| 330 |
(namazu-mode) |
| 331 |
(setq buffer-read-only t) |
| 332 |
(run-hooks 'namazu-display-hook) |
| 333 |
(message "Namazu running ... done.") ))) |
| 334 |
|
| 335 |
(defun namazu-fill () |
| 336 |
"namazu-command $B$G$N8!:w7k2L$r@07A$7$^$9!#(B" |
| 337 |
(while (re-search-forward "^[0-9]+\. " nil t) |
| 338 |
(beginning-of-line 2) |
| 339 |
(let ((start-point (point))) |
| 340 |
(re-search-forward "^$" nil t) |
| 341 |
(forward-line -1) |
| 342 |
;; there is URL or file name |
| 343 |
(if (looking-at namazu-output-url-pattern) |
| 344 |
(forward-line -1)) |
| 345 |
;; there is description |
| 346 |
(if (> (point) start-point) |
| 347 |
(save-excursion |
| 348 |
(while (> (point) start-point) |
| 349 |
(forward-line -1) |
| 350 |
(insert namazu-header-prefix) |
| 351 |
(beginning-of-line)) |
| 352 |
)) |
| 353 |
;; there is description |
| 354 |
(let ((fill-column default-fill-column) |
| 355 |
(fill-prefix namazu-fill-prefix) |
| 356 |
(enable-kinsoku nil)) |
| 357 |
(insert namazu-fill-prefix) |
| 358 |
(fill-region (point) |
| 359 |
(save-excursion (forward-line 1) (point)))) |
| 360 |
;; $BM>J,$J6u9T$r$H$C$Q$i$&$?$a$NEXNO(B |
| 361 |
(re-search-forward "^$" nil t) |
| 362 |
(while (looking-at "^$") |
| 363 |
(delete-char 1) |
| 364 |
(forward-line 1)) |
| 365 |
))) |
| 366 |
|
| 367 |
(defun namazu-re-search (&optional key) |
| 368 |
"$B8=:_$N8!:w%-!<$rJQ99$7$?>e$G:F8!:w$7$^$9!#(B" |
| 369 |
(interactive |
| 370 |
(list |
| 371 |
(save-excursion |
| 372 |
(read-from-minibuffer "Enter Keyword: " |
| 373 |
(cons (car namazu-keyword-history) 1) |
| 374 |
namazu-minibuffer-field-map |
| 375 |
nil 'namazu-keyword-history)))) |
| 376 |
(namazu 0 namazu-last-dir key)) |
| 377 |
|
| 378 |
(defun namazu-next-page () |
| 379 |
"$B<!$N%Z!<%8$N8!:w7k2L$X0\F0$7$^$9!#(B" |
| 380 |
(interactive) |
| 381 |
(if (< namazu-current-page namazu-max-page) |
| 382 |
(namazu (+ 1 namazu-current-page) namazu-last-dir (car namazu-keyword-history)) |
| 383 |
t)) |
| 384 |
|
| 385 |
(defun namazu-prev-page () |
| 386 |
"$BA0$N%Z!<%8$N8!:w7k2L$X0\F0$7$^$9!#(B" |
| 387 |
(interactive) |
| 388 |
(if (> namazu-current-page 0) |
| 389 |
(namazu (+ -1 namazu-current-page) namazu-last-dir (car namazu-keyword-history)) |
| 390 |
t)) |
| 391 |
|
| 392 |
(defun namazu-dir-complete () |
| 393 |
"$B%G%#%l%/%H%jL>$^$?$O(B namazu-dir-alist $B$+$i$N(B |
| 394 |
$BJ8;zNsJd40$r9T$$$^$9!#(B" |
| 395 |
(interactive) |
| 396 |
(let ((input (buffer-substring 1 (point))) |
| 397 |
(alist namazu-dir-alist) |
| 398 |
dir file files compl all sub-input mb) |
| 399 |
(if (string-match "\\(^\\|\\(\\\\\\\\\\)*[^\\\\] \\)\\(\\(\\(\\\\\\\\\\)*\\\\ \\|[^ ]\\)*/\\)?\\([^/]*\\)$" input) |
| 400 |
(progn |
| 401 |
(setq mb (match-end 1)) |
| 402 |
(save-match-data |
| 403 |
(setq sub-input |
| 404 |
(namazu-unescape-dir |
| 405 |
(substring input mb (match-end 6))))) |
| 406 |
(save-match-data |
| 407 |
(setq dir |
| 408 |
(namazu-unescape-dir |
| 409 |
(substring input mb (match-beginning 6))))) |
| 410 |
(setq file (substring input (match-beginning 6) (match-end 6))) |
| 411 |
;; HOME $B$+$i$NAjBP%Q%9$N=hM}(B |
| 412 |
(if (and (string= dir "") |
| 413 |
(string-match "^~" file)) |
| 414 |
(progn (setq dir file) (setq file ""))) |
| 415 |
;; $B%G%#%l%/%H%j$N>l9g$N=hM}(B |
| 416 |
(setq files (and (file-exists-p dir) |
| 417 |
(file-directory-p dir) |
| 418 |
(directory-files dir t "^[^.]"))) |
| 419 |
(while files |
| 420 |
(if (file-directory-p (car files)) |
| 421 |
(setq alist |
| 422 |
(append alist |
| 423 |
(list (cons (concat (car files) "/") |
| 424 |
(car files)))))) |
| 425 |
(setq files (cdr files))) |
| 426 |
;; Completion-List $B$N:n@.(B |
| 427 |
(setq compl (or (try-completion sub-input alist) |
| 428 |
(try-completion (expand-file-name sub-input) alist))) |
| 429 |
(setq all (or (all-completions sub-input alist) |
| 430 |
(all-completions (expand-file-name sub-input) alist))) |
| 431 |
(cond ((stringp compl) |
| 432 |
(delete-region (+ mb 1) (point-max)) |
| 433 |
(insert (namazu-escape-dir compl)) |
| 434 |
(with-output-to-temp-buffer "*Completions*" |
| 435 |
(display-completion-list all))) |
| 436 |
(compl |
| 437 |
nil) |
| 438 |
(t |
| 439 |
(beep))) |
| 440 |
) |
| 441 |
(beep)))) |
| 442 |
|
| 443 |
(defun namazu-escape-dir (dir) |
| 444 |
"$B%G%#%l%/%H%jCf$N(B \"\\\" $B$H(B \" \" $B$r%(%9%1!<%W$7$^$9!#(B" |
| 445 |
(let ((tmpdir1 dir) (tmpdir2 "")) |
| 446 |
(while (string-match "\\([ \\]\\)" tmpdir1) |
| 447 |
(setq tmpdir2 |
| 448 |
(concat tmpdir2 |
| 449 |
(substring tmpdir1 0 (match-beginning 0)) |
| 450 |
"\\" (substring tmpdir1 |
| 451 |
(match-beginning 1) (match-end 1)))) |
| 452 |
(setq tmpdir1 (substring tmpdir1 (match-end 0)))) |
| 453 |
(concat tmpdir2 tmpdir1))) |
| 454 |
|
| 455 |
(defun namazu-unescape-dir (dir) |
| 456 |
"$B%G%#%l%/%H%jCf$N(B \"\\\" $B$H(B \" \" $B$r%(%9%1!<%W$7$^$9!#(B" |
| 457 |
(let ((tmpdir1 dir) (tmpdir2 "")) |
| 458 |
(while (string-match "\\\\\\([ \\]\\)" tmpdir1) |
| 459 |
(setq tmpdir2 |
| 460 |
(concat tmpdir2 |
| 461 |
(substring tmpdir1 0 (match-beginning 0)) |
| 462 |
(substring tmpdir1 |
| 463 |
(match-beginning 1) (match-end 1)))) |
| 464 |
(setq tmpdir1 (substring tmpdir1 (match-end 0)))) |
| 465 |
(concat tmpdir2 tmpdir1))) |
| 466 |
|
| 467 |
(defun namazu-split-dir (dirs) |
| 468 |
"$B%$%s%G%C%/%9%G%#%l%/%H%jJ8;zNs$rJ,3d$7!"(B\"~\" $B$J$I$rE83+$7$^$9!#(B" |
| 469 |
(let ((tmpdir1 dirs) (dir-list (list)) |
| 470 |
(nmz-expand-filename (function (lambda (f) |
| 471 |
(expand-file-name (namazu-unescape-dir |
| 472 |
(or (cdr (assoc f namazu-dir-alist)) f))))))) |
| 473 |
(while (string-match "\\([^\\\\]\\) " tmpdir1) |
| 474 |
(save-match-data |
| 475 |
(setq dir-list |
| 476 |
(append dir-list |
| 477 |
(list (funcall nmz-expand-filename |
| 478 |
(substring tmpdir1 0 (match-end 1))))))) |
| 479 |
(setq tmpdir1 (substring tmpdir1 (match-end 0)))) |
| 480 |
(if dirs |
| 481 |
(append dir-list (list (funcall nmz-expand-filename tmpdir1))) |
| 482 |
dir-list))) |
| 483 |
|
| 484 |
(defun namazu-expand-dir-alias (dir) |
| 485 |
"$B%$%s%G%C%/%9%G%#%l%/%H%jJ8;zNsCf$N%(%$%j%"%9$rE83+$7$^$9!#(B" |
| 486 |
(and dir namazu-dir-alist |
| 487 |
(let ((alist namazu-dir-alist)) |
| 488 |
(while alist |
| 489 |
(while (string-match |
| 490 |
(concat "\\(^\\| \\|\t\\)\\(" |
| 491 |
(regexp-quote (car (car alist))) |
| 492 |
"\\)\\( \\|\t\\|$\\)") dir) |
| 493 |
(setq dir (concat (substring dir 0 (match-beginning 2)) |
| 494 |
(cdr (car alist)) |
| 495 |
(substring dir (match-beginning 3))))) |
| 496 |
(setq alist (cdr alist))))) |
| 497 |
dir) |
| 498 |
|
| 499 |
(defun namazu-field-complete () |
| 500 |
"+to:field $B$NJd40$r$7$^$9!#(B" |
| 501 |
(interactive) |
| 502 |
(goto-char (point-max)) |
| 503 |
(let ((p (point)) |
| 504 |
(alist (namazu-make-field-completion-alist namazu-last-dir)) |
| 505 |
(completion-buffer "*Completions*") |
| 506 |
word start result) |
| 507 |
(save-excursion |
| 508 |
(if (re-search-backward "\\+[^ \t]*" nil t) |
| 509 |
(progn |
| 510 |
(setq start (match-beginning 0)) |
| 511 |
(setq word (match-string 0)) |
| 512 |
(setq result (try-completion word alist))))) |
| 513 |
(cond |
| 514 |
((eq result t) |
| 515 |
(ding)) |
| 516 |
((eq result nil) |
| 517 |
(ding)) |
| 518 |
((string= result word) |
| 519 |
(with-output-to-temp-buffer completion-buffer |
| 520 |
(display-completion-list |
| 521 |
(all-completions word alist)))) |
| 522 |
(t |
| 523 |
(delete-region start p) |
| 524 |
(insert result) |
| 525 |
(if (eq t (try-completion result alist)) |
| 526 |
() |
| 527 |
(ding)))))) |
| 528 |
|
| 529 |
(defun namazu-make-field-completion-alist (namazu-dirs) |
| 530 |
"make \'+files:\' completion alist." |
| 531 |
(let (dir flist fields fname el |
| 532 |
(dirs (namazu-split-dir |
| 533 |
(or namazu-dirs namazu-default-dir |
| 534 |
(setq namazu-default-dir (namazu-get-default-index-dir)))))) |
| 535 |
(while (setq dir (car dirs)) |
| 536 |
(if (file-exists-p dir) |
| 537 |
(setq flist (append (directory-files dir) flist))) |
| 538 |
(setq dirs (cdr dirs))) |
| 539 |
(while (setq fname (car flist)) |
| 540 |
(and (string-match "NMZ.field.\\([^.]+\\)\\'" fname) |
| 541 |
(setq el (list (format "+%s:" |
| 542 |
(substring fname (match-beginning 1) (match-end 1))))) |
| 543 |
(if (not (member el fields)) |
| 544 |
(setq fields (append (list el) fields)))) |
| 545 |
(setq flist (cdr flist))) |
| 546 |
fields)) |
| 547 |
|
| 548 |
(defun namazu-search-config-file () |
| 549 |
"Search namazu-config-file-path for a Namazu configuration file. |
| 550 |
Return the abosolute file name of the configuration. When the file is |
| 551 |
not found, return nil " |
| 552 |
(let ((config-file-list namazu-config-file-path) config-file) |
| 553 |
(setq config-file-list (delq nil config-file-list)) |
| 554 |
(if (catch 'found |
| 555 |
(while config-file-list |
| 556 |
(setq config-file (expand-file-name (car config-file-list))) |
| 557 |
(and (file-exists-p config-file) |
| 558 |
(throw 'found t)) |
| 559 |
(setq config-file-list (cdr config-file-list)))) |
| 560 |
config-file |
| 561 |
nil))) |
| 562 |
|
| 563 |
(defun namazu-read-config-file (file) |
| 564 |
"Read a namazu configuration file and return an alist of directive |
| 565 |
and value(s) pairs. |
| 566 |
FILE indicates the absolute file name of the configuration file. FILE |
| 567 |
must exists." |
| 568 |
(let* (conf-alist |
| 569 |
(buffer (get-file-buffer file)) |
| 570 |
(buffer-already-there-p buffer)) |
| 571 |
(or buffer-already-there-p |
| 572 |
(setq buffer (find-file-noselect file))) |
| 573 |
(unwind-protect |
| 574 |
(save-excursion |
| 575 |
(set-buffer buffer) |
| 576 |
(goto-char (point-min)) |
| 577 |
(let (directive value1 value2) |
| 578 |
(while (re-search-forward "\\(^[ \t]*\\(INDEX\\|BASE\\|\ |
| 579 |
LOGGING\\|LANG\\|SCORING\\)[ \t]+\\([^ \t\n#]+\\)\\)\\|\ |
| 580 |
\\(^[ \t]*\\(REPLACE\\)[ \t]+\\([^ \t\n#]+\\)[ \t]+\\([^ \t\n#]+\\)\\)" nil t) |
| 581 |
(cond ((match-string 1) ; only 1 value |
| 582 |
(setq directive (match-string 2)) |
| 583 |
(setq value1 (match-string 3)) |
| 584 |
(setq conf-alist |
| 585 |
(delete (assoc directive conf-alist) conf-alist)) |
| 586 |
(setq conf-alist |
| 587 |
(cons (cons directive value1) conf-alist))) |
| 588 |
((match-string 4) ; 2 values |
| 589 |
(setq directive (match-string 5)) |
| 590 |
(setq value1 (match-string 6)) |
| 591 |
(setq value2 (match-string 7)) |
| 592 |
(setq conf-alist |
| 593 |
(delete (assoc directive conf-alist) conf-alist)) |
| 594 |
(setq conf-alist |
| 595 |
(cons (list directive value1 value2) |
| 596 |
conf-alist))))))) |
| 597 |
(if (not buffer-already-there-p) |
| 598 |
(kill-buffer buffer))) |
| 599 |
conf-alist)) |
| 600 |
|
| 601 |
(defun namazu-get-default-index-dir () |
| 602 |
"Get a Namazu default index directory from a Namazu configuration file. |
| 603 |
Return \"/usr/local/namazu/index\" if the configuration file is not |
| 604 |
found." |
| 605 |
(let (config-file conf-alist cell dir) |
| 606 |
(setq config-file (namazu-search-config-file)) |
| 607 |
(if config-file |
| 608 |
(progn |
| 609 |
(setq conf-alist (namazu-read-config-file config-file)) |
| 610 |
(setq cell (assoc "INDEX" conf-alist)) |
| 611 |
(and cell |
| 612 |
(setq dir (cdr cell))) |
| 613 |
dir) |
| 614 |
"/usr/local/namazu/index"))) |
| 615 |
|
| 616 |
(defun namazu-mode () |
| 617 |
"Namazu $B$N8!:w7k2L$r1\Mw$9$k$?$a$N%b!<%I$G$9!#(B |
| 618 |
|
| 619 |
binding key |
| 620 |
------- --- |
| 621 |
$BA0$N%Z!<%8(B P / h / [left] |
| 622 |
$BA0$N9`L\(B p / [BkSp] / k / [up] / M-[Tab] |
| 623 |
$B8e$N9`L\(B n / [Space] / j / [down] / [Tab] |
| 624 |
$B8e$N%Z!<%8(B N / l / [right] |
| 625 |
|
| 626 |
$B%Z!<%8$N@hF,$X(B < |
| 627 |
$B%Z!<%8$NKvHx$X(B > |
| 628 |
$BJ8=q$r;2>H(B g / [Enter] |
| 629 |
$B:F8!:w(B r / f |
| 630 |
$B8!:w7k2L>C5n(B q |
| 631 |
Namazu $B=*N;(B Q |
| 632 |
$B%X%k%WI=<((B ? |
| 633 |
|
| 634 |
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 |
| 635 |
\"$BA0$N%Z!<%8(B\"$B!"(B\"$B8e$m$N%Z!<%8(B\" $B$N$I$l$+$N=hM}$r<B9T$7$^$9!#(B |
| 636 |
" |
| 637 |
(interactive) |
| 638 |
(save-excursion |
| 639 |
(if (eq major-mode 'namazu-mode) |
| 640 |
() |
| 641 |
(kill-all-local-variables) |
| 642 |
(use-local-map namazu-mode-map) |
| 643 |
(setq mode-name "Namazu") |
| 644 |
(setq major-mode 'namazu-mode) |
| 645 |
(run-hooks 'namazu-mode-hook)))) |
| 646 |
|
| 647 |
(defun namazu-jump-next () |
| 648 |
"$B8!:w7k2L$N<!$N9`L\$X0\F0$7$^$9!#(B" |
| 649 |
(interactive) |
| 650 |
(let ((pos (point))) |
| 651 |
(forward-line 1) |
| 652 |
(if (re-search-forward namazu-output-url-pattern nil t) |
| 653 |
(beginning-of-line) |
| 654 |
(goto-char pos) |
| 655 |
(if (and namazu-auto-turn-page |
| 656 |
(< namazu-current-page namazu-max-page)) |
| 657 |
(progn |
| 658 |
(namazu-next-page) |
| 659 |
(namazu-jump-next)))))) |
| 660 |
|
| 661 |
(defun namazu-jump-prev () |
| 662 |
"$B8!:w7k2L$N0l$DA0$N9`L\$X0\F0$7$^$9!#(B" |
| 663 |
(interactive) |
| 664 |
(if (re-search-backward namazu-output-url-pattern nil t) |
| 665 |
(if (save-excursion |
| 666 |
(let ((ws (window-start))) |
| 667 |
(if (re-search-backward "^$" nil t) |
| 668 |
(and (>= ws (point)) |
| 669 |
(< 1 (count-lines ws (point)))) |
| 670 |
nil))) |
| 671 |
(recenter)) |
| 672 |
(if (and namazu-auto-turn-page |
| 673 |
(> namazu-current-page 0)) |
| 674 |
(progn |
| 675 |
(namazu-prev-page) |
| 676 |
(end-of-buffer) |
| 677 |
(namazu-jump-prev))))) |
| 678 |
|
| 679 |
(defun namazu-view-at-mouse (event) |
| 680 |
"mouse $B$r;H$C$F%V%i%&%:$7$?$j%Z!<%8$r0\F0$7$?$j$7$^$9!#(B" |
| 681 |
(interactive "e") |
| 682 |
(set-buffer (event-buffer event)) |
| 683 |
(goto-char (event-point event)) |
| 684 |
(let ((pos (point)) |
| 685 |
pos-title pos-url) |
| 686 |
(end-of-line) |
| 687 |
(and (re-search-backward namazu-output-title-pattern nil t) |
| 688 |
(setq pos-title (point)) |
| 689 |
(goto-char pos) |
| 690 |
(re-search-forward namazu-output-title-pattern nil t) |
| 691 |
(re-search-backward namazu-output-url-pattern nil t) |
| 692 |
(> (point) pos-title) |
| 693 |
(setq pos-url (point)) |
| 694 |
(setq pos (point))) |
| 695 |
(goto-char pos) |
| 696 |
(beginning-of-line) |
| 697 |
(and (not pos-url) |
| 698 |
(re-search-forward namazu-output-url-pattern nil t) |
| 699 |
(setq pos-url (point))) |
| 700 |
(goto-char pos) |
| 701 |
(cond |
| 702 |
((and pos-title pos-url) |
| 703 |
(namazu-view)) |
| 704 |
((and pos-url (> namazu-current-page 0)) |
| 705 |
(namazu-prev-page)) |
| 706 |
((and pos-title (< namazu-current-page namazu-max-page)) |
| 707 |
(namazu-next-page)) |
| 708 |
(t (message "nothing to do."))))) |
| 709 |
|
| 710 |
;; emacs $B8~$1$NDj5A(B |
| 711 |
(eval-and-compile |
| 712 |
(or (fboundp 'event-buffer) |
| 713 |
(defun event-buffer (event) |
| 714 |
(window-buffer (posn-window (event-start event)))))) |
| 715 |
|
| 716 |
(eval-and-compile |
| 717 |
(or (fboundp 'event-point) |
| 718 |
(defun event-point (event) |
| 719 |
(posn-point (event-start event))))) |
| 720 |
|
| 721 |
(eval-and-compile |
| 722 |
(or (fboundp 'match-string) |
| 723 |
(defun match-string (num &optional string) |
| 724 |
(if (match-beginning num) |
| 725 |
(if string |
| 726 |
(substring string (match-beginning num) (match-end num)) |
| 727 |
(buffer-substring (match-beginning num) (match-end num))))))) |
| 728 |
|
| 729 |
(defun namazu-view () |
| 730 |
"$B%]%$%s%H$,0LCV$9$k9`L\$r%V%i%&%:$7$^$9!#(B" |
| 731 |
(interactive) |
| 732 |
(beginning-of-line) |
| 733 |
(if (re-search-forward namazu-output-url-pattern nil t) |
| 734 |
(let ((url (buffer-substring (match-beginning 1) (match-end 1)))) |
| 735 |
(beginning-of-line) |
| 736 |
(sit-for 0) |
| 737 |
(and (string-match "^/\\([a-zA-Z]\\)|\\(/.*\\)$" url) |
| 738 |
;; if DOS/Windows /c|... |
| 739 |
(setq url |
| 740 |
(concat (substring url (match-beginning 1) (match-end 1)) |
| 741 |
":" |
| 742 |
(substring url (match-beginning 2) (match-end 2))))) |
| 743 |
(if (string-match namazu-url-regex url) |
| 744 |
(namazu-browse-url url) |
| 745 |
(let ((ext '("" ".gz" ".Z" "bz2")) |
| 746 |
(fl namazu-view-function-alist) |
| 747 |
(file (expand-file-name url)) (name "") path done) |
| 748 |
(and (string-match "\\(.*\\)\\(#.*\\)$" url) |
| 749 |
(setq file (substring url (match-beginning 1) (match-end 1))) |
| 750 |
(setq name (substring url (match-beginning 2) (match-end 2)))) |
| 751 |
(while (and (null done) ext) |
| 752 |
(setq path (concat file (car ext))) |
| 753 |
(and (file-exists-p path) |
| 754 |
(setq done t) |
| 755 |
(while fl |
| 756 |
(if (string-match (car (car fl)) path) |
| 757 |
(progn |
| 758 |
(funcall (cdr (car fl)) (concat path name)) |
| 759 |
(setq fl nil))) |
| 760 |
(setq fl (cdr fl)))) |
| 761 |
(setq ext (cdr ext)))))))) |
| 762 |
|
| 763 |
(defun namazu-view-file (&optional file) |
| 764 |
"View file function." |
| 765 |
(interactive "fView message: ") |
| 766 |
(if (and window-system namazu-view-other-frame) |
| 767 |
(view-file-other-frame file) |
| 768 |
(if namazu-view-other-window |
| 769 |
(view-file-other-window file) |
| 770 |
(view-file file))) |
| 771 |
;; xxx |
| 772 |
(if (and (boundp 'view-mode-map) view-mode-map) |
| 773 |
(define-key view-mode-map "," 'namazu-view-top)) |
| 774 |
(if (and (boundp 'view-minor-mode-map) view-minor-mode-map) |
| 775 |
(define-key view-minor-mode-map "," 'namazu-view-top)) |
| 776 |
(make-local-variable 'namazu-view-vismark)) |
| 777 |
|
| 778 |
(defun namazu-view-msg (&optional file) |
| 779 |
"View message function." |
| 780 |
(namazu-view-file file) |
| 781 |
(let ((buffer-read-only nil) |
| 782 |
(vis-head "") |
| 783 |
hspos) |
| 784 |
(goto-char (point-min)) |
| 785 |
(if (not (re-search-forward "^$" nil t)) |
| 786 |
() |
| 787 |
(save-excursion |
| 788 |
(save-restriction |
| 789 |
(narrow-to-region (point-min) (point)) |
| 790 |
(mapcar (function |
| 791 |
(lambda (head) |
| 792 |
(goto-char (point-min)) |
| 793 |
(if (not (re-search-forward (concat "^" head ":") nil t)) |
| 794 |
() |
| 795 |
(beginning-of-line) |
| 796 |
(setq hspos (point)) |
| 797 |
(forward-line 1) |
| 798 |
(while (looking-at "^[ \t]+") |
| 799 |
(forward-line 1)) |
| 800 |
(setq vis-head |
| 801 |
(concat vis-head (buffer-substring hspos (point)))) |
| 802 |
(delete-region hspos (point))))) |
| 803 |
namazu-msg-visible-field) |
| 804 |
(goto-char (point-max)) |
| 805 |
(setq namazu-view-vismark (point-marker)) |
| 806 |
(insert vis-head) |
| 807 |
(condition-case err |
| 808 |
(cond |
| 809 |
((fboundp 'mew-header-decode-region) |
| 810 |
(mew-header-decode-region 'text (point-min) (point-max) t)) |
| 811 |
((fboundp 'eword-decode-region) |
| 812 |
(eword-decode-region (point-min) (point-max) t))) |
| 813 |
(error nil)) |
| 814 |
(widen))) |
| 815 |
(goto-char namazu-view-vismark) |
| 816 |
(recenter 0) |
| 817 |
(if namazu-msg-highlight-function |
| 818 |
(funcall namazu-msg-highlight-function)) |
| 819 |
(set-visited-file-name nil) |
| 820 |
(set-buffer-modified-p nil)))) |
| 821 |
|
| 822 |
(defun namazu-view-top () |
| 823 |
"goto namazu view top point." |
| 824 |
(interactive) |
| 825 |
(if (and (boundp 'namazu-view-vismark) |
| 826 |
(markerp namazu-view-vismark)) |
| 827 |
(goto-char namazu-view-vismark) |
| 828 |
(goto-char (point-min))) |
| 829 |
(recenter 0)) |
| 830 |
|
| 831 |
(defun namazu-browse-url (url) |
| 832 |
"browse-url $B$r;H$C$FI=<($7$^$9!#(B |
| 833 |
$B;HMQ$9$k(B browser $B$O(B browse-url-browser-function $B$G;XDj$7$^$9!#(B" |
| 834 |
(interactive) |
| 835 |
(setq url (browse-url-file-url url)) |
| 836 |
(if (fboundp 'browse-url) |
| 837 |
(browse-url url) |
| 838 |
(funcall browse-url-browser-function url))) |
| 839 |
|
| 840 |
(defun namazu-man (file) |
| 841 |
"manual $B$rI=<($7$^$9!#(B" |
| 842 |
(interactive) |
| 843 |
(require 'man) |
| 844 |
(let ((manual-program "nroff -man -h")) |
| 845 |
(Man-getpage-in-background file))) |
| 846 |
|
| 847 |
(defun namazu-exit () |
| 848 |
"namazu $B$r=*N;$7$^$9!#(B" |
| 849 |
(interactive) |
| 850 |
(if (and (get-buffer namazu-buffer) |
| 851 |
(buffer-name (get-buffer namazu-buffer))) |
| 852 |
(kill-buffer namazu-buffer))) |
| 853 |
|
| 854 |
(if namazu-mode-map |
| 855 |
nil |
| 856 |
(setq namazu-mode-map (make-keymap)) |
| 857 |
(suppress-keymap namazu-mode-map) |
| 858 |
(define-key namazu-mode-map "P" 'namazu-prev-page) |
| 859 |
(define-key namazu-mode-map "p" 'namazu-jump-prev) |
| 860 |
(define-key namazu-mode-map "n" 'namazu-jump-next) |
| 861 |
(define-key namazu-mode-map "N" 'namazu-next-page) |
| 862 |
|
| 863 |
(define-key namazu-mode-map "\177" 'namazu-jump-prev) |
| 864 |
(define-key namazu-mode-map " " 'namazu-jump-next) |
| 865 |
|
| 866 |
(define-key namazu-mode-map "\M-\t" 'namazu-jump-prev) |
| 867 |
(define-key namazu-mode-map "\t" 'namazu-jump-next) |
| 868 |
|
| 869 |
(define-key namazu-mode-map "h" 'namazu-prev-page) |
| 870 |
(define-key namazu-mode-map "k" 'namazu-jump-prev) |
| 871 |
(define-key namazu-mode-map "j" 'namazu-jump-next) |
| 872 |
(define-key namazu-mode-map "l" 'namazu-next-page) |
| 873 |
|
| 874 |
(define-key namazu-mode-map [left] 'namazu-prev-page) |
| 875 |
(define-key namazu-mode-map [up] 'namazu-jump-prev) |
| 876 |
(define-key namazu-mode-map [down] 'namazu-jump-next) |
| 877 |
(define-key namazu-mode-map [right] 'namazu-next-page) |
| 878 |
|
| 879 |
(define-key namazu-mode-map "<" 'beginning-of-buffer) |
| 880 |
(define-key namazu-mode-map ">" 'end-of-buffer) |
| 881 |
(define-key namazu-mode-map "\r" 'namazu-view) |
| 882 |
(define-key namazu-mode-map "g" 'namazu-view) |
| 883 |
(define-key namazu-mode-map "r" 'namazu-re-search) |
| 884 |
(define-key namazu-mode-map "q" 'bury-buffer) |
| 885 |
(define-key namazu-mode-map "Q" 'namazu-exit) |
| 886 |
(define-key namazu-mode-map "?" 'describe-mode) |
| 887 |
|
| 888 |
(if (string-match "XEmacs" emacs-version) |
| 889 |
(define-key namazu-mode-map [(button2)] 'namazu-view-at-mouse) |
| 890 |
(define-key namazu-mode-map [mouse-2] 'namazu-view-at-mouse))) |
| 891 |
|
| 892 |
(if namazu-minibuffer-map |
| 893 |
nil |
| 894 |
(let ((map (copy-keymap minibuffer-local-map))) |
| 895 |
(define-key map "\t" 'namazu-dir-complete) |
| 896 |
(setq namazu-minibuffer-map map))) |
| 897 |
|
| 898 |
(if namazu-minibuffer-field-map |
| 899 |
nil |
| 900 |
(let ((map (copy-keymap minibuffer-local-map))) |
| 901 |
(define-key map "\t" 'namazu-field-complete) |
| 902 |
(setq namazu-minibuffer-field-map map))) |
| 903 |
|
| 904 |
(cond |
| 905 |
((featurep 'font-lock) |
| 906 |
(or (boundp 'font-lock-variable-name-face) |
| 907 |
(setq font-lock-variable-name-face font-lock-type-face)) |
| 908 |
(or (boundp 'font-lock-reference-face) |
| 909 |
(setq font-lock-reference-face font-lock-function-name-face)) |
| 910 |
(if (boundp 'font-lock-defaults) |
| 911 |
(progn |
| 912 |
(defvar namazu-font-lock-keywords |
| 913 |
(list |
| 914 |
(list namazu-output-title-pattern |
| 915 |
'(1 font-lock-comment-face) |
| 916 |
'(2 font-lock-keyword-face) |
| 917 |
'(3 font-lock-reference-face)) |
| 918 |
(list namazu-output-header-pattern |
| 919 |
1 'font-lock-variable-name-face) |
| 920 |
(list namazu-output-url-pattern |
| 921 |
'(1 (progn |
| 922 |
(set-text-properties (match-beginning 1) (match-end 1) |
| 923 |
'(mouse-face highlight)) |
| 924 |
font-lock-function-name-face)) |
| 925 |
'(3 font-lock-type-face)) |
| 926 |
(list namazu-output-current-list-pattern |
| 927 |
0 'font-lock-comment-face) |
| 928 |
(list namazu-output-pages-pattern 0 'font-lock-comment-face))) |
| 929 |
(add-hook |
| 930 |
'namazu-display-hook |
| 931 |
(lambda () |
| 932 |
(make-local-variable 'font-lock-defaults) |
| 933 |
(setq font-lock-defaults |
| 934 |
'((namazu-font-lock-keywords) t)) |
| 935 |
(font-lock-mode 1)))) |
| 936 |
(defvar namazu-font-lock-keywords |
| 937 |
(list |
| 938 |
(list namazu-output-title-pattern 1 'font-lock-comment-face) |
| 939 |
(list namazu-output-title-pattern 2 'font-lock-keyword-face) |
| 940 |
(list namazu-output-title-pattern 3 'font-lock-reference-face) |
| 941 |
(list namazu-output-header-pattern 1 'font-lock-variable-name-face) |
| 942 |
(list namazu-output-url-pattern 1 'font-lock-function-name-face) |
| 943 |
(list namazu-output-url-pattern 3 'font-lock-type-face) |
| 944 |
(list namazu-output-current-list-pattern 0 'font-lock-comment-face) |
| 945 |
(list namazu-output-pages-pattern 0 'font-lock-comment-face)) |
| 946 |
"Namazu $B$G$N8!:w7k2L$K$*2=>Q$r$9$k$?$a$N@_Dj$G$9(B. ") |
| 947 |
(add-hook 'namazu-display-hook |
| 948 |
(lambda () |
| 949 |
(setq font-lock-keywords namazu-font-lock-keywords) |
| 950 |
(font-lock-mode 1))))) |
| 951 |
((featurep 'hilit19) |
| 952 |
(if (and (boundp 'hilit-background-mode) |
| 953 |
(eq hilit-background-mode 'dark)) |
| 954 |
(hilit-set-mode-patterns |
| 955 |
'namazu-mode |
| 956 |
(list |
| 957 |
(list namazu-output-title-pattern 1 'red-bold-underline) |
| 958 |
(list namazu-output-title-pattern 2 'yellow-bold) |
| 959 |
(list namazu-output-title-pattern 3 'grey80) |
| 960 |
(list namazu-output-header-pattern 1 'palegreen) |
| 961 |
(list namazu-output-url-pattern 1 'gold-underline) |
| 962 |
(list namazu-output-url-pattern 3 'grey80))) |
| 963 |
(hilit-set-mode-patterns |
| 964 |
'namazu-mode |
| 965 |
(list |
| 966 |
(list namazu-output-title-pattern 1 'red-bold-underline) |
| 967 |
(list namazu-output-title-pattern 2 'purple) |
| 968 |
(list namazu-output-title-pattern 3 'grey40) |
| 969 |
(list namazu-output-header-pattern 1 'DarkGoldenrod) |
| 970 |
(list namazu-output-url-pattern 1 'blue-bold-underline) |
| 971 |
(list namazu-output-url-pattern 3 'grey40)))) |
| 972 |
(add-hook 'namazu-display-hook |
| 973 |
'hilit-rehighlight-buffer-quietly))) |
| 974 |
|
| 975 |
;; Message highlight functions. |
| 976 |
;; e.g. |
| 977 |
;; (setq namazu-msg-highlight-function 'namazu-msg-highlight-mew) |
| 978 |
|
| 979 |
;; |
| 980 |
;; for Mew freak. |
| 981 |
(defun namazu-msg-highlight-mew () |
| 982 |
"namazu message highlight use Mew functions (1.94 or later)." |
| 983 |
(save-excursion |
| 984 |
(condition-case err |
| 985 |
(progn |
| 986 |
(if (not (and (boundp 'mew-version) |
| 987 |
mew-version)) |
| 988 |
(save-excursion |
| 989 |
(require 'mew) |
| 990 |
(mew-init) |
| 991 |
(if (get-buffer mew-buffer-hello) |
| 992 |
(kill-buffer mew-buffer-hello)))) |
| 993 |
(goto-char (point-min)) |
| 994 |
(if (and (fboundp 'mew-highlight-header-region) |
| 995 |
(re-search-forward "^$" nil t)) |
| 996 |
(progn |
| 997 |
(mew-highlight-header-region (point-min) (point)) |
| 998 |
(put-text-property (point) (1+ (point)) 'read-only t))) ;; header-end |
| 999 |
(cond |
| 1000 |
((fboundp 'mew-cite-color) |
| 1001 |
(mew-cite-color)) |
| 1002 |
((fboundp 'mew-highlight-body) |
| 1003 |
(mew-highlight-body))) |
| 1004 |
(and (fboundp 'mew-highlight-url) |
| 1005 |
(mew-highlight-url))) |
| 1006 |
(error nil)))) |
| 1007 |
|
| 1008 |
;; end here. |