[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.
- [nongnu] elpa/dart-mode 907cba5 095/192: Indicate deprecated hovers, (continued)
- [nongnu] elpa/dart-mode 907cba5 095/192: Indicate deprecated hovers, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 8e09b68 120/192: Exclusively use cl-lib to avoid byte-compilation inconsistencies, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 1249417 108/192: Better handle zero-argument functions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 0277dad 107/192: Include parameter documentation, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 73d0ebc 135/192: Merge branch 'refactor-tests', ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 4feac34 123/192: Make sure to provide the full buffer in dart-add-analysis-overlay, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode e01234a 113/192: Use funcall rather than apply where appropriate, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode eba375b 112/192: Parse JSON arrays as lists, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 905ce53 117/192: Fix a bunch of byte-compilation warnings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 25a0b8a 128/192: Add tests for dart-format, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode d1a0c5e 103/192: Fall back to normal expansion,
ELPA Syncer <=
- [nongnu] elpa/dart-mode 613b311 111/192: Stop using lexical let, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 950d3a8 133/192: Add emacs versions 24.3 and snapshot, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode a4126bd 121/192: Allow s 1.10, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 52034c7 110/192: Add a dart--get helper to make it easier to use JSON, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode f3a7c7b 122/192: Properly tell flycheck when there are no errors, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 1153c53 134/192: Add ert-runner, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 2a95005 159/192: Fix typo in README, regarding M-/ fallback, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c30eaa9 140/192: Specify path to the dart-sdk inside of flutter, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode d9a12e1 151/192: Fontifies function declarations, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode aa628c9 138/192: Remove deprecated analysis server option, ELPA Syncer, 2021/08/29