[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/javaimp fc39dc0: Use already existing buffer for javaim
From: |
Filipp Gunbin |
Subject: |
[elpa] externals/javaimp fc39dc0: Use already existing buffer for javaimp--get-file-classes, if there is one |
Date: |
Thu, 26 Aug 2021 12:54:47 -0400 (EDT) |
branch: externals/javaimp
commit fc39dc0ffabf6700e9618e0dd282373f9ed3b56d
Author: Filipp Gunbin <fgunbin@fastmail.fm>
Commit: Filipp Gunbin <fgunbin@fastmail.fm>
Use already existing buffer for javaimp--get-file-classes, if there is one
---
javaimp-parse.el | 43 +++++++++++++++++++++++++------------------
javaimp.el | 36 ++++++++++++++++++++----------------
2 files changed, 45 insertions(+), 34 deletions(-)
diff --git a/javaimp-parse.el b/javaimp-parse.el
index cb26b81..d543a62 100644
--- a/javaimp-parse.el
+++ b/javaimp-parse.el
@@ -395,10 +395,13 @@ non-nil. Resets this variable after parsing is done."
;; Functions intended to be called from other parts of javaimp.
(defun javaimp--parse-get-package ()
- (goto-char (point-max))
- (when (javaimp--parse-rsb-keyword
- "^[ \t]*package[ \t]+\\([^ \t;\n]+\\)[ \t]*;" nil t 1)
- (match-string 1)))
+ (save-excursion
+ (save-restriction
+ (widen)
+ (goto-char (point-max))
+ (when (javaimp--parse-rsb-keyword
+ "^[ \t]*package[ \t]+\\([^ \t;\n]+\\)[ \t]*;" nil t 1)
+ (match-string 1)))))
(defun javaimp--parse-get-all-classlikes ()
(mapcar (lambda (scope)
@@ -431,20 +434,24 @@ non-nil. Resets this variable after parsing is done."
(defun javaimp--parse-get-all-scopes (&optional pred parent-pred)
"Return all scopes in the current buffer, optionally filtering
-them with PRED, and their parents with PARENT-PRED."
- (javaimp--parse-all-scopes)
- (let ((pos (point-max))
- scope res)
- (while (setq pos (previous-single-property-change pos
'javaimp-parse-scope))
- (setq scope (get-text-property pos 'javaimp-parse-scope))
- (when (and scope
- (or (null pred)
- (funcall pred scope)))
- (setq scope (javaimp--copy-scope scope))
- (when parent-pred
- (javaimp--filter-scope-parents scope parent-pred))
- (push scope res)))
- res))
+them with PRED, and their parents with PARENT-PRED. Neither of
+them should move point."
+ (save-excursion
+ (save-restriction
+ (widen)
+ (javaimp--parse-all-scopes)
+ (let ((pos (point-max))
+ scope res)
+ (while (setq pos (previous-single-property-change pos
'javaimp-parse-scope))
+ (setq scope (get-text-property pos 'javaimp-parse-scope))
+ (when (and scope
+ (or (null pred)
+ (funcall pred scope)))
+ (setq scope (javaimp--copy-scope scope))
+ (when parent-pred
+ (javaimp--filter-scope-parents scope parent-pred))
+ (push scope res)))
+ res))))
(defun javaimp--parse-update-dirty-pos (beg _end _old-len)
"Function to add to `after-change-functions' hook."
diff --git a/javaimp.el b/javaimp.el
index 4b69d71..c8c7bc8 100644
--- a/javaimp.el
+++ b/javaimp.el
@@ -457,10 +457,7 @@ prefix arg is given, don't do this filtering."
javaimp-additional-source-dirs)))
(defun javaimp--dir-above-current-package ()
- (let ((package (save-excursion
- (save-restriction
- (widen)
- (javaimp--parse-get-package)))))
+ (let ((package (javaimp--parse-get-package)))
(when package
(string-remove-suffix
(mapconcat #'file-name-as-directory
@@ -475,14 +472,23 @@ prefix arg is given, don't do this filtering."
(directory-files-recursively dir
"\\.java\\'")))))
(defun javaimp--get-file-classes (file)
- (with-temp-buffer
- (insert-file-contents file)
- (setq javaimp--parse-dirty-pos (point-min))
- (let ((package (javaimp--parse-get-package)))
- (mapcar (lambda (class)
- (if package
- (concat package "." class)))
- (javaimp--parse-get-all-classlikes)))))
+ (let ((buf (seq-find (lambda (b) (equal (buffer-file-name b) file))
+ (buffer-list))))
+ (if buf
+ (with-current-buffer buf
+ (javaimp--get-file-classes-1))
+ (with-temp-buffer
+ (insert-file-contents file)
+ (setq javaimp--parse-dirty-pos (point-min))
+ (javaimp--get-file-classes-1)))))
+
+(defun javaimp--get-file-classes-1 ()
+ (let ((package (javaimp--parse-get-package)))
+ (mapcar (lambda (class)
+ (if package
+ (concat package "." class)
+ class))
+ (javaimp--parse-get-all-classlikes))))
;; Organizing imports
@@ -618,8 +624,7 @@ the `java-mode-hook':
In future, when we implement a minor / major mode, it will be
done in mode functions automatically."
- (let ((forest (save-excursion
- (javaimp--parse-get-imenu-forest))))
+ (let ((forest (javaimp--parse-get-imenu-forest)))
(cond ((not javaimp-imenu-group-methods)
;; plain list of methods
(let ((entries
@@ -722,8 +727,7 @@ start (`javaimp-scope-start') instead."
(defun javaimp-help-show-scopes ()
"Show scopes in a *javaimp-scopes* buffer."
(interactive)
- (let ((scopes (save-excursion
- (javaimp--parse-get-all-scopes)))
+ (let ((scopes (javaimp--parse-get-all-scopes))
(file buffer-file-name)
(buf (get-buffer-create "*javaimp-scopes*")))
(with-current-buffer buf
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/javaimp fc39dc0: Use already existing buffer for javaimp--get-file-classes, if there is one,
Filipp Gunbin <=