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

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

[nongnu] elpa/dart-mode d1a0c5e 103/192: Fall back to normal expansion


From: ELPA Syncer
Subject: [nongnu] elpa/dart-mode d1a0c5e 103/192: Fall back to normal expansion
Date: Sun, 29 Aug 2021 11:01:59 -0400 (EDT)

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

    Fall back to normal expansion
---
 README.md    |  5 ++++
 dart-mode.el | 98 ++++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 60 insertions(+), 43 deletions(-)

diff --git a/README.md b/README.md
index 3196096..511c721 100644
--- a/README.md
+++ b/README.md
@@ -90,3 +90,8 @@ You can press `M-/` multiple times in a row to cycle through 
possible
 completions.
 
 [dabbrev]: 
https://www.gnu.org/software/emacs/manual/html_node/emacs/Dynamic-Abbrevs.html
+
+If the analysis server isn't enabled for the current buffer, this will fall 
back
+to whatever command is assigned to `M-/` outside of Dart mode (`dabbrev-expand`
+in vanilla Emacs). This will usually pick up any custom key bindings, but if it
+doesn't you can manually choose a fallback by setting the `
diff --git a/dart-mode.el b/dart-mode.el
index 130d9e9..12cf8a3 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -1353,6 +1353,15 @@ to add a header and otherwise prepare it for displaying 
results."
 
 ;;;; Auto-complete
 
+(defcustom dart-expand-fallback (key-binding (kbd "M-/"))
+  "The fallback command to use for `dart-expand'.
+
+This is used when the analysis server isn't available. It
+defaults to the command globally bound to M-/."
+  :group 'dart-mode
+  :type 'function
+  :package-version '(dart-mode . "1.0.0"))
+
 (defvar dart--last-expand-results nil
   "The results of the last call to `dart-expand'.")
 
@@ -1371,49 +1380,52 @@ to add a header and otherwise prepare it for displaying 
results."
 (defun dart-expand ()
   "Expand previous word using Dart's autocompletion."
   (interactive "*")
-  (if (and (eq last-command 'dart-expand) dart--last-expand-results)
-      (progn
-        (incf dart--last-expand-index)
-        (when (>= dart--last-expand-index (length dart--last-expand-results))
-          (setq dart--last-expand-index 0))
-        (dart--use-expand-suggestion
-         dart--last-expand-offset
-         dart--last-expand-length
-         (elt dart--last-expand-results dart--last-expand-index)))
-
-    (when dart--last-expand-subscription
-      (dart--analysis-server-unsubscribe dart--last-expand-subscription))
-    (setq dart--last-expand-results nil)
-    (setq dart--last-expand-offset nil)
-    (setq dart--last-expand-length nil)
-    (setq dart--last-expand-index nil)
-    (setq dart--last-expand-subscription nil)
-
-    (-when-let (filename (buffer-file-name))
-      (dart--analysis-server-send
-       "completion.getSuggestions"
-       `(("file" . ,filename)
-         ("offset" . ,(- (point) 1)))
-       (lexical-let ((buffer (current-buffer)))
-         (lambda (response)
-           (-when-let (result (cdr (assoc 'result response)))
-             (lexical-let ((completion-id (cdr (assoc 'id result)))
-                           (first t))
-               (dart--analysis-server-subscribe
-                "completion.results"
-                (setq dart--last-expand-subscription
-                      (lambda (event subscription)
-                        (dart--json-let event
-                            (id results
-                                (offset replacementOffset)
-                                (length replacementLength)
-                                (is-last isLast))
-                          (when is-last (dart--analysis-server-unsubscribe 
subscription))
-
-                          (when (equal id completion-id)
-                            (with-current-buffer buffer
-                              (dart--handle-completion-event results offset 
length first))
-                            (setq first nil))))))))))))))
+  (if (not dart-enable-analysis-server)
+      (call-interactively dart-expand-fallback t)
+
+    (if (and (eq last-command 'dart-expand) dart--last-expand-results)
+        (progn
+          (incf dart--last-expand-index)
+          (when (>= dart--last-expand-index (length dart--last-expand-results))
+            (setq dart--last-expand-index 0))
+          (dart--use-expand-suggestion
+           dart--last-expand-offset
+           dart--last-expand-length
+           (elt dart--last-expand-results dart--last-expand-index)))
+
+      (when dart--last-expand-subscription
+        (dart--analysis-server-unsubscribe dart--last-expand-subscription))
+      (setq dart--last-expand-results nil)
+      (setq dart--last-expand-offset nil)
+      (setq dart--last-expand-length nil)
+      (setq dart--last-expand-index nil)
+      (setq dart--last-expand-subscription nil)
+
+      (-when-let (filename (buffer-file-name))
+        (dart--analysis-server-send
+         "completion.getSuggestions"
+         `(("file" . ,filename)
+           ("offset" . ,(- (point) 1)))
+         (lexical-let ((buffer (current-buffer)))
+           (lambda (response)
+             (-when-let (result (cdr (assoc 'result response)))
+               (lexical-let ((completion-id (cdr (assoc 'id result)))
+                             (first t))
+                 (dart--analysis-server-subscribe
+                  "completion.results"
+                  (setq dart--last-expand-subscription
+                        (lambda (event subscription)
+                          (dart--json-let event
+                              (id results
+                                  (offset replacementOffset)
+                                  (length replacementLength)
+                                  (is-last isLast))
+                            (when is-last (dart--analysis-server-unsubscribe 
subscription))
+
+                            (when (equal id completion-id)
+                              (with-current-buffer buffer
+                                (dart--handle-completion-event results offset 
length first))
+                              (setq first nil)))))))))))))))
 
 (defun dart--handle-completion-event (results offset length first)
   "Handles a completion results event.



reply via email to

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