;; hyperestraier (autoload 'w3m-active-region-or-url-at-point "w3m") (setq hyperestraier-index (expand-file-name "document.index" "~/var")) (setq hyperestraier-display-length 999) (defface hyperestraier-face-url '((((type x w32 mac) (class color)) (:foreground "blue" :underline t :bold t))) "Face url" :group 'hyperestraier-faces) (defface hyperestraier-face-title '((((type x w32 mac) (class color)) (:foreground "darkgreen" :bold t :background "lavender"))) "Face title" :group 'hyperestraier-faces) (setq hyperestraier-mode-map (make-sparse-keymap)) (define-key hyperestraier-mode-map "\C-m" 'hyperestraier-url-open) (define-key hyperestraier-mode-map "\C-i" 'hyperestraier-url-search-forward) (define-key hyperestraier-mode-map "n" 'hyperestraier-url-next) (define-key hyperestraier-mode-map "p" 'hyperestraier-url-previous) (define-key hyperestraier-mode-map " " 'scroll-up) (defun hyperestraier-url-search-forward () "前方にある URL を探索し移動する。" (interactive) (when (not (re-search-forward "URI: " nil t)) (goto-char (point-min)) (when (re-search-forward "URI: " nil t) (message "Wrapped hyperestraier-url-search-forward")))) (defun hyperestraier-url-search-backward () "後方にある URL を探索し移動する。" (interactive) (when (not (re-search-backward "URI: " nil t)) (goto-char (point-max)) (when (re-search-backward "URI: " nil t) (message "Wrapped hyperestraier-url-search-backward"))) (goto-char (+ 5 (point)))) (defun hyperestraier-url-next () "カーソルを次の URL 行に移動する。" (interactive) (forward-line) (hyperestraier-url-search-forward) (recenter '(t))) (defun hyperestraier-url-previous () "カーソルを前の URL 行に移動する。" (interactive) (forward-line -1) (hyperestraier-url-search-backward) (recenter '(t))) (defun hyperestraier-url-open () "カーソル位置の URL 行を emacs-w3m でオープンする。" (interactive) (w3m (w3m-active-region-or-url-at-point) t)) (defun hyperestraier-search () (interactive) (let (string) (if mark-active (setq string (buffer-substring (region-beginning) (region-end))) (setq string (read-from-minibuffer "keyword?:"))) (let ((buffer-name (concat "*HYPERESTRAIER*" string)) point-start point-end) (if (get-buffer buffer-name) (progn (message "cache buffer found.") (switch-to-buffer buffer-name)) (message "searching...") (call-process "estcmd" nil buffer-name t "search" "-vh" "-max" (number-to-string hyperestraier-display-length) hyperestraier-index string) (set-buffer buffer-name) (message "formatting...") (let ((count 0) (i 0)) (goto-char (point-min)) (when (re-search-forward "HIT[\t ]+\\([0-9]+\\)" nil t) (setq count (string-to-number (match-string 1)))) (goto-char (point-min)) (while (setq point-end (re-search-forward "URI: .+" nil t)) (when (setq point-start (+ 5 (re-search-backward "URI:" nil t))) (set-text-properties point-start point-end '(face hyperestraier-face-url)) (forward-line)) (when (setq point-end (re-search-forward "Title: .+" nil t)) (when (setq point-start (+ 7 (re-search-backward "Title:" nil t))) (set-text-properties point-start point-end '(face hyperestraier-face-title)) (beginning-of-line) (setq i (1+ i)) (insert (format "(%4d/%4d)" i count)) (forward-line))))) (goto-char (point-min)) (setq buffer-read-only t) (switch-to-buffer buffer-name) (message "done.") (kill-all-local-variables) (use-local-map hyperestraier-mode-map) (setq mode-name "hyperestraier-mode") (setq major-mode 'hyperestraier-mode) (run-hooks 'hyperestraier-mode-hook))))) (defun HYPERESTRAIER () (interactive) (hyperestraier-search))