Skip to content

Commit ab1eb32

Browse files
committed
Apply syntax highlighting to strings shown in the minibuffer
1 parent 17a87f1 commit ab1eb32

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pyimport.el

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ Preserves pyimport text properties on LINE."
122122
(eq major-mode mode))
123123
(buffer-list)))
124124

125+
(defun pyimport--syntax-highlight (str)
126+
"Apply font-lock properties to a string STR of Python code."
127+
(with-temp-buffer
128+
(insert str)
129+
(delay-mode-hooks (python-mode))
130+
(if (fboundp 'font-lock-ensure)
131+
(font-lock-ensure)
132+
(with-no-warnings
133+
(font-lock-fontify-buffer)))
134+
(buffer-string)))
135+
125136
;;;###autoload
126137
(defun pyimport-insert-missing (prefix)
127138
"Try to insert an import for the symbol at point.
@@ -146,6 +157,10 @@ This is a simple heuristic: we just look for imports in all open Python buffers.
146157
(setq matching-lines
147158
(--map (pyimport--import-simplify it symbol) matching-lines))
148159

160+
;; Syntax highlight, to give a prettier choice in the minibuffer.
161+
(setq matching-lines
162+
(-map #'pyimport--syntax-highlight matching-lines))
163+
149164
;; Sort by string length, because the shortest string is usually best.
150165
(setq matching-lines
151166
(--sort (< (length it) (length other)) matching-lines))

0 commit comments

Comments
 (0)