Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lexic.el
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ Using `lexic-current-dictionary-list' and `lexic-dictionary-path'."
(defun lexic-return-from-lexic ()
"Bury lexic buffer and restore the previous window configuration."
(interactive)
(kill-process (get-process lexic-process-name))
(ignore-errors (kill-process (get-process lexic-process-name)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated fix of small annoyance - sometimes pressing 'q' did not bury the buffer, because killing the already dead buffer caused an error

(if (window-configuration-p lexic-previous-window-conf)
(progn
(set-window-configuration lexic-previous-window-conf)
Expand Down Expand Up @@ -652,7 +652,7 @@ Returns a list of plists with keys :word, :dict, and :info."
"When lexic failed to match the word, format the suggestions in RESULTS."
(let (suggestions last-match)
(while (setq last-match
(string-match "^[0-9]+)\\(.*\\)-->\\([A-Za-z]+\\)"
(string-match "^[0-9]+)\\(.*\\)-->\\(.*\\)"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sure to include the whole suggestion, so that it can be searched.
For example when searching for "project" in the "Online Etymology Dictionary", it returns two suggestions:

  • project (n.)
  • project (v.)
    allowing only alpha characters would not work

results
(when last-match (1+ last-match))))
(let ((dict (match-string 1 results))
Expand All @@ -662,21 +662,33 @@ Returns a list of plists with keys :word, :dict, and :info."
(list (append (cadr (assoc dict suggestions)) (list word))))
(setq suggestions (append suggestions `((,dict . ((,word)))))))))
(concat
"\u200B"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a hack(?) to make sure that the point does not get before the first heading (which makes outline navigation not work)

(propertize
(replace-regexp-in-string
"items" "entries"
(substring results 0 (string-match "\n" results)))
'face 'warning)
"\n"
(mapconcat (lambda (dict-suggestions)
(format "\u200B\u200B%s\n\u200B\u200B\u200B%s"
(format "%s\n%s"
(propertize (or
(lexic-dictionary-spec (car dict-suggestions) :short)
(car dict-suggestions))
'face 'outline-3)
(propertize
(mapconcat #'identity (cadr dict-suggestions) "\n\u200B\u200B\u200B")
'face 'font-lock-keyword-face)))
(mapconcat (lambda (entry)
(propertize
(format "\u200B\u200B%s" entry)
;; (mapconcat #'identity (cadr dict-suggestions) "\n\u200B\u200B\u200B")
'face 'font-lock-keyword-face
'keymap (let ((map (make-sparse-keymap)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main part - propertizing the entry with keymap.

(define-key map (kbd "<RET>")
(lambda ()
(interactive)
(lexic-search entry nil (list (car dict-suggestions)) t)
(setq lexic-current-dictionary-list t)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A hack(?) to reset the lexic-current-dictionary-list. Without this, lexic remembers the particular dictionary until called with prefix argument.
Not specifying the dict-list argument of lexic-search results in the "suggestions" buffer again.

map)))
(cadr dict-suggestions)
"\n")))
(sort suggestions
(lambda (a b)
(< (or (lexic-dictionary-spec (car a) :priority) 1)
Expand Down