mirror of
https://github.com/magnars/multiple-cursors.el.git
synced 2026-02-04 06:12:25 +00:00
Avoid deprecated ELisp features
Activate `lexical-binding` in a few more files. Use `advice-add` rather than `defadvice`. Fix some compilation warnings. Prefer #' to quote function names. Adjust `Package-Requires:` accordingly.
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,7 @@
|
|||||||
elpa
|
elpa
|
||||||
*.elc
|
*.elc
|
||||||
/.ecukes-failing-scenarios
|
/.ecukes-failing-scenarios
|
||||||
|
|
||||||
|
# ELPA-generated files
|
||||||
|
/multiple-cursors-pkg.el
|
||||||
|
/multiple-cursors-autoloads.el
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
(require 'cl) ;; For lexical-let
|
;; -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(require 'multiple-cursors-core)
|
||||||
|
|
||||||
(When "^I mark next like this$"
|
(When "^I mark next like this$"
|
||||||
(lambda () (call-interactively 'mc/mark-next-like-this)))
|
(lambda () (call-interactively 'mc/mark-next-like-this)))
|
||||||
@@ -109,26 +111,22 @@
|
|||||||
|
|
||||||
(When "^I copy \"\\(.+\\)\" in another program$"
|
(When "^I copy \"\\(.+\\)\" in another program$"
|
||||||
(lambda (text)
|
(lambda (text)
|
||||||
(lexical-let ((text text))
|
(setq interprogram-paste-function
|
||||||
(setq interprogram-paste-function
|
#'(lambda () (let ((r text)) (setq text nil) r)))))
|
||||||
#'(lambda () (let ((r text)) (setq text nil) r))))))
|
|
||||||
|
|
||||||
(Given "^I have bound C-! to a lambda that inserts \"\\(.+\\)\"$"
|
(Given "^I have bound C-! to a lambda that inserts \"\\(.+\\)\"$"
|
||||||
(lambda (ins)
|
(lambda (ins)
|
||||||
(lexical-let ((ins ins))
|
(global-set-key (kbd "C-!") #'(lambda () (interactive) (insert ins)))))
|
||||||
(global-set-key (kbd "C-!") #'(lambda () (interactive) (insert ins))))))
|
|
||||||
|
|
||||||
(Given "^I have bound C-! to a new command that inserts \"\\(.+\\)\"$"
|
(Given "^I have bound C-! to a new command that inserts \"\\(.+\\)\"$"
|
||||||
(lambda (ins)
|
(lambda (ins)
|
||||||
(lexical-let ((ins ins))
|
(defun mc-test-temp-command () (interactive) (insert ins))
|
||||||
(defun mc-test-temp-command () (interactive) (insert ins))
|
(global-set-key (kbd "C-!") 'mc-test-temp-command)))
|
||||||
(global-set-key (kbd "C-!") 'mc-test-temp-command))))
|
|
||||||
|
|
||||||
(Given "^I have bound C-! to another new command that inserts \"\\(.+\\)\"$"
|
(Given "^I have bound C-! to another new command that inserts \"\\(.+\\)\"$"
|
||||||
(lambda (ins)
|
(lambda (ins)
|
||||||
(lexical-let ((ins ins))
|
(defun mc-test-temp-command-2 () (interactive) (insert ins))
|
||||||
(defun mc-test-temp-command-2 () (interactive) (insert ins))
|
(global-set-key (kbd "C-!") 'mc-test-temp-command-2)))
|
||||||
(global-set-key (kbd "C-!") 'mc-test-temp-command-2))))
|
|
||||||
|
|
||||||
(Given "^I have bound C-! to a new command that inserts two read-chars$"
|
(Given "^I have bound C-! to a new command that inserts two read-chars$"
|
||||||
(lambda ()
|
(lambda ()
|
||||||
@@ -171,7 +169,7 @@
|
|||||||
|
|
||||||
(When "^I mark all \\(.+\\)$"
|
(When "^I mark all \\(.+\\)$"
|
||||||
(lambda (rest)
|
(lambda (rest)
|
||||||
(let ((func (intern (mapconcat 'identity
|
(let ((func (intern (mapconcat #'identity
|
||||||
(cons "mc/mark-all"
|
(cons "mc/mark-all"
|
||||||
(split-string rest))
|
(split-string rest))
|
||||||
"-"))))
|
"-"))))
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
(let* ((current-directory (file-name-directory load-file-name))
|
;; -*- lexical-binding: t; -*-
|
||||||
(features-directory (expand-file-name ".." current-directory))
|
(defvar multiple-cursors-root-path
|
||||||
(project-directory (expand-file-name ".." features-directory)))
|
(let* ((current-directory (file-name-directory load-file-name))
|
||||||
(setq multiple-cursors-root-path project-directory)
|
(features-directory (expand-file-name ".." current-directory)))
|
||||||
(setq multiple-cursors-util-path (expand-file-name "util" project-directory)))
|
(expand-file-name ".." features-directory)))
|
||||||
|
(defvar multiple-cursors-util-path
|
||||||
|
(expand-file-name "util" multiple-cursors-root-path))
|
||||||
|
|
||||||
(add-to-list 'load-path multiple-cursors-root-path)
|
(add-to-list 'load-path multiple-cursors-root-path)
|
||||||
(add-to-list 'load-path multiple-cursors-util-path)
|
(add-to-list 'load-path multiple-cursors-util-path)
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
(cursors-after-point (cl-remove-if (lambda (cursor)
|
(cursors-after-point (cl-remove-if (lambda (cursor)
|
||||||
(< (mc/cursor-beg cursor) point))
|
(< (mc/cursor-beg cursor) point))
|
||||||
cursors))
|
cursors))
|
||||||
(cursors-in-order (cl-sort cursors-after-point '< :key 'mc/cursor-beg)))
|
(cursors-in-order (cl-sort cursors-after-point #'< :key #'mc/cursor-beg)))
|
||||||
(car cursors-in-order)))
|
(car cursors-in-order)))
|
||||||
|
|
||||||
(defun mc/last-fake-cursor-before (point)
|
(defun mc/last-fake-cursor-before (point)
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
(cursors-before-point (cl-remove-if (lambda (cursor)
|
(cursors-before-point (cl-remove-if (lambda (cursor)
|
||||||
(> (mc/cursor-end cursor) point))
|
(> (mc/cursor-end cursor) point))
|
||||||
cursors))
|
cursors))
|
||||||
(cursors-in-order (cl-sort cursors-before-point '> :key 'mc/cursor-end)))
|
(cursors-in-order (cl-sort cursors-before-point #'> :key #'mc/cursor-end)))
|
||||||
(car cursors-in-order)))
|
(car cursors-in-order)))
|
||||||
|
|
||||||
(cl-defun mc/cycle (next-cursor fallback-cursor loop-message)
|
(cl-defun mc/cycle (next-cursor fallback-cursor loop-message)
|
||||||
@@ -110,8 +110,8 @@
|
|||||||
(mc/last-fake-cursor-before (point-max))
|
(mc/last-fake-cursor-before (point-max))
|
||||||
"We're already at the last cursor"))
|
"We're already at the last cursor"))
|
||||||
|
|
||||||
(define-key mc/keymap (kbd "C-v") 'mc/cycle-forward)
|
(define-key mc/keymap (kbd "C-v") #'mc/cycle-forward)
|
||||||
(define-key mc/keymap (kbd "M-v") 'mc/cycle-backward)
|
(define-key mc/keymap (kbd "M-v") #'mc/cycle-backward)
|
||||||
|
|
||||||
(provide 'mc-cycle-cursors)
|
(provide 'mc-cycle-cursors)
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,8 @@
|
|||||||
(defvar hum/hide-unmatched-lines-mode-map (make-sparse-keymap)
|
(defvar hum/hide-unmatched-lines-mode-map (make-sparse-keymap)
|
||||||
"Keymap for hide unmatched lines is mainly for rebinding C-g")
|
"Keymap for hide unmatched lines is mainly for rebinding C-g")
|
||||||
|
|
||||||
(define-key hum/hide-unmatched-lines-mode-map (kbd "C-g") 'hum/keyboard-quit)
|
(define-key hum/hide-unmatched-lines-mode-map (kbd "C-g") #'hum/keyboard-quit)
|
||||||
(define-key hum/hide-unmatched-lines-mode-map (kbd "<return>") 'hum/keyboard-quit)
|
(define-key hum/hide-unmatched-lines-mode-map (kbd "<return>") #'hum/keyboard-quit)
|
||||||
|
|
||||||
(defun hum/keyboard-quit ()
|
(defun hum/keyboard-quit ()
|
||||||
"Leave hide-unmatched-lines mode"
|
"Leave hide-unmatched-lines mode"
|
||||||
@@ -61,10 +61,10 @@ mode. To leave this mode press <return> or \"C-g\""
|
|||||||
;;just in case if mc mode will be disabled while hide-unmatched-lines is active
|
;;just in case if mc mode will be disabled while hide-unmatched-lines is active
|
||||||
(progn
|
(progn
|
||||||
(hum/hide-unmatched-lines)
|
(hum/hide-unmatched-lines)
|
||||||
(add-hook 'multiple-cursors-mode-disabled-hook 'hum/disable-hum-mode t t))
|
(add-hook 'multiple-cursors-mode-disabled-hook #'hum/disable-hum-mode t t))
|
||||||
(progn
|
(progn
|
||||||
(hum/unhide-unmatched-lines)
|
(hum/unhide-unmatched-lines)
|
||||||
(remove-hook 'multiple-cursors-mode-disabled-hook 'hum/disable-hum-mode))))
|
(remove-hook 'multiple-cursors-mode-disabled-hook #'hum/disable-hum-mode))))
|
||||||
|
|
||||||
(defconst hum/invisible-overlay-name 'hum/invisible-overlay-name)
|
(defconst hum/invisible-overlay-name 'hum/invisible-overlay-name)
|
||||||
|
|
||||||
@@ -104,6 +104,6 @@ mode. To leave this mode press <return> or \"C-g\""
|
|||||||
(defun hum/unhide-unmatched-lines ()
|
(defun hum/unhide-unmatched-lines ()
|
||||||
(remove-overlays nil nil hum/invisible-overlay-name t))
|
(remove-overlays nil nil hum/invisible-overlay-name t))
|
||||||
|
|
||||||
(define-key mc/keymap (kbd "C-'") 'mc-hide-unmatched-lines-mode)
|
(define-key mc/keymap (kbd "C-'") #'mc-hide-unmatched-lines-mode)
|
||||||
|
|
||||||
(provide 'mc-hide-unmatched-lines-mode)
|
(provide 'mc-hide-unmatched-lines-mode)
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ With zero ARG, skip the last one and mark next."
|
|||||||
(mc/mark-previous-like-this arg)))
|
(mc/mark-previous-like-this arg)))
|
||||||
|
|
||||||
(defun mc/mark-lines (num-lines direction)
|
(defun mc/mark-lines (num-lines direction)
|
||||||
(dotimes (i (if (= num-lines 0) 1 num-lines))
|
(dotimes (_ (if (= num-lines 0) 1 num-lines))
|
||||||
(mc/save-excursion
|
(mc/save-excursion
|
||||||
(let ((furthest-cursor (cl-ecase direction
|
(let ((furthest-cursor (cl-ecase direction
|
||||||
(forwards (mc/furthest-cursor-after-point))
|
(forwards (mc/furthest-cursor-after-point))
|
||||||
@@ -500,10 +500,10 @@ remove the keymap depends on user input and KEEP-PRED:
|
|||||||
|
|
||||||
(defvar mc/mark-more-like-this-extended-keymap (make-sparse-keymap))
|
(defvar mc/mark-more-like-this-extended-keymap (make-sparse-keymap))
|
||||||
|
|
||||||
(define-key mc/mark-more-like-this-extended-keymap (kbd "<up>") 'mc/mmlte--up)
|
(define-key mc/mark-more-like-this-extended-keymap (kbd "<up>") #'mc/mmlte--up)
|
||||||
(define-key mc/mark-more-like-this-extended-keymap (kbd "<down>") 'mc/mmlte--down)
|
(define-key mc/mark-more-like-this-extended-keymap (kbd "<down>") #'mc/mmlte--down)
|
||||||
(define-key mc/mark-more-like-this-extended-keymap (kbd "<left>") 'mc/mmlte--left)
|
(define-key mc/mark-more-like-this-extended-keymap (kbd "<left>") #'mc/mmlte--left)
|
||||||
(define-key mc/mark-more-like-this-extended-keymap (kbd "<right>") 'mc/mmlte--right)
|
(define-key mc/mark-more-like-this-extended-keymap (kbd "<right>") #'mc/mmlte--right)
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun mc/mark-more-like-this-extended ()
|
(defun mc/mark-more-like-this-extended ()
|
||||||
@@ -706,7 +706,7 @@ already there."
|
|||||||
(mc/maybe-multiple-cursors-mode)))
|
(mc/maybe-multiple-cursors-mode)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defalias 'mc/add-cursor-on-click 'mc/toggle-cursor-on-click)
|
(defalias 'mc/add-cursor-on-click #'mc/toggle-cursor-on-click)
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun mc/mark-sgml-tag-pair ()
|
(defun mc/mark-sgml-tag-pair ()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
;;; mc-separate-operations.el - functions that work differently on each cursor -*- lexical-binding: t; -*-
|
;;; mc-separate-operations.el --- Functions that work differently on each cursor -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Copyright (C) 2012-2016 Magnar Sveen
|
;; Copyright (C) 2012-2016 Magnar Sveen
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@
|
|||||||
(interactive)
|
(interactive)
|
||||||
(unless (use-region-p)
|
(unless (use-region-p)
|
||||||
(mc/execute-command-for-all-cursors 'mark-sexp))
|
(mc/execute-command-for-all-cursors 'mark-sexp))
|
||||||
(setq mc--strings-to-replace (sort (mc--ordered-region-strings) 'string<))
|
(setq mc--strings-to-replace (sort (mc--ordered-region-strings) #'string<))
|
||||||
(mc--replace-region-strings))
|
(mc--replace-region-strings))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
;;; multiple-cursors-core.el --- An experiment in multiple cursors for emacs. -*- lexical-binding: t; -*-
|
;;; multiple-cursors-core.el --- An experiment in multiple cursors for Emacs -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Copyright (C) 2012-2016 Magnar Sveen
|
;; Copyright (C) 2012-2016 Magnar Sveen
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ rendered or shift text."
|
|||||||
(cons (cons 'apply (cons 'activate-cursor-for-undo (list id))) buffer-undo-list))))))
|
(cons (cons 'apply (cons 'activate-cursor-for-undo (list id))) buffer-undo-list))))))
|
||||||
|
|
||||||
(defun mc/all-fake-cursors (&optional start end)
|
(defun mc/all-fake-cursors (&optional start end)
|
||||||
(cl-remove-if-not 'mc/fake-cursor-p
|
(cl-remove-if-not #'mc/fake-cursor-p
|
||||||
(overlays-in (or start (point-min))
|
(overlays-in (or start (point-min))
|
||||||
(or end (point-max)))))
|
(or end (point-max)))))
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ rendered or shift text."
|
|||||||
(mapc #'(lambda (cursor)
|
(mapc #'(lambda (cursor)
|
||||||
(when (mc/fake-cursor-p cursor)
|
(when (mc/fake-cursor-p cursor)
|
||||||
,@forms))
|
,@forms))
|
||||||
(sort (overlays-in (point-min) (point-max)) 'mc--compare-by-overlay-start))
|
(sort (overlays-in (point-min) (point-max)) #'mc--compare-by-overlay-start))
|
||||||
(mc/pop-state-from-overlay (mc/cursor-with-id ,rci)))))
|
(mc/pop-state-from-overlay (mc/cursor-with-id ,rci)))))
|
||||||
|
|
||||||
(defmacro mc/save-window-scroll (&rest forms)
|
(defmacro mc/save-window-scroll (&rest forms)
|
||||||
@@ -290,6 +290,8 @@ makes sense for fake cursors."
|
|||||||
(defvar mc--executing-command-for-fake-cursor nil)
|
(defvar mc--executing-command-for-fake-cursor nil)
|
||||||
|
|
||||||
(defun mc/execute-command-for-fake-cursor (cmd cursor)
|
(defun mc/execute-command-for-fake-cursor (cmd cursor)
|
||||||
|
(defvar annoying-arrows-mode)
|
||||||
|
(defvar smooth-scroll-margin)
|
||||||
(let ((mc--executing-command-for-fake-cursor t)
|
(let ((mc--executing-command-for-fake-cursor t)
|
||||||
(id (overlay-get cursor 'mc-id))
|
(id (overlay-get cursor 'mc-id))
|
||||||
(annoying-arrows-mode nil)
|
(annoying-arrows-mode nil)
|
||||||
@@ -581,7 +583,7 @@ which action is being undone."
|
|||||||
|
|
||||||
(defun mc/num-cursors ()
|
(defun mc/num-cursors ()
|
||||||
"The number of cursors (real and fake) in the buffer."
|
"The number of cursors (real and fake) in the buffer."
|
||||||
(1+ (cl-count-if 'mc/fake-cursor-p
|
(1+ (cl-count-if #'mc/fake-cursor-p
|
||||||
(overlays-in (point-min) (point-max)))))
|
(overlays-in (point-min) (point-max)))))
|
||||||
|
|
||||||
(defvar mc--this-command nil
|
(defvar mc--this-command nil
|
||||||
@@ -613,9 +615,10 @@ not be recognized through the command-remapping lookup."
|
|||||||
;; execute-kbd-macro should never be run for fake cursors. The real cursor will
|
;; execute-kbd-macro should never be run for fake cursors. The real cursor will
|
||||||
;; execute the keyboard macro, resulting in new commands in the command loop,
|
;; execute the keyboard macro, resulting in new commands in the command loop,
|
||||||
;; and the fake cursors can pick up on those instead.
|
;; and the fake cursors can pick up on those instead.
|
||||||
(defadvice execute-kbd-macro (around skip-fake-cursors activate)
|
(advice-add 'execute-kbd-macro :around #'mc--skip-fake-cursors)
|
||||||
|
(defun mc--skip-fake-cursors (orig-fun &rest args)
|
||||||
(unless mc--executing-command-for-fake-cursor
|
(unless mc--executing-command-for-fake-cursor
|
||||||
ad-do-it))
|
(apply orig-fun args)))
|
||||||
|
|
||||||
(defun mc/execute-this-command-for-all-cursors-1 ()
|
(defun mc/execute-this-command-for-all-cursors-1 ()
|
||||||
"Used with post-command-hook to execute supported commands for all cursors.
|
"Used with post-command-hook to execute supported commands for all cursors.
|
||||||
@@ -694,7 +697,7 @@ you should disable multiple-cursors-mode."
|
|||||||
(mc/execute-command-for-all-fake-cursors
|
(mc/execute-command-for-all-fake-cursors
|
||||||
(lambda () (interactive)
|
(lambda () (interactive)
|
||||||
(cl-letf (((symbol-function 'read-from-minibuffer)
|
(cl-letf (((symbol-function 'read-from-minibuffer)
|
||||||
(lambda (p &optional i k r h d m) (read i))))
|
(lambda (_p &optional i &rest _) (read i))))
|
||||||
(repeat-complex-command 0))))))
|
(repeat-complex-command 0))))))
|
||||||
|
|
||||||
(defvar mc/keymap nil
|
(defvar mc/keymap nil
|
||||||
@@ -703,13 +706,13 @@ Main goal of the keymap is to rebind C-g and <return> to conclude
|
|||||||
multiple cursors editing.")
|
multiple cursors editing.")
|
||||||
(unless mc/keymap
|
(unless mc/keymap
|
||||||
(setq mc/keymap (make-sparse-keymap))
|
(setq mc/keymap (make-sparse-keymap))
|
||||||
(define-key mc/keymap (kbd "C-g") 'mc/keyboard-quit)
|
(define-key mc/keymap (kbd "C-g") #'mc/keyboard-quit)
|
||||||
(define-key mc/keymap (kbd "<return>") 'multiple-cursors-mode)
|
(define-key mc/keymap (kbd "<return>") #'multiple-cursors-mode)
|
||||||
(define-key mc/keymap (kbd "C-:") 'mc/repeat-command)
|
(define-key mc/keymap (kbd "C-:") #'mc/repeat-command)
|
||||||
(when (fboundp 'phi-search)
|
(when (fboundp 'phi-search)
|
||||||
(define-key mc/keymap (kbd "C-s") 'phi-search))
|
(define-key mc/keymap (kbd "C-s") #'phi-search))
|
||||||
(when (fboundp 'phi-search-backward)
|
(when (fboundp 'phi-search-backward)
|
||||||
(define-key mc/keymap (kbd "C-r") 'phi-search-backward)))
|
(define-key mc/keymap (kbd "C-r") #'phi-search-backward)))
|
||||||
|
|
||||||
(defun mc--all-equal (list)
|
(defun mc--all-equal (list)
|
||||||
"Are all the items in LIST equal?"
|
"Are all the items in LIST equal?"
|
||||||
@@ -750,13 +753,13 @@ They are temporarily disabled when multiple-cursors are active.")
|
|||||||
(funcall mode -1)))
|
(funcall mode -1)))
|
||||||
|
|
||||||
(defun mc/temporarily-disable-unsupported-minor-modes ()
|
(defun mc/temporarily-disable-unsupported-minor-modes ()
|
||||||
(mapc 'mc/temporarily-disable-minor-mode mc/unsupported-minor-modes))
|
(mapc #'mc/temporarily-disable-minor-mode mc/unsupported-minor-modes))
|
||||||
|
|
||||||
(defun mc/enable-minor-mode (mode)
|
(defun mc/enable-minor-mode (mode)
|
||||||
(funcall mode 1))
|
(funcall mode 1))
|
||||||
|
|
||||||
(defun mc/enable-temporarily-disabled-minor-modes ()
|
(defun mc/enable-temporarily-disabled-minor-modes ()
|
||||||
(mapc 'mc/enable-minor-mode mc/temporarily-disabled-minor-modes)
|
(mapc #'mc/enable-minor-mode mc/temporarily-disabled-minor-modes)
|
||||||
(setq mc/temporarily-disabled-minor-modes nil))
|
(setq mc/temporarily-disabled-minor-modes nil))
|
||||||
|
|
||||||
(defcustom mc/mode-line
|
(defcustom mc/mode-line
|
||||||
@@ -776,11 +779,11 @@ They are temporarily disabled when multiple-cursors are active.")
|
|||||||
(if multiple-cursors-mode
|
(if multiple-cursors-mode
|
||||||
(progn
|
(progn
|
||||||
(mc/temporarily-disable-unsupported-minor-modes)
|
(mc/temporarily-disable-unsupported-minor-modes)
|
||||||
(add-hook 'pre-command-hook 'mc/make-a-note-of-the-command-being-run nil t)
|
(add-hook 'pre-command-hook #'mc/make-a-note-of-the-command-being-run nil t)
|
||||||
(add-hook 'post-command-hook 'mc/execute-this-command-for-all-cursors t t)
|
(add-hook 'post-command-hook #'mc/execute-this-command-for-all-cursors t t)
|
||||||
(run-hooks 'multiple-cursors-mode-enabled-hook))
|
(run-hooks 'multiple-cursors-mode-enabled-hook))
|
||||||
(remove-hook 'post-command-hook 'mc/execute-this-command-for-all-cursors t)
|
(remove-hook 'post-command-hook #'mc/execute-this-command-for-all-cursors t)
|
||||||
(remove-hook 'pre-command-hook 'mc/make-a-note-of-the-command-being-run t)
|
(remove-hook 'pre-command-hook #'mc/make-a-note-of-the-command-being-run t)
|
||||||
(setq mc--this-command nil)
|
(setq mc--this-command nil)
|
||||||
(mc--maybe-set-killed-rectangle)
|
(mc--maybe-set-killed-rectangle)
|
||||||
(mc/remove-fake-cursors)
|
(mc/remove-fake-cursors)
|
||||||
@@ -792,7 +795,7 @@ They are temporarily disabled when multiple-cursors are active.")
|
|||||||
(multiple-cursors-mode 0)
|
(multiple-cursors-mode 0)
|
||||||
(run-hooks 'multiple-cursors-mode-disabled-hook))
|
(run-hooks 'multiple-cursors-mode-disabled-hook))
|
||||||
|
|
||||||
(add-hook 'after-revert-hook 'mc/disable-multiple-cursors-mode)
|
(add-hook 'after-revert-hook #'mc/disable-multiple-cursors-mode)
|
||||||
|
|
||||||
(defun mc/maybe-multiple-cursors-mode ()
|
(defun mc/maybe-multiple-cursors-mode ()
|
||||||
"Enable multiple-cursors-mode if there is more than one currently active cursor."
|
"Enable multiple-cursors-mode if there is more than one currently active cursor."
|
||||||
@@ -800,23 +803,26 @@ They are temporarily disabled when multiple-cursors are active.")
|
|||||||
(multiple-cursors-mode 1)
|
(multiple-cursors-mode 1)
|
||||||
(mc/disable-multiple-cursors-mode)))
|
(mc/disable-multiple-cursors-mode)))
|
||||||
|
|
||||||
|
(defun mc--unsupported-advice (orig-fun &rest args)
|
||||||
|
"command isn't supported with multiple cursors."
|
||||||
|
(unless (and multiple-cursors-mode (called-interactively-p 'any))
|
||||||
|
(apply orig-fun args)))
|
||||||
|
|
||||||
(defmacro unsupported-cmd (cmd msg)
|
(defmacro unsupported-cmd (cmd msg)
|
||||||
"Adds command to list of unsupported commands and prevents it
|
"Adds command to list of unsupported commands and prevents it
|
||||||
from being executed if in multiple-cursors-mode."
|
from being executed if in multiple-cursors-mode."
|
||||||
`(progn
|
`(progn
|
||||||
(put (quote ,cmd) 'mc--unsupported ,msg)
|
(put ',cmd 'mc--unsupported ,msg)
|
||||||
(defadvice ,cmd (around unsupported-advice activate)
|
(advice-add ',cmd :around #'mc--unsupported-advice)))
|
||||||
"command isn't supported with multiple cursors"
|
|
||||||
(unless (and multiple-cursors-mode (called-interactively-p 'any))
|
|
||||||
ad-do-it))))
|
|
||||||
|
|
||||||
;; Commands that does not work with multiple-cursors
|
;; Commands that does not work with multiple-cursors
|
||||||
(unsupported-cmd isearch-forward ". Feel free to add a compatible version.")
|
(unsupported-cmd isearch-forward ". Feel free to add a compatible version.")
|
||||||
(unsupported-cmd isearch-backward ". Feel free to add a compatible version.")
|
(unsupported-cmd isearch-backward ". Feel free to add a compatible version.")
|
||||||
|
|
||||||
;; Make sure pastes from other programs are added to all kill-rings when yanking
|
;; Make sure pastes from other programs are added to all kill-rings when yanking
|
||||||
(defadvice current-kill (before interprogram-paste-for-all-cursors
|
(advice-add 'current-kill :before #'mc--interprogram-paste-for-all-cursors)
|
||||||
(n &optional do-not-move) activate)
|
(defun mc--interprogram-paste-for-all-cursors (n &rest _)
|
||||||
|
;; FIXME: Shouldn't we check `multiple-cursors-mode' or something?
|
||||||
(let ((interprogram-paste (and (= n 0)
|
(let ((interprogram-paste (and (= n 0)
|
||||||
interprogram-paste-function
|
interprogram-paste-function
|
||||||
(funcall interprogram-paste-function))))
|
(funcall interprogram-paste-function))))
|
||||||
@@ -827,7 +833,7 @@ from being executed if in multiple-cursors-mode."
|
|||||||
;; something once. It is not a pure function.
|
;; something once. It is not a pure function.
|
||||||
(let ((interprogram-cut-function nil))
|
(let ((interprogram-cut-function nil))
|
||||||
(if (listp interprogram-paste)
|
(if (listp interprogram-paste)
|
||||||
(mapc 'kill-new (nreverse interprogram-paste))
|
(mapc #'kill-new (nreverse interprogram-paste))
|
||||||
(kill-new interprogram-paste))
|
(kill-new interprogram-paste))
|
||||||
;; And then add interprogram-paste to the kill-rings
|
;; And then add interprogram-paste to the kill-rings
|
||||||
;; of all the other cursors too.
|
;; of all the other cursors too.
|
||||||
@@ -835,12 +841,13 @@ from being executed if in multiple-cursors-mode."
|
|||||||
(let ((kill-ring (overlay-get cursor 'kill-ring))
|
(let ((kill-ring (overlay-get cursor 'kill-ring))
|
||||||
(kill-ring-yank-pointer (overlay-get cursor 'kill-ring-yank-pointer)))
|
(kill-ring-yank-pointer (overlay-get cursor 'kill-ring-yank-pointer)))
|
||||||
(if (listp interprogram-paste)
|
(if (listp interprogram-paste)
|
||||||
(mapc 'kill-new (nreverse interprogram-paste))
|
(mapc #'kill-new (nreverse interprogram-paste))
|
||||||
(kill-new interprogram-paste))
|
(kill-new interprogram-paste))
|
||||||
(overlay-put cursor 'kill-ring kill-ring)
|
(overlay-put cursor 'kill-ring kill-ring)
|
||||||
(overlay-put cursor 'kill-ring-yank-pointer kill-ring-yank-pointer)))))))
|
(overlay-put cursor 'kill-ring-yank-pointer kill-ring-yank-pointer)))))))
|
||||||
|
|
||||||
(defadvice execute-extended-command (after execute-extended-command-for-all-cursors () activate)
|
(advice-add 'execute-extended-command :after #'mc--execute-extended-command-for-all-cursors)
|
||||||
|
(defun mc--execute-extended-command-for-all-cursors (&rest _)
|
||||||
(when multiple-cursors-mode
|
(when multiple-cursors-mode
|
||||||
(unless (or mc/always-run-for-all
|
(unless (or mc/always-run-for-all
|
||||||
(not (symbolp this-command))
|
(not (symbolp this-command))
|
||||||
@@ -870,7 +877,7 @@ for running commands with multiple cursors."
|
|||||||
(setq mc--list-file-loaded t)))
|
(setq mc--list-file-loaded t)))
|
||||||
|
|
||||||
(defun mc/dump-list (list-symbol)
|
(defun mc/dump-list (list-symbol)
|
||||||
"Insert (setq 'LIST-SYMBOL LIST-VALUE) to current buffer."
|
"Insert (setq LIST-SYMBOL LIST-VALUE) to current buffer."
|
||||||
(cl-symbol-macrolet ((value (symbol-value list-symbol)))
|
(cl-symbol-macrolet ((value (symbol-value list-symbol)))
|
||||||
(insert "(setq " (symbol-name list-symbol) "\n"
|
(insert "(setq " (symbol-name list-symbol) "\n"
|
||||||
" '(")
|
" '(")
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
;;; multiple-cursors.el --- Multiple cursors for emacs. -*- lexical-binding: t; -*-
|
;;; multiple-cursors.el --- Multiple cursors for Emacs -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Copyright (C) 2012-2016 Magnar Sveen
|
;; Copyright (C) 2012-2016 Magnar Sveen
|
||||||
|
|
||||||
;; Author: Magnar Sveen <magnars@gmail.com>
|
;; Author: Magnar Sveen <magnars@gmail.com>
|
||||||
;; Package-Version: 1.5.0
|
;; Package-Version: 1.5.0
|
||||||
;; Package-Requires: ((cl-lib "0.5"))
|
;; Package-Requires: ((emacs "24.4") (cl-lib "0.5"))
|
||||||
;; Keywords: editing cursors
|
;; Keywords: editing cursors
|
||||||
;; Homepage: https://github.com/magnars/multiple-cursors.el
|
;; Homepage: https://github.com/magnars/multiple-cursors.el
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,8 @@
|
|||||||
(defvar rectangular-region-mode-map (make-sparse-keymap)
|
(defvar rectangular-region-mode-map (make-sparse-keymap)
|
||||||
"Keymap for rectangular region is mainly for rebinding C-g")
|
"Keymap for rectangular region is mainly for rebinding C-g")
|
||||||
|
|
||||||
(define-key rectangular-region-mode-map (kbd "C-g") 'rrm/keyboard-quit)
|
(define-key rectangular-region-mode-map (kbd "C-g") #'rrm/keyboard-quit)
|
||||||
(define-key rectangular-region-mode-map (kbd "<return>") 'rrm/switch-to-multiple-cursors)
|
(define-key rectangular-region-mode-map (kbd "<return>") #'rrm/switch-to-multiple-cursors)
|
||||||
|
|
||||||
(defvar rectangular-region-mode nil)
|
(defvar rectangular-region-mode nil)
|
||||||
|
|
||||||
@@ -71,16 +71,17 @@ multiple cursors to multiple lines."
|
|||||||
(defun rrm/repaint ()
|
(defun rrm/repaint ()
|
||||||
"Start from the anchor and draw a rectangle between it and point."
|
"Start from the anchor and draw a rectangle between it and point."
|
||||||
(if (not rectangular-region-mode)
|
(if (not rectangular-region-mode)
|
||||||
(remove-hook 'post-command-hook 'rrm/repaint t)
|
(remove-hook 'post-command-hook #'rrm/repaint t)
|
||||||
;; else
|
;; else
|
||||||
|
(defvar annoying-arrows-mode)
|
||||||
(rrm/remove-rectangular-region-overlays)
|
(rrm/remove-rectangular-region-overlays)
|
||||||
(let* ((annoying-arrows-mode nil)
|
(let* ((annoying-arrows-mode nil)
|
||||||
(point-column (current-column))
|
(point-column (current-column))
|
||||||
(point-line (mc/line-number-at-pos))
|
(point-line (mc/line-number-at-pos))
|
||||||
(anchor-column (save-excursion (goto-char rrm/anchor) (current-column)))
|
(anchor-column (save-excursion (goto-char rrm/anchor) (current-column)))
|
||||||
(anchor-line (save-excursion (goto-char rrm/anchor) (mc/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))
|
;; (left-column (if (< point-column anchor-column) point-column anchor-column))
|
||||||
(right-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)))
|
(navigation-step (if (< point-line anchor-line) 1 -1)))
|
||||||
(move-to-column anchor-column)
|
(move-to-column anchor-column)
|
||||||
(set-mark (point))
|
(set-mark (point))
|
||||||
@@ -95,17 +96,15 @@ multiple cursors to multiple lines."
|
|||||||
(when (= point-column (current-column))
|
(when (= point-column (current-column))
|
||||||
(mc/create-fake-cursor-at-point))))))))
|
(mc/create-fake-cursor-at-point))))))))
|
||||||
|
|
||||||
(defun rrm/switch-to-multiple-cursors (&rest forms)
|
(defun rrm/switch-to-multiple-cursors (&rest _)
|
||||||
"Switch from rectangular-region-mode to multiple-cursors-mode."
|
"Switch from `rectangular-region-mode' to `multiple-cursors-mode'."
|
||||||
(interactive)
|
(interactive)
|
||||||
(rectangular-region-mode 0)
|
(rectangular-region-mode 0)
|
||||||
(multiple-cursors-mode 1))
|
(multiple-cursors-mode 1))
|
||||||
|
|
||||||
(defadvice er/expand-region (before switch-from-rrm-to-mc activate)
|
(advice-add 'er/expand-region :before #'rrm//switch-from-rrm-to-mc)
|
||||||
(when rectangular-region-mode
|
(advice-add 'kill-ring-save :before #'rrm//switch-from-rrm-to-mc)
|
||||||
(rrm/switch-to-multiple-cursors)))
|
(defun rrm//switch-from-rrm-to-mc (&rest _)
|
||||||
|
|
||||||
(defadvice kill-ring-save (before switch-from-rrm-to-mc activate)
|
|
||||||
(when rectangular-region-mode
|
(when rectangular-region-mode
|
||||||
(rrm/switch-to-multiple-cursors)))
|
(rrm/switch-to-multiple-cursors)))
|
||||||
|
|
||||||
@@ -117,10 +116,10 @@ multiple cursors to multiple lines."
|
|||||||
:keymap rectangular-region-mode-map
|
:keymap rectangular-region-mode-map
|
||||||
(if rectangular-region-mode
|
(if rectangular-region-mode
|
||||||
(progn
|
(progn
|
||||||
(add-hook 'after-change-functions 'rrm/switch-to-multiple-cursors t t)
|
(add-hook 'after-change-functions #'rrm/switch-to-multiple-cursors t t)
|
||||||
(add-hook 'post-command-hook 'rrm/repaint t t))
|
(add-hook 'post-command-hook #'rrm/repaint t t))
|
||||||
(remove-hook 'after-change-functions 'rrm/switch-to-multiple-cursors t)
|
(remove-hook 'after-change-functions #'rrm/switch-to-multiple-cursors t)
|
||||||
(remove-hook 'post-command-hook 'rrm/repaint t)
|
(remove-hook 'post-command-hook #'rrm/repaint t)
|
||||||
(set-marker rrm/anchor nil)))
|
(set-marker rrm/anchor nil)))
|
||||||
|
|
||||||
(provide 'rectangular-region-mode)
|
(provide 'rectangular-region-mode)
|
||||||
|
|||||||
Reference in New Issue
Block a user