From 2cd802b1f71efead5a12a3e27da34e257a47a135 Mon Sep 17 00:00:00 2001 From: Renato Ferreira Date: Thu, 8 Jan 2026 06:09:20 -0300 Subject: [PATCH] Use built-in line-number-at-pos in Emacs >= 28 (#373) --- multiple-cursors-core.el | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el index 4cc9dd9..de8b39a 100644 --- a/multiple-cursors-core.el +++ b/multiple-cursors-core.el @@ -123,18 +123,20 @@ rendered or shift text." (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")))) +(if (>= emacs-major-version 28) + (defalias 'mc/line-number-at-pos #'line-number-at-pos) + (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."