emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/dart-mode eca3f15 105/192: Add the ability to autocomplete


From: ELPA Syncer
Subject: [nongnu] elpa/dart-mode eca3f15 105/192: Add the ability to autocomplete parameters
Date: Sun, 29 Aug 2021 11:01:59 -0400 (EDT)

branch: elpa/dart-mode
commit eca3f153c058c713a1c2c91f1a067a003130d625
Author: Natalie Weizenbaum <nex342@gmail.com>
Commit: Natalie Weizenbaum <nex342@gmail.com>

    Add the ability to autocomplete parameters
---
 dart-mode.el | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/dart-mode.el b/dart-mode.el
index 180583f..ac4f41c 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -423,6 +423,7 @@ Any stderr is logged using dart-log. Returns nil if the 
exit code is non-0."
 (define-key dart-mode-map (kbd "C-c C-r") 'dart-find-member-refs)
 (define-key dart-mode-map (kbd "C-c C-t") 'dart-find-top-level-decls)
 (define-key dart-mode-map (kbd "M-/") 'dart-expand)
+(define-key dart-mode-map (kbd "M-?") 'dart-expand-parameters)
 
 ;;; CC indentation support
 
@@ -1383,7 +1384,8 @@ defaults to the command globally bound to M-/."
   (if (not dart-enable-analysis-server)
       (call-interactively dart-expand-fallback t)
 
-    (if (and (eq last-command 'dart-expand) dart--last-expand-results)
+    (if (and (memq last-command '(dart-expand dart-expand-parameters))
+             dart--last-expand-results)
         (progn
           (incf dart--last-expand-index)
           (when (>= dart--last-expand-index (length dart--last-expand-results))
@@ -1503,6 +1505,52 @@ If FIRST is non-nil, this is the first completion event 
for this completion."
         (when return-type (insert " → " return-type)))
       (buffer-string))))
 
+(defun dart-expand-parameters ()
+  "Adds parameters to the currently-selected `dart-expand' completion.
+
+This will select the first parameter, if one exists."
+  (interactive "*")
+  (when (and (eq last-command 'dart-expand)
+             dart--last-expand-results)
+    (dart--json-let (elt dart--last-expand-results dart--last-expand-index)
+        ((parameter-names parameterNames)
+         (argument-string defaultArgumentListString)
+         (argument-ranges defaultArgumentListTextRanges))
+      (when parameter-names
+        (setq argument-string (or argument-string ""))
+        (setq argument-ranges (or argument-ranges [0 0]))
+
+        (save-excursion
+          (insert ?\( argument-string ?\)))
+        (incf dart--last-expand-length (+ (length argument-string) 2))
+
+        (setq transient-mark-mode nil)
+        (forward-char (+ 1 (elt argument-ranges 0)))
+        (push-mark nil t)
+        (forward-char (elt argument-ranges 1))
+
+        ;; Run this in a timer because `activate-mark' doesn't seem to work
+        ;; directly, and because we don't want to disable 
`delete-selection-mode'
+        ;; after this command.
+        (run-at-time
+         "0 sec" nil
+         (lambda ()
+           (activate-mark)
+
+           ;; Overwrite the current selection, but don't globally enable
+           ;; delete-selection-mode.
+           (unless delete-selection-mode
+             (delete-selection-mode 1)
+             (add-hook 'post-command-hook 'dart--disable-highlight t t))))))))
+
+(defun dart--disable-highlight ()
+  "Disables `delete-selection-mode' and deactivates the mark.
+
+Also removes this function from `post-command-hook'."
+  (deactivate-mark)
+  (delete-selection-mode 0)
+  (remove-hook 'post-command-hook 'dart--disable-delete-selection-mode t))
+
 
 ;;; Popup Mode
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]