;;; howm-mode.el --- Wiki-like note-taking tool
-;;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2017
-;;; HIRAOKA Kazuyuki <khi@users.sourceforge.jp>
-;;; $Id: howm-mode.el,v 1.318 2012-12-29 08:57:18 hira Exp $
+;;; Copyright (C) 2002, 2003, 2004, 2005-2022
+;;; HIRAOKA Kazuyuki <khi@users.osdn.me>
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;; This must be earlier than (require 'howm-common), because
;; howm-common needs cl, and (require 'cl) should be written in howm.el.
-(when (not (featurep 'howm-version))
+(when (not (featurep 'howm))
(message "Warning: Requiring howm-mode is obsolete. Require howm instead.")
;; (beep)
;; (sit-for 1)
(howm-defvar-risky howm-migemo-client nil
"Command name of migemo-client.
-Try (setq howm-migemo-client \"migemo-client\") for howm-migemo-*.")
+Example of cmigemo:
+ (setq howm-migemo-client '((type . cmigemo) (command . \"cmigemo\")))
+Example of migemo-client (obsolete):
+ (setq howm-migemo-client \"migemo-client\")
+See also `howm-migemo-client-option`")
(howm-defvar-risky howm-migemo-client-option nil
"List of option for migemo-client.
-e.g. (\"-H\" \"::1\")")
+Example of cmigemo:
+ (setq howm-migemo-client-option
+ '(\"-q\" \"-d\" \"/usr/share/cmigemo/utf-8/migemo-dict\"))
+Example of migemo-client (obsolete):
+ (setq howm-migemo-client-option '(\"-H\" \"::1\")
+See also `howm-migemo-client`")
;;; --- level 2 ---
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Definitions
-(easy-mmode-define-minor-mode howm-mode
+(define-minor-mode howm-mode
"With no argument, this command toggles the mode.
Non-null prefix argument turns on the mode.
Null prefix argument turns off the mode.
\\[howm-create-interactively] Create new file interactively (not recommended)
\\[howm-random-walk] Browse random entries automtically
"
- nil ;; default = off
- howm-lighter ;; mode-line
- (mapcar (lambda (entry)
- (let ((k (car entry))
- (f (cadr entry)))
- (cons (concat howm-prefix k) f)))
- howm-default-key-table)
- )
-
-;; emacs20's easy-mmode-define-minor-mode can't have body. sigh...
-(add-hook 'howm-mode-on-hook 'howm-initialize-buffer)
-(add-hook 'howm-mode-off-hook 'howm-restore-buffer)
+ :init-value nil ;; default = off
+ :lighter howm-lighter ;; mode-line
+ :keymap (mapcar (lambda (entry)
+ (let ((k (car entry))
+ (f (cadr entry)))
+ (cons (concat howm-prefix k) f)))
+ howm-default-key-table)
+ (if howm-mode
+ (howm-initialize-buffer)
+ (howm-restore-buffer)))
(defun howm-set-keymap ()
(mapc (lambda (entry)
(howm-list-grep-general t))
(defun howm-list-grep-general (&optional completion-p)
- (let* ((regexp (if completion-p
- (howm-completing-read-keyword)
- (read-from-minibuffer "Search all (grep): "))))
+ (let* ((action (lambda (pattern) (howm-search pattern completion-p)))
+ (regexp (howm-iigrep completion-p action)))
(when completion-p ;; Goto link works only for fixed string at now.
(howm-write-history regexp))
- (howm-search regexp completion-p)))
+ (funcall action regexp)))
-(defun howm-search (regexp fixed-p &optional emacs-regexp filter)
+(defun howm-search (regexp fixed-p &optional emacs-regexp filter bufname)
(if (string= regexp "")
(howm-list-all)
(howm-message-time "search"
(let* ((trio (howm-call-view-search-internal regexp fixed-p emacs-regexp))
(kw (car trio))
- (name (cadr trio))
+ (name (or bufname (cadr trio)))
(items (cl-caddr trio)))
(when filter
(setq items (funcall filter items)))
(howm-normalize-show name items (or emacs-regexp regexp) nil nil kw)
(howm-record-view-window-configuration)))))
+(defun howm-iigrep (completion-p action)
+ (howm-with-iigrep (howm-iigrep-command-for-pattern completion-p)
+ howm-iigrep-show-what action
+ (if completion-p
+ (howm-completing-read-keyword)
+ (read-from-minibuffer "Search all (grep): "))))
+
+(defmacro howm-with-iigrep (command-for-pattern show-what action &rest body)
+ (declare (indent 3))
+ `(let ((*iigrep-post-sentinel* (howm-iigrep-post-sentinel ,action))
+ (howm-view-summary-name "*howmS(preview)*")
+ (howm-view-contents-name "*howmC(preview)*")
+ (howm-history-limit 0)
+ (*howm-show-item-filename* nil)
+ (howm-message-time nil))
+ (unwind-protect
+ (iigrep-with-grep ,command-for-pattern ,show-what
+ ,@body)
+ (mapc (lambda (b) (and (get-buffer b) (kill-buffer b)))
+ (list howm-view-summary-name howm-view-contents-name)))))
+
+(defmacro howm-iigrep-command-for-pattern (&optional fixed-p converter)
+ ;; use macro due to dynamic binding. Sigh...
+ `(and howm-view-use-grep
+ (lambda (str)
+ (let* ((pattern (funcall (or ,converter #'identity) str))
+ (trio (howm-real-grep-single-command
+ pattern (list howm-directory) ,fixed-p))
+ (com (car trio))
+ (args (cl-second trio))
+ (fs (cl-third trio)))
+ (append (list com) (cons "-I" args) fs)))))
+
+(defmacro howm-iigrep-post-sentinel (action)
+ ;; use macro due to dynamic binding. Sigh...
+ `(lambda (hits pattern)
+ (when (<= hits howm-iigrep-preview-items)
+ (save-selected-window
+ (funcall ,action pattern)))))
+
(defvar *howm-view-window-configuration* nil
"For internal use")
(defun howm-view-window-configuration ()
(howm-set-command 'howm-list-migemo)
(if completion-p
(howm-list-grep t)
- (let* ((roma (read-from-minibuffer "Search all (migemo): "))
- (e-reg (howm-migemo-get-pattern roma "emacs"))
- (g-reg (if howm-view-use-grep
- (howm-migemo-get-pattern roma "egrep")
- e-reg)))
- (if (and e-reg g-reg)
- (howm-search g-reg nil e-reg)
- (message "No response from migemo-client.")))))
+ (howm-list-migemo-action (howm-iigrep-migemo))))
+
+(defun howm-list-migemo-action (roma)
+ (let* ((e-reg (howm-migemo-get-pattern roma "emacs"))
+ (g-reg (if howm-view-use-grep
+ (howm-migemo-get-pattern roma "egrep")
+ e-reg)))
+ (if (and e-reg g-reg)
+ (howm-search g-reg nil e-reg nil roma)
+ (message "No response from migemo-client."))))
+
+(defun howm-iigrep-migemo ()
+ (let* ((converter (lambda (yomi) (howm-migemo-get-pattern yomi "egrep")))
+ (command-for-pattern (howm-iigrep-command-for-pattern nil converter))
+ (show-what (if (eq howm-iigrep-migemo-show-what 'inherit)
+ howm-iigrep-show-what
+ howm-iigrep-migemo-show-what)))
+ (howm-with-iigrep command-for-pattern show-what
+ #'howm-list-migemo-action
+ (read-from-minibuffer "Search all (migemo): "))))
(defun howm-migemo-get-pattern (roma type)
(when (and (null howm-migemo-client) (not howm-view-use-grep))
(require 'migemo))
- (if (and (featurep 'migemo) (string= type "emacs"))
- (howm-funcall-if-defined (migemo-get-pattern roma))
-;; (migemo-get-pattern roma)
- (car (howm-call-process (or howm-migemo-client "migemo-client")
- `(,@howm-migemo-client-option "-t" ,type ,roma)
- 0))))
-
-;; (defun howm-migemo-get-pattern (roma type)
-;; (when (and (null (howm-migemo-client)) (not howm-view-use-grep))
-;; (require 'migemo))
-;; (if (and (featurep 'migemo) (string= type "emacs"))
-;; (howm-funcall-if-defined (migemo-get-pattern roma))
-;; ;; (migemo-get-pattern roma)
-;; (car (howm-call-process (howm-migemo-client)
-;; `(,@(howm-migemo-client-option) "-t" ,type ,roma)
-;; 0))))
-
-;; (defun howm-migemo-client ()
-;; (if (stringp howm-migemo-client)
-;; howm-migemo-client
-;; (or (car howm-migemo-client) "migemo-client")))
-
-;; (defun howm-migemo-client-option ()
-;; (cdr-safe howm-migemo-client))
+ (cl-labels ((ref (key) (cdr (assoc key howm-migemo-client))))
+ (cond ((and (featurep 'migemo) (string= type "emacs"))
+ (howm-funcall-if-defined (migemo-get-pattern roma)))
+ ((or (null howm-migemo-client) (stringp howm-migemo-client))
+ (car (howm-call-process (or howm-migemo-client "migemo-client")
+ `(,@howm-migemo-client-option "-t" ,type ,roma)
+ 0)))
+ ((eq (ref 'type) 'cmigemo)
+ (car (howm-call-process (ref 'command)
+ `(,@howm-migemo-client-option
+ ,@(and (string= type "emacs") '("-e"))
+ "-w" ,roma))))
+ (t (error "Invalid howm-migemo-client: %s" howm-migemo-client)))))
(defun howm-normalize-oldp ()
howm-list-normalizer)
(funcall disp-f arg))))
rules))
-;; Use dynamic bindings dirtily!
(defun howm-template-title (arg)
(insert (cdr (assoc 'title arg))))
(defun howm-template-date (arg)