[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult 11516643e4 1/3: consult-goto-line: Support line
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult 11516643e4 1/3: consult-goto-line: Support line:column input |
Date: |
Mon, 26 Jun 2023 09:57:49 -0400 (EDT) |
branch: externals/consult
commit 11516643e47adf63c1e9f55a0af2aacbc031b2c5
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
consult-goto-line: Support line:column input
---
CHANGELOG.org | 1 +
README.org | 6 ++++--
consult.el | 33 +++++++++++++++++++--------------
3 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/CHANGELOG.org b/CHANGELOG.org
index 134efd9354..8c590e1bb4 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -16,6 +16,7 @@
case sensitive.
- Do not preview remote files by default, see =consult-preview-excluded-files=.
- Use =consult--maybe-recenter= instead of =recenter= in
=consult-after-jump-hook=.
+- =consult-goto-line=: Support =line:column= input.
* Version 0.34 (2023-04-21)
diff --git a/README.org b/README.org
index eef93ea6b7..6b6c466603 100644
--- a/README.org
+++ b/README.org
@@ -179,8 +179,10 @@ their descriptions.
#+findex: consult-outline
#+findex: consult-imenu
#+findex: consult-imenu-multi
-- =consult-goto-line=: Jump to line number enhanced with live preview.
- This is a drop-in replacement for =goto-line=.
+- =consult-goto-line=: Jump to line number enhanced with live preview. This is
a
+ drop-in replacement for =goto-line=. Enter a line number to jump to the first
+ column of the given line. Alternatively enter =line:column= in order to jump
to
+ a specific column.
- =consult-mark=: Jump to a marker in the =mark-ring=. Supports live
preview and recursive editing.
- =consult-global-mark=: Jump to a marker in the =global-mark-ring=.
diff --git a/consult.el b/consult.el
index 14619d50db..971aa07f42 100644
--- a/consult.el
+++ b/consult.el
@@ -3636,31 +3636,36 @@ INITIAL is the initial input."
(defun consult--goto-line-position (str msg)
"Transform input STR to line number.
Print an error message with MSG function."
- (if-let (line (and str
- (string-match-p "\\`[[:digit:]]+\\'" str)
- (string-to-number str)))
- (let ((pos (save-excursion
- (save-restriction
- (when consult-line-numbers-widen
- (widen))
- (goto-char (point-min))
- (forward-line (1- line))
- (point)))))
+ (save-match-data
+ (if (and str (string-match "\\`\\([[:digit:]]+\\):?\\([[:digit:]]*\\)\\'"
str))
+ (let* ((line (string-to-number (match-string 1 str)))
+ (col (string-to-number (match-string 2 str)))
+ (pos (save-excursion
+ (save-restriction
+ (when consult-line-numbers-widen
+ (widen))
+ (goto-char (point-min))
+ (forward-line (1- line))
+ (when (> col 0)
+ (goto-char (min (+ (point) (1- col)) (pos-eol))))
+ (point)))))
(if (consult--in-range-p pos)
pos
(funcall msg "Line number out of range.")
nil))
(when (and str (not (equal str "")))
(funcall msg "Please enter a number."))
- nil))
+ nil)))
;;;###autoload
(defun consult-goto-line (&optional arg)
"Read line number and jump to the line with preview.
-Jump directly if a line number is given as prefix ARG. The command respects
-narrowing and the settings `consult-goto-line-numbers' and
-`consult-line-numbers-widen'."
+Enter either a line number to jump to the first column of the
+given line or line:column in order to jump to a specific column.
+Jump directly if a line number is given as prefix ARG. The
+command respects narrowing and the settings
+`consult-goto-line-numbers' and `consult-line-numbers-widen'."
(interactive "P")
(if arg
(call-interactively #'goto-line)