mirror of
https://github.com/magnars/multiple-cursors.el.git
synced 2025-10-13 05:03:03 +00:00
Merge pull request #358 from renatofdds/master
Faster line-number-at-pos calculation
This commit is contained in:
commit
b9b851a767
@ -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)
|
||||
|
@ -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))
|
||||
|
@ -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)))
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user