contrib/gadict.el
changeset 448 a61c140a4b6f
parent 444 70fa100cedef
child 453 ad2b19c9d05d
equal deleted inserted replaced
447:e72fc3940606 448:a61c140a4b6f
   141 (defun gadict-search-floor (headword)
   141 (defun gadict-search-floor (headword)
   142   "Move to HEADWORD definition or place on posiiton for new corresponding
   142   "Move to HEADWORD definition or place on posiiton for new corresponding
   143 definition. Check for headwords ordering during search.
   143 definition. Check for headwords ordering during search.
   144 
   144 
   145 Return `t' if definition found, `nil' if no such headword."
   145 Return `t' if definition found, `nil' if no such headword."
   146   (interactive (list (read-string "Headword: ")))
       
   147   (let ( prev curr )
   146   (let ( prev curr )
   148     (catch 'exit
   147     (catch 'exit
   149       (goto-char (point-min))
   148       (goto-char (point-min))
   150       (unless (re-search-forward "^__$" nil t)
   149       (unless (re-search-forward "^__$" nil t)
   151         (throw 'exit nil))
   150         (throw 'exit nil))
   170           (re-search-backward "^__$")
   169           (re-search-backward "^__$")
   171           (forward-line 2)
   170           (forward-line 2)
   172           (throw 'exit nil))
   171           (throw 'exit nil))
   173         (setq prev curr)) )))
   172         (setq prev curr)) )))
   174 
   173 
       
   174 (defun gadict-search (headword)
       
   175   "Move to HEADWORD definition or place on posiiton for new corresponding
       
   176 definition. Check for headwords ordering during search."
       
   177   (interactive (list (read-string "Headword: ")))
       
   178   (gadict-search-floor headword)
       
   179   (recenter-top-bottom))
       
   180 
   175 (defun gadict-insert-template-in-order (headword)
   181 (defun gadict-insert-template-in-order (headword)
   176   "Insert new article template with respect of headword order."
   182   "Insert new article template with respect of headword order."
   177   (interactive (list (read-string "Headword: ")))
   183   (interactive (list (read-string "Headword: ")))
   178   (unless (gadict-search-floor headword)
   184   (unless (gadict-search-floor headword)
   179     (gadict-insert-template headword))
   185     (gadict-insert-template headword))
   180   (recenter-top-bottom))
   186   (recenter-top-bottom))
   181 
   187 
   182 (defun gadict-setup-keymap ()
   188 (defun gadict-setup-keymap ()
   183   "Setup gadict keymap."
   189   "Setup gadict keymap."
   184   (define-key (current-local-map) [S-return] 'gadict-search-floor)
   190   (define-key (current-local-map) [S-return] 'gadict-search)
   185   (define-key (current-local-map) [C-return] 'gadict-insert-template-in-order))
   191   (define-key (current-local-map) [C-return] 'gadict-insert-template-in-order))
   186 
   192 
   187 ;;;###autoload
   193 ;;;###autoload
   188 (define-derived-mode gadict-mode fundamental-mode "gadict"
   194 (define-derived-mode gadict-mode fundamental-mode "gadict"
   189   "Derived mode for editing gadict dictionary source files."
   195   "Derived mode for editing gadict dictionary source files."