I am trying to write a minor mode that upon visiting a word, it manipulate it. There is a list of words which is parsed from a file. Here is the problem:
(define-minor-mode auto-gls-mode
"Documentation goes here"
:lighter " AGLS"
;(setq agls-list '("foo" "bar")) <----------works
(setq agls-list (agls-parse-acn-file)) <-------doesn't work
(if auto-gls-mode
(add-hook 'post-self-insert-hook
'agls-check-word nil t)
(remove-hook 'post-self-insert-hook
'agls-check-word t)))
and the hooked function:
(defun agls-check-word ()
"Check if the word is in the list"
(if (= last-command-event 32)
(do-some-stuff)))
The agls-parse-acn-file
is pretty long but in pseudo-elisp reads like this:
(defun agls-parse-acn-file()
;find-file-noselect
;while new-line
;extract keywords
;end
local-list)
simply opens a file by find-file-noselect
, parse it, extract keywords and return a list. The conundrum is that, if populate the list as pointed by arrow the function in add-hook
get called properly. If I use populate the list by calling the parse function, as I type in buffers with minor mode activate, nothing happens (agls-check-word
is not called)
(agls-parse-acn-file)
work? Ifagls-list
doesn't change, you don't need to set its value every time the mode is turned on and off.agls-list
gets populated, however, when I activate the minor mode and type in buffer,agls-check-word
function which is added to hook does not get called. If I use the comment line and set the list in the body ofdefine-minor-mode
and comment the call toagls-parse-acn-file
, then everything goes fine.C-h v post-self-insert-hook
to see ifagls-check-word
is added. Maybe duringagls-parse-acn-file
you change the current buffer? We usually use(with-temp-buffer (insert-file-contents "path/to/file") (parse-the-file))
to read a file, instead offind-file-noselect