[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors b39e963 425/434: Faster line-number-at-po
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors b39e963 425/434: Faster line-number-at-pos calculation |
Date: |
Sat, 7 Aug 2021 09:21:13 -0400 (EDT) |
branch: elpa/multiple-cursors
commit b39e9631d6541de8f32524c26fe922e90776abc1
Author: Renato Ferreira <renatofdds@gmail.com>
Commit: Renato Ferreira <renatofdds@gmail.com>
Faster line-number-at-pos calculation
---
mc-edit-lines.el | 6 +++---
mc-mark-more.el | 4 ++--
multiple-cursors-core.el | 13 +++++++++++++
rectangular-region-mode.el | 6 +++---
4 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/mc-edit-lines.el b/mc-edit-lines.el
index e38d1c1..55772af 100644
--- a/mc-edit-lines.el
+++ b/mc-edit-lines.el
@@ -54,8 +54,8 @@ other non-nil value will cause short lines to be padded."
(error "Mark a set of lines first"))
(mc/remove-fake-cursors)
(let* ((col (current-column))
- (point-line (line-number-at-pos))
- (mark-line (progn (exchange-point-and-mark) (line-number-at-pos)))
+ (point-line (mc/line-number-at-pos))
+ (mark-line (progn (exchange-point-and-mark) (mc/line-number-at-pos)))
(direction (if (< point-line mark-line) :up :down))
(style (cond
;; called from lisp
@@ -71,7 +71,7 @@ other non-nil value will cause short lines to be padded."
(previous-logical-line 1 nil)
(move-to-column col))
;; Add the cursors
- (while (not (eq (line-number-at-pos) point-line))
+ (while (not (eq (mc/line-number-at-pos) point-line))
;; Pad the line
(when (eq style 'pad)
(while (< (current-column) col)
diff --git a/mc-mark-more.el b/mc-mark-more.el
index da8cedf..2e63130 100644
--- a/mc-mark-more.el
+++ b/mc-mark-more.el
@@ -579,8 +579,8 @@ If the region is inactive or on a single line, it will
behave like
(interactive "P")
(if (and (use-region-p)
(not (> (mc/num-cursors) 1))
- (not (= (line-number-at-pos (region-beginning))
- (line-number-at-pos (region-end)))))
+ (not (= (mc/line-number-at-pos (region-beginning))
+ (mc/line-number-at-pos (region-end)))))
(if arg
(call-interactively 'mc/edit-lines)
(call-interactively 'mc/mark-all-in-region))
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index 12e9e75..d93ace9 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -109,6 +109,19 @@
(and (listp cursor-type)
(eq (car cursor-type) 'bar))))
+(defun mc/line-number-at-pos (&optional pos absolute)
+ "Faster implementation of `line-number-at-pos'."
+ (if pos
+ (save-excursion
+ (if absolute
+ (save-restriction
+ (widen)
+ (goto-char pos)
+ (string-to-number (format-mode-line "%l")))
+ (goto-char pos)
+ (string-to-number (format-mode-line "%l"))))
+ (string-to-number (format-mode-line "%l"))))
+
(defun mc/make-cursor-overlay-at-eol (pos)
"Create overlay to look like cursor at end of line."
(let ((overlay (make-overlay pos pos nil nil nil)))
diff --git a/rectangular-region-mode.el b/rectangular-region-mode.el
index 01a078d..d8051cc 100644
--- a/rectangular-region-mode.el
+++ b/rectangular-region-mode.el
@@ -75,9 +75,9 @@ an exceedingly quick way of adding multiple cursors to
multiple lines."
(rrm/remove-rectangular-region-overlays)
(let* ((annoying-arrows-mode nil)
(point-column (current-column))
- (point-line (line-number-at-pos))
+ (point-line (mc/line-number-at-pos))
(anchor-column (save-excursion (goto-char rrm/anchor)
(current-column)))
- (anchor-line (save-excursion (goto-char rrm/anchor)
(line-number-at-pos)))
+ (anchor-line (save-excursion (goto-char rrm/anchor)
(mc/line-number-at-pos)))
(left-column (if (< point-column anchor-column) point-column
anchor-column))
(right-column (if (> point-column anchor-column) point-column
anchor-column))
(navigation-step (if (< point-line anchor-line) 1 -1)))
@@ -85,7 +85,7 @@ an exceedingly quick way of adding multiple cursors to
multiple lines."
(set-mark (point))
(move-to-column point-column)
(mc/save-excursion
- (while (not (= anchor-line (line-number-at-pos)))
+ (while (not (= anchor-line (mc/line-number-at-pos)))
(forward-line navigation-step)
(move-to-column anchor-column)
(when (= anchor-column (current-column))
- [nongnu] elpa/multiple-cursors 415e29f 352/434: Add @jtamagnan to contributors list, (continued)
- [nongnu] elpa/multiple-cursors 415e29f 352/434: Add @jtamagnan to contributors list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 1686630 369/434: try to implement blacklist, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d26cecd 381/434: added always-run-for-all, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 8e59a8a 390/434: Merge pull request #262 from AndreaOrru/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors fa91dfb 397/434: Don't display message while loading mc/list-file, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6f183a1 405/434: Merge pull request #304 from angadgill92/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 18f992b 403/434: Merge pull request #290 from raxod502/feat/silent-load, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 75dd6bf 413/434: Merge pull request #327 from notetiene/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 9c49874 415/434: Merge pull request #333 from drrlvn/patch-1, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6a7c3c0 418/434: Fix whitespace, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b39e963 425/434: Faster line-number-at-pos calculation,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors cb7a145 210/434: Release 1.2.0, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 25dd14d 219/434: Add more scenarios for mark-all-*-like-this, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors cc45842 241/434: Improved mc/mark-more-like-this-extended, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 4535033 235/434: Added a new function mc/mark-pop that sets cursors by popping marks off the mark stack., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 4748386 238/434: Make mc/mark-pop only run once per invocation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors be7905d 258/434: Update README to note that there is a mode allowing search in multiple-cursors., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors a86daa7 270/434: Guard with 'if' rather than defun*/return-from, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 18d858f 272/434: Fall straight through in 'mc/mark-all-dwim' if multiple cursors are already active, as that means we can't sensibly edit lines or mark all in region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 2b536cb 283/434: Added mc/edit-lines-empty-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 75ece68 288/434: Merge pull request #118 from aspiers/fix-compile-warnings, ELPA Syncer, 2021/08/07