[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil 11913ecee1: evil-find-file-at-point-with-line | suppo
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil 11913ecee1: evil-find-file-at-point-with-line | support column number too (#1566) |
Date: |
Mon, 17 Jan 2022 06:57:53 -0500 (EST) |
branch: elpa/evil
commit 11913ecee10063cd1f53ebb9f4b7ded1e413e83e
Author: Elliott Shugerman <eeshugerman@gmail.com>
Commit: GitHub <noreply@github.com>
evil-find-file-at-point-with-line | support column number too (#1566)
* evil-find-file-at-point-with-line | support column number too
Add support for the <filename>:<line>:<column> format. Previously, given
this format, `column` was treated as line number and `line` was ignored.
* add tests
---
evil-commands.el | 33 ++++++++++++++++++++-------------
evil-tests.el | 36 ++++++++++++++++++++++++++++++++----
2 files changed, 52 insertions(+), 17 deletions(-)
diff --git a/evil-commands.el b/evil-commands.el
index fc1d478c61..a0aa0c0821 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -3538,21 +3538,28 @@ If FORCE is non-nil and MARKS is blank, all local marks
except 0-9 are removed."
(eval-when-compile (require 'ffap))
(evil-define-command evil-find-file-at-point-with-line ()
- "Opens the file at point and goes to line-number."
+ "Opens the file at point and goes to position if present."
(require 'ffap)
(let ((fname (with-no-warnings (ffap-file-at-point))))
- (if fname
- (let ((line
- (save-excursion
- (goto-char (cadr ffap-string-at-point-region))
- (and (re-search-backward ":\\([0-9]+\\)\\="
- (line-beginning-position) t)
- (string-to-number (match-string 1))))))
- (with-no-warnings (find-file-at-point fname))
- (when line
- (goto-char (point-min))
- (forward-line (1- line))))
- (user-error "File does not exist."))))
+ (unless fname
+ (user-error "File does not exist."))
+ (let* ((line-number-pattern ":\\([0-9]+\\)\\=" )
+ (line-and-column-numbers-pattern ":\\([0-9]+\\):\\([0-9]+\\)\\=")
+ (get-number (lambda (pattern match-number)
+ (save-excursion
+ (goto-char (cadr ffap-string-at-point-region))
+ (and (re-search-backward pattern
(line-beginning-position) t)
+ (string-to-number (match-string
match-number))))))
+ (line-number (or (funcall get-number
line-and-column-numbers-pattern 1)
+ (funcall get-number line-number-pattern 1)))
+ (column-number (funcall get-number line-and-column-numbers-pattern
2)))
+ (message "line: %s, column: %s" line-number column-number)
+ (with-no-warnings (find-file-at-point fname))
+ (when line-number
+ (goto-char (point-min))
+ (forward-line (1- line-number))
+ (when column-number
+ (move-to-column (1- column-number)))))))
(evil-define-command evil-find-file-at-point-visual ()
"Find the filename selected by the visual region.
diff --git a/evil-tests.el b/evil-tests.el
index 0c56862ed5..8a5f4b1b91 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -9078,23 +9078,51 @@ Source
(ert-deftest evil-test-find-file ()
:tags '(evil jumps)
- (ert-info ("Normal mode find-file-at-point")
+ (ert-info ("Find file at point (normal state)")
(evil-with-temp-file file-name ""
(evil-test-buffer
(vconcat "i" file-name [escape])
(should (not (equal file-name (buffer-file-name (current-buffer)))))
("gf")
(should (equal file-name (buffer-file-name (current-buffer)))))))
- (ert-info ("Visual mode evil-find-file-at-point-visual")
+ (ert-info ("Find file at point (visual state)")
(evil-with-temp-file file-name ""
(evil-test-buffer
(vconcat "iuser@localhost:" file-name "$" [escape])
(should (not (equal file-name (buffer-file-name (current-buffer)))))
("0f:lvt$gf")
- (should (equal file-name (buffer-file-name (current-buffer))))))))
+ (should (equal file-name (buffer-file-name (current-buffer)))))))
+ (ert-info ("Find file at point with line number")
+ (let* ((line-number 3)
+ (file-content (make-string (* 2 line-number) ?\n)))
+ (evil-with-temp-file file-name (insert file-content)
+ (evil-test-buffer
+ (vconcat "i" file-name (format ":%d" line-number) [escape])
+ (should (and (not (equal file-name (buffer-file-name
(current-buffer))))
+ (not (equal line-number (line-number-at-pos)))))
+ ("gF")
+ (should (and (equal file-name (buffer-file-name (current-buffer)))
+ (equal line-number (line-number-at-pos))))))))
+ (ert-info ("Find file at point with line and column numbers")
+ (let* ((line-number 3)
+ (column-number 5)
+ (file-content (mapconcat 'identity
+ (make-list (* 2 line-number)
+ (make-string (* 2
column-number) ?\s))
+ "\n")))
+ (evil-with-temp-file file-name (insert file-content)
+ (evil-test-buffer
+ (vconcat "i" file-name (format ":%d:%d" line-number column-number)
[escape])
+ (should (and (not (equal file-name (buffer-file-name
(current-buffer))))
+ (not (equal line-number (line-number-at-pos)))
+ (not (equal column-number (current-column)))))
+ ("gF")
+ (should (and (equal file-name (buffer-file-name (current-buffer)))
+ (equal line-number (line-number-at-pos))
+ (equal column-number (1+ (current-column))))))))))
(ert-deftest evil-test-jump-buffers ()
- :tags '(evil jums)
+ :tags '(evil jumps)
(skip-unless nil)
(ert-info ("Test jumping backward and forward across buffers")
(evil-test-buffer
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/evil 11913ecee1: evil-find-file-at-point-with-line | support column number too (#1566),
ELPA Syncer <=