[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/magit 1d13151c27 27/33: magit-file-region-line-numbers: Ne
From: |
Jonas Bernoulli |
Subject: |
[nongnu] elpa/magit 1d13151c27 27/33: magit-file-region-line-numbers: New function |
Date: |
Thu, 9 Jan 2025 14:10:02 -0500 (EST) |
branch: elpa/magit
commit 1d13151c27f70235a2f1a413f27c02ccab09f289
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
magit-file-region-line-numbers: New function
- Only include line at end of region if at least one character
on that line falls within the region.
- Never include the line after the end of the file. Emacs thinks
there is another line there, but everything else, including Git,
disagrees.
- Use `line-number-at-pos's ABSOLUTE argument instead of `widen'.
- It would have been better to define it in "magit-base.el", if
only `magit-buffer-file-name' were defined this early.
---
lisp/magit-log.el | 16 +---------------
lisp/magit-mode.el | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/lisp/magit-log.el b/lisp/magit-log.el
index 489d3131af..6c0159913c 100644
--- a/lisp/magit-log.el
+++ b/lisp/magit-log.el
@@ -756,21 +756,7 @@ completion candidates."
With a prefix argument or when `--follow' is an active log
argument, then follow renames. When the region is active,
restrict the log to the lines that the region touches."
- (interactive
- (cons current-prefix-arg
- (and (region-active-p)
- (magit-file-relative-name)
- (not (derived-mode-p 'dired-mode))
- (save-restriction
- (widen)
- (list (line-number-at-pos (region-beginning))
- (line-number-at-pos
- (let ((end (region-end)))
- (if (char-after end)
- end
- ;; Ensure that we don't get the line number
- ;; of a trailing newline.
- (1- end)))))))))
+ (interactive (cons current-prefix-arg (magit-file-region-line-numbers)))
(require 'magit)
(if-let ((file (magit-file-relative-name)))
(magit-log-setup-buffer
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index fa81b34035..baf35f88ac 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -1499,6 +1499,22 @@ The additional output can be found in the *Messages*
buffer."
(message " %-50s %f" fn (benchmark-elapse (funcall
fn))))))))
((run-hooks hook))))
+(defun magit-file-region-line-numbers ()
+ "Return the bounds of the region as line numbers.
+The returned value has the form (BEGINNING-LINE END-LINE). If
+the region end at the beginning of a line, do not include that
+line. Avoid including the line after the end of the file."
+ (and (or magit-buffer-file-name buffer-file-name)
+ (region-active-p)
+ (not (= (region-beginning) (region-end) (1+ (buffer-size))))
+ (let ((beg (region-beginning))
+ (end (min (region-end) (buffer-size))))
+ (list (line-number-at-pos beg t)
+ (line-number-at-pos (if (= (magit--bol-position end) end)
+ (max beg (1- end))
+ end)
+ t)))))
+
;;; _
(provide 'magit-mode)
;;; magit-mode.el ends here
- [nongnu] elpa/magit a08b4dd513 06/33: magit-stash--apply-1: Improve presentation of fallback methods, (continued)
- [nongnu] elpa/magit a08b4dd513 06/33: magit-stash--apply-1: Improve presentation of fallback methods, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 929eb4dca5 07/33: magit--run-git-stash: Match all error message, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 92f6d57a0a 10/33: magit-status-show-untracked-files: New option, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 816fc35c96 11/33: Move definition of obsolete variable aliases, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 4c524377f3 14/33: magit-revision--wash-message: Ignore values of wrapped hook functions, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 7f47299581 21/33: Let the byte-compiler check more function references, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit b86fe009e2 19/33: magit-log-wash-summary-hook: New hook, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 3ec4a182a6 26/33: magit--{bolp, eolp, bol-position, eol-position}: New utility functions, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit d0e795f423 31/33: magit-blame-maybe-show-message: Protect against %-specs in format, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 5e05d1b083 20/33: magit-maybe-save-repository-buffers: Add to hooks in their definition, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 1d13151c27 27/33: magit-file-region-line-numbers: New function,
Jonas Bernoulli <=
- [nongnu] elpa/magit 1836c8d841 32/33: Use magit-msg more, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 46c3d8b0ad 33/33: magit-insert-revision-{message, notes}: Set background for whole heading, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 93c0c684a8 13/33: magit-insert-{upstream, push}-branch-header: Remove stray code, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 4d0a38ca87 23/33: magit-file-{line, lines}: Cosmetics, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit b786614cc9 17/33: magit-highlight-squash-markers: New function, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit d6d1bcfeb7 29/33: magit-commit-assert: Call magit-diff-unstaged with magit-diff-arguments, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit bb89386d98 25/33: magit-file-relative-name: Remove special handling of indirect buffers, Jonas Bernoulli, 2025/01/09
- [nongnu] elpa/magit 8b6bb7c7e8 28/33: git-commit.el: Require magit-process, Jonas Bernoulli, 2025/01/09