Skip to content

Commit

Permalink
Refactoring on emacs/merlin-search
Browse files Browse the repository at this point in the history
  • Loading branch information
xvw committed Aug 29, 2024
1 parent 65c7ec3 commit 339c5fa
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions emacs/merlin.el
Original file line number Diff line number Diff line change
Expand Up @@ -1107,33 +1107,33 @@ An ocaml atom is any string containing [a-z_0-9A-Z`.]."
(defun merlin--get-polarity-buff ()
(get-buffer-create merlin-polarity-search-buffer-name))

(defun merlin--render-polarity-result (name type)
(let ((plain-name (string-remove-prefix "Stdlib__" name)))
(concat
(propertize "val " 'face (intern "font-lock-keyword-face"))
(propertize plain-name 'face (intern "font-lock-function-name-face"))
" : "
(propertize type 'face (intern "font-lock-doc-face")))))

(defun merlin--polarity-result-to-list (entry)
(let ((function-name (merlin-completion-entry-text "" entry))
(function-type (merlin-completion-entry-short-description entry)))
(list function-name
(vector (merlin--render-polarity-result function-name function-type)))))

(defun merlin-search (query)
(interactive "sSearch pattern: ")
(let* ((result (merlin--search query))
(entries (cdr (assoc 'entries result)))
(previous-buff (current-buffer)))
(let ((pol-buff (merlin--get-polarity-buff))
(to-entry
(lambda (entry)
(let ((text (merlin-completion-entry-text "" entry))
(type (merlin-completion-entry-short-description entry)))
(list
text
(vector
(concat
(propertize "val " 'face (intern "font-lock-keyword-face"))
(propertize
(string-remove-prefix "Stdlib__" text)
'face (intern "font-lock-function-name-face"))
" : "
(propertize type 'face (intern "font-lock-doc-face"))))))))
(inhibit-read-only t))
(with-current-buffer pol-buff
(switch-to-buffer-other-window pol-buff)
(goto-char 1)
(tabulated-list-mode)
(setq tabulated-list-format [("functions" 100 t)])
(setq tabulated-list-entries (mapcar to-entry entries))
(setq tabulated-list-entries (mapcar 'merlin--polarity-result-to-list entries))
(setq tabulated-list-padding 2)

(face-spec-set 'header-line '((t :weight bold :height 1.2)))
Expand Down

0 comments on commit 339c5fa

Please sign in to comment.