Skip to content

Commit 5fa30eb

Browse files
authored
Emacs: Optionally pass -with-values to construct (#1644)
from bcc32/construct-with-values
2 parents 4ba69de + d1891e4 commit 5fa30eb

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

CHANGES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ unreleased
99
- emacs: call merlin-client-logger with "interrupted" if the
1010
merlin binary itself is interrupted, not just the parsing of the
1111
result (#1626).
12-
12+
- emacs: merlin-construct, with a prefix argument, now includes
13+
local values in the completion options. Alternatively, this
14+
behavior can be enabled permanently by customizing
15+
`merlin-construct-with-local-values` (#1644)
1316

1417
merlin 4.9
1518
==========

emacs/merlin.el

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ kill ring and C-d destructures the expression."
209209
`merlin-allow-sit-for' is `t'."
210210
:group 'merlin :type 'boolean)
211211

212+
(defcustom merlin-construct-with-local-values nil
213+
"If non-nil, `merlin-construct' includes values in the local environment.
214+
215+
Otherwise, `merlin-construct' only includes constructors."
216+
:group 'merlin :type 'boolean)
217+
212218
(defalias 'merlin-find-file 'find-file-other-window
213219
"The function called when merlin try to open a file (doesn't apply to
214220
merlin-locate, see `merlin-locate-in-new-window').")
@@ -1458,19 +1464,30 @@ strictly within, or nil if there is no such element."
14581464
(`(,result) (insert-choice result))
14591465
(results (insert-choice (completing-read "Constructor: " results nil t)))))))
14601466

1461-
(defun merlin--construct-point (point)
1462-
"Execute a construct at POINT."
1467+
(defun merlin--construct-point (with-local-values point)
1468+
"Execute a construct at POINT.
1469+
1470+
If WITH-LOCAL-VALUES is non-nil, pass \"-with-values local\" to
1471+
include local values in the candidate list."
14631472
(when-let ((result (merlin-call "construct"
1464-
"-position" (merlin-unmake-point point))))
1473+
"-position" (merlin-unmake-point point)
1474+
"-with-values"
1475+
(if (or with-local-values merlin-construct-with-local-values)
1476+
"local"
1477+
"null"))))
14651478
(let* ((loc (car result))
14661479
(start (cdr (assoc 'start loc)))
14671480
(stop (cdr (assoc 'end loc))))
14681481
(merlin--construct-complete start stop (cadr result)))))
14691482

1470-
(defun merlin-construct ()
1471-
"Construct over the current hole."
1472-
(interactive)
1473-
(merlin--construct-point (point)))
1483+
(defun merlin-construct (&optional arg)
1484+
"Construct over the current hole.
1485+
1486+
With prefix ARG, include local values and not just constructors.
1487+
This is like temporarily setting
1488+
`merlin-construct-with-local-values' non-nil."
1489+
(interactive "P")
1490+
(merlin--construct-point arg (point)))
14741491

14751492

14761493
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)