[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/dart-mode 3a73a1f 090/192: Make dart-executable-path resil
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/dart-mode 3a73a1f 090/192: Make dart-executable-path resilient to wrappers |
Date: |
Sun, 29 Aug 2021 11:01:56 -0400 (EDT) |
branch: elpa/dart-mode
commit 3a73a1f736a10bb40afac27a0fe3be7dd4a64533
Author: Natalie Weizenbaum <nex342@gmail.com>
Commit: Natalie Weizenbaum <nex342@gmail.com>
Make dart-executable-path resilient to wrappers
---
CHANGELOG.md | 4 ++
dart-mode.el | 190 +++++++++++++++++++++++++++++++++++++----------------------
2 files changed, 124 insertions(+), 70 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..09dc7a6
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,4 @@
+## 1.0.0
+
+* `dart-executable-path`'s default value is now set correctly even if the
+ executable named `dart` on the user's path is a symlink or a wrapper script.
diff --git a/dart-mode.el b/dart-mode.el
index 1c0e29c..009debe 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -94,6 +94,111 @@
(require 'flycheck)
(require 'json)
+
+;;; Utility functions and macros
+
+(defun dart-beginning-of-statement ()
+ "Moves to the beginning of a Dart statement.
+
+Unlike `c-beginning-of-statement', this handles maps correctly
+and will move to the top level of a bracketed statement."
+ (while
+ (progn
+ (back-to-indentation)
+ (while (eq (char-after) ?})
+ (forward-char)
+ (forward-sexp -1)
+ (back-to-indentation))
+ (when (not (-dart-beginning-of-statement-p)) (forward-line -1)))))
+
+(defun -dart-beginning-of-statement-p ()
+ "Returns whether the point is at the beginning of a statement.
+
+Statements are assumed to begin on their own lines. This returns
+true for positions before the start of the statement, but on its line."
+ (and
+ (save-excursion
+ (skip-syntax-forward " ")
+ (not (or (bolp) (eq (char-after) ?}))))
+ (save-excursion
+ (skip-syntax-backward " ")
+ (when (bolp)
+ (cl-loop do (forward-char -1)
+ while (looking-at "^ *$"))
+ (skip-syntax-backward " ")
+ (cl-case (char-before)
+ ((?} ?\;) t)
+ ((?{) (dart-in-block-p (c-guess-basic-syntax))))))))
+
+(defun dart--goto-line (line)
+ "Move to the specified line."
+ (goto-char (point-min))
+ (forward-line (1- line)))
+
+(defun dart--delete-whole-line (&optional arg)
+ "Delete the current line without putting it in the `kill-ring'.
+Derived from function `kill-whole-line'. ARG is defined as for that
+function."
+ (setq arg (or arg 1))
+ (if (and (> arg 0)
+ (eobp)
+ (save-excursion (forward-visible-line 0) (eobp)))
+ (signal 'end-of-buffer nil))
+ (if (and (< arg 0)
+ (bobp)
+ (save-excursion (end-of-visible-line) (bobp)))
+ (signal 'beginning-of-buffer nil))
+ (cond ((zerop arg)
+ (delete-region (progn (forward-visible-line 0) (point))
+ (progn (end-of-visible-line) (point))))
+ ((< arg 0)
+ (delete-region (progn (end-of-visible-line) (point))
+ (progn (forward-visible-line (1+ arg))
+ (unless (bobp)
+ (backward-char))
+ (point))))
+ (t
+ (delete-region (progn (forward-visible-line 0) (point))
+ (progn (forward-visible-line arg) (point))))))
+
+(defun dart--read-file (filename)
+ "Returns the contents of FILENAME."
+ (with-temp-buffer
+ (insert-file-contents filename)
+ (buffer-string)))
+
+(defmacro dart--with-temp-file (name-variable &rest body)
+ "Creates a temporary file for the duration of BODY.
+Assigns the filename to NAME-VARIABLE. Doesn't change the current buffer.
+Returns the value of the last form in BODY."
+ (declare (indent 1))
+ `(let ((,name-variable (make-temp-file "dart-mode.")))
+ (unwind-protect
+ (progn ,@body)
+ (delete-file ,name-variable))))
+
+(defun dart--run-process (executable &rest args)
+ "Runs EXECUTABLE with ARGS synchronously.
+Returns (STDOUT STDERR EXIT-CODE)."
+ (dart--with-temp-file stderr-file
+ (with-temp-buffer
+ (setq exit-code
+ (apply #'call-process
+ executable nil (list t stderr-file) nil args))
+ (list
+ (buffer-string)
+ (dart--read-file stderr-file)
+ exit-code))))
+
+(defun dart--try-process (executable &rest args)
+ "Like `dart--run-process', but only returns stdout.
+Any stderr is logged using dart-log. Returns nil if the exit code is non-0."
+ (let ((result (apply #'dart--run-process executable args)))
+ (unless (string-empty-p (nth 1 result))
+ (dart-log (format "Error running %S:\n%s" (cons executable args) (nth 1
result))))
+ (if (eq (nth 2 result) 0) (nth 0 result))))
+
+
;;; CC configuration
(c-lang-defconst c-symbol-start
@@ -537,11 +642,24 @@ navigation, and more."
(defvar dart--analysis-server nil
"The instance of the Dart analysis server we are communicating with.")
-(defcustom dart-executable-path (executable-find "dart")
+(defcustom dart-executable-path
+ ;; Use Platform.resolvedExecutable so that this logic works through symlinks
+ ;; and wrapper scripts.
+ (-when-let (dart (executable-find "dart"))
+ (dart--with-temp-file input
+ (with-temp-file input (insert "
+ import 'dart:io';
+
+ void main() {
+ print(Platform.resolvedExecutable);
+ }
+ "))
+ (-when-let (result (dart--try-process dart input))
+ (string-trim result))))
"The absolute path to the 'dart' executable."
:group 'dart-mode
:type 'file
- :package-version '(dart-mode . "0.12"))
+ :package-version '(dart-mode . "1.0.0"))
(defcustom dart-analysis-server-snapshot-path
(when dart-executable-path
@@ -974,74 +1092,6 @@ you save any file, kind of defeating the point of
autoloading."
(when (eq major-mode 'dart-mode) (dartfmt)))
-;;; Utility functions
-
-(defun dart-beginning-of-statement ()
- "Moves to the beginning of a Dart statement.
-
-Unlike `c-beginning-of-statement', this handles maps correctly
-and will move to the top level of a bracketed statement."
- (while
- (progn
- (back-to-indentation)
- (while (eq (char-after) ?})
- (forward-char)
- (forward-sexp -1)
- (back-to-indentation))
- (when (not (-dart-beginning-of-statement-p)) (forward-line -1)))))
-
-(defun -dart-beginning-of-statement-p ()
- "Returns whether the point is at the beginning of a statement.
-
-Statements are assumed to begin on their own lines. This returns
-true for positions before the start of the statement, but on its line."
- (and
- (save-excursion
- (skip-syntax-forward " ")
- (not (or (bolp) (eq (char-after) ?}))))
- (save-excursion
- (skip-syntax-backward " ")
- (when (bolp)
- (cl-loop do (forward-char -1)
- while (looking-at "^ *$"))
- (skip-syntax-backward " ")
- (cl-case (char-before)
- ((?} ?\;) t)
- ((?{) (dart-in-block-p (c-guess-basic-syntax))))))))
-
-(defun dart--goto-line (line)
- "Move to the specified line."
- (goto-char (point-min))
- (forward-line (1- line)))
-
-(defun dart--delete-whole-line (&optional arg)
- "Delete the current line without putting it in the `kill-ring'.
-Derived from function `kill-whole-line'. ARG is defined as for that
-function."
- (setq arg (or arg 1))
- (if (and (> arg 0)
- (eobp)
- (save-excursion (forward-visible-line 0) (eobp)))
- (signal 'end-of-buffer nil))
- (if (and (< arg 0)
- (bobp)
- (save-excursion (end-of-visible-line) (bobp)))
- (signal 'beginning-of-buffer nil))
- (cond ((zerop arg)
- (delete-region (progn (forward-visible-line 0) (point))
- (progn (end-of-visible-line) (point))))
- ((< arg 0)
- (delete-region (progn (end-of-visible-line) (point))
- (progn (forward-visible-line (1+ arg))
- (unless (bobp)
- (backward-char))
- (point))))
- (t
- (delete-region (progn (forward-visible-line 0) (point))
- (progn (forward-visible-line arg) (point))))))
-
-
-
;;; Initialization
;;;###autoload (add-to-list 'auto-mode-alist '("\\.dart\\'" . dart-mode))
- [nongnu] elpa/dart-mode 51b9915 023/192: Fix optional argument fontification., (continued)
- [nongnu] elpa/dart-mode 51b9915 023/192: Fix optional argument fontification., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode f5097c0 027/192: Add a dart-mode-map., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 4232d23 041/192: Actually set the style when initializing the mode., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 2d00ec4 043/192: Properly indent multiline optional parameter lists., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode b1ba925 045/192: arglist-intro should be ++., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode f16c1c1 047/192: Fix an odd indentation bug., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 147f554 063/192: Merge pull request #11 from hterkelsen/dartanalyzer, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 89573d5 067/192: Use a pipe instead of a pty for the analysis server, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 35a794c 086/192: Add workaround for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=18845 (#40), ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 9b11e8f 088/192: Another attempt at fixing byte compilation. (#42), ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 3a73a1f 090/192: Make dart-executable-path resilient to wrappers,
ELPA Syncer <=
- [nongnu] elpa/dart-mode b4e592f 098/192: Add more search commands, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c172f19 106/192: Support completing multiple parameters, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 2b085f5 125/192: Do not fail if Flycheck is not available. (#52), ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c973dea 127/192: Require ‘help-mode’., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 68f7f4f 132/192: Require cl for emacs 24.4, 24.5, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode caa7a19 124/192: Don't error out with revert-buffer, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 199709f 148/192: Removes cc-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode da244c6 144/192: Fixes no such file or directory, dartfmt.exe, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 9db2679 143/192: Fixes invalid file path format on Windows, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 06e2d4b 160/192: Respect font-lock-maximum-decoration, ELPA Syncer, 2021/08/29