Skip to content

Commit

Permalink
Rename some functions and improve racket--doc
Browse files Browse the repository at this point in the history
Have racket--doc handle the search vs. not cases distinctly, which I
think makes the code clearer. Also, to get search text use plain old
read-from-minibuffer.
  • Loading branch information
greghendershott committed Jul 28, 2024
1 parent 600c4fa commit 64997f5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
28 changes: 15 additions & 13 deletions racket-doc.el
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@

(defun racket--doc (prefix how completions)
"A helper for `racket-xp-documentation' and `racket-repl-documentation'."
(let ((search-p (equal prefix '(16))))
(pcase (racket--symbol-at-point-or-prompt prefix
"Documentation for: "
(unless search-p completions)
search-p)
((and (pred stringp) str)
(if search-p
(racket--search-doc str)
(racket--doc-assert-local-back-end)
(racket--doc-command (when (eq how 'namespace)
(racket--repl-session-id))
how
str))))))
(racket--doc-assert-local-back-end)
(cond
((equal prefix '(16))
(when-let (str (read-from-minibuffer
"Search documentation for text: "))
(racket--search-doc str)))
(t
(when-let (str (racket--symbol-at-point-or-prompt
prefix
"Documentation for: "
completions))
(racket--doc-command (when (eq how 'namespace)
(racket--repl-session-id))
how
str)))))

(defun racket--doc-command (repl-session-id how str)
"A helper for `racket--doc', `racket-xp-describe', and `racket-repl-describe'.
Expand Down
12 changes: 6 additions & 6 deletions racket-xp-complete.el
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
(require 'racket-describe)
(require 'racket-company-doc)

(defvar-local racket--xp-lexical-and-import-binding-completions nil
"A completion table all bindings; for use by a CAPF.
(defvar-local racket--xp-completion-table-all nil
"A completion table of all bindings; for use by a CAPF.
Includes both imports and lexical bindings. Better for use by
`completion-at-point' in an edit buffer, because in general more
Expand All @@ -25,7 +25,7 @@ The table includes category and affixation-function metadata; the
latter shows the module from which an identifier was imported,
when not a lexical binding.")

(defvar-local racket--xp-import-binding-completions nil
(defvar-local racket--xp-completion-table-imports nil
"A completion table of import bindings; for use in minibuffer.
Includes only imports, not lexical bindings. Definitely better
Expand Down Expand Up @@ -55,9 +55,9 @@ The table includes category and affixation-funciton metadata.")
(push (propertize sym 'racket-module mod) all)
(when mod
(push (propertize sym 'racket-module mod) imports)))))
(setq racket--xp-lexical-and-import-binding-completions
(setq racket--xp-completion-table-all
(racket--completion-table all metadata))
(setq racket--xp-import-binding-completions
(setq racket--xp-completion-table-imports
(racket--completion-table imports metadata))))

(defun racket--xp-binding-completion-affixator (strs)
Expand Down Expand Up @@ -115,7 +115,7 @@ Do not `setq' directly; instead call `racket--xp-set-module-completions'.")
(defun racket--xp-capf-bindings (beg end)
(list beg
end
racket--xp-lexical-and-import-binding-completions
racket--xp-completion-table-all
:affixation-function #'racket--xp-binding-completion-affixator
:exclusive 'no
:company-location (racket--xp-make-company-location-proc)
Expand Down
6 changes: 3 additions & 3 deletions racket-xp.el
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ command prefixes you supply.
((and `(,path ,anchor) (guard (not prefix)))
(racket-browse-file-url path anchor))
(_
(racket--doc prefix (buffer-file-name) racket--xp-import-binding-completions))))
(racket--doc prefix (buffer-file-name) racket--xp-completion-table-imports))))

;;; Navigation

Expand Down Expand Up @@ -1033,7 +1033,7 @@ press F1 or C-h in its pop up completion list."
(racket-describe-search)
(pcase (racket--symbol-at-point-or-prompt
prefix "Describe: "
racket--xp-lexical-and-import-binding-completions)
racket--xp-completion-table-all)
((and (pred stringp) str)
;; When user did /not/ supply command prefix to input an
;; arbitrary string, we can look for a racket-xp-doc property
Expand Down Expand Up @@ -1093,7 +1093,7 @@ else returns STR."
(thing-at-point 'symbol)))

(cl-defmethod xref-backend-identifier-completion-table ((_backend (eql racket-xp-xref)))
racket--xp-lexical-and-import-binding-completions)
racket--xp-completion-table-all)

(cl-defmethod xref-backend-definitions ((_backend (eql racket-xp-xref)) str)
;; If xref used `completing-read', then STR will have no text
Expand Down

0 comments on commit 64997f5

Please sign in to comment.