Use cl-lib instead of shimming, which breaks in older emacsen

Aliasing built-in (cl) functions to cl-lib versions when they are
available in older Emacs versions can seemingly lead to problems
including infinite loops during byte compilation.

Since cl-lib works with all Emacs versions supported by
multiple-cursors, just depend on this directly instead.

This commit makes the necessary changes, both to code, documentation and
package metadata.
This commit is contained in:
Steve Purcell 2016-04-21 23:04:20 +12:00
parent 8297f1f210
commit 4bf9860bcc
6 changed files with 60 additions and 62 deletions

View File

@ -6,13 +6,17 @@ great success and much merriment.
## Installation ## Installation
I highly recommend installing multiple-cursors through elpa. I highly recommend installing multiple-cursors through `package.el`.
It's available on [marmalade](http://marmalade-repo.org/) and It's available on [marmalade](http://marmalade-repo.org/) and
[melpa](http://melpa.milkbox.net/): [melpa](http://melpa.milkbox.net/):
M-x package-install multiple-cursors M-x package-install multiple-cursors
The package depends on the `cl-lib` package, so if you do not use
`package.el` or have a recent Emacs, you would need to install that
too: see [GNU ELPA](http://elpa.gnu.org/packages/cl-lib.html).
## Basic usage ## Basic usage
Start out with: Start out with:

View File

@ -1,3 +1,5 @@
(require 'cl) ;; For lexical-let
(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)))
@ -48,24 +50,24 @@
(Then "^I should have \\([0-9]+\\) cursors$" (Then "^I should have \\([0-9]+\\) cursors$"
(lambda (num) (lambda (num)
(let ((actual (mc/num-cursors))) (let ((actual (mc/num-cursors)))
(assert (eq (string-to-number num) actual) nil (cl-assert (eq (string-to-number num) actual) nil
"Expected to have %s cursors, but was %d." num actual)))) "Expected to have %s cursors, but was %d." num actual))))
(Then "^I should have one cursor$" (Then "^I should have one cursor$"
(lambda () (lambda ()
(assert (not multiple-cursors-mode) nil (cl-assert (not multiple-cursors-mode) nil
"Expected to have one cursor, but multiple-cursors-mode is still active.") "Expected to have one cursor, but multiple-cursors-mode is still active.")
(assert (eq 1 (mc/num-cursors)) nil (cl-assert (eq 1 (mc/num-cursors)) nil
"Expected to have one cursor, but there are still fake cursor overlays."))) "Expected to have one cursor, but there are still fake cursor overlays.")))
(Then "^rectangular-region-mode should be off$" (Then "^rectangular-region-mode should be off$"
(lambda () (lambda ()
(assert (not rectangular-region-mode) nil (cl-assert (not rectangular-region-mode) nil
"Expected rectangular-region-mode mode to be off, but wasn't."))) "Expected rectangular-region-mode mode to be off, but wasn't.")))
(Then "^rectangular-region-mode should be on$" (Then "^rectangular-region-mode should be on$"
(lambda () (lambda ()
(assert rectangular-region-mode nil (cl-assert rectangular-region-mode nil
"Expected rectangular-region-mode mode to be on, but wasn't."))) "Expected rectangular-region-mode mode to be on, but wasn't.")))
(When "^I press \"\\(.+\\)\"$" (When "^I press \"\\(.+\\)\"$"
@ -132,21 +134,21 @@
(goto-char (point-min)) (goto-char (point-min))
(let ((search (re-search-forward (format "%s" char) nil t)) (let ((search (re-search-forward (format "%s" char) nil t))
(message "Can not go to character '%s' since it does not exist in the current buffer: %s")) (message "Can not go to character '%s' since it does not exist in the current buffer: %s"))
(assert search nil message char (espuds-buffer-contents))))) (cl-assert search nil message char (espuds-buffer-contents)))))
(When "^I go to the \\(front\\|end\\) of the word \"\\(.+\\)\"$" (When "^I go to the \\(front\\|end\\) of the word \"\\(.+\\)\"$"
(lambda (pos word) (lambda (pos word)
(goto-char (point-min)) (goto-char (point-min))
(let ((search (re-search-forward (format "%s" word) nil t)) (let ((search (re-search-forward (format "%s" word) nil t))
(message "Can not go to character '%s' since it does not exist in the current buffer: %s")) (message "Can not go to character '%s' since it does not exist in the current buffer: %s"))
(assert search nil message word (espuds-buffer-contents)) (cl-assert search nil message word (espuds-buffer-contents))
(if (string-equal "front" pos) (backward-word))))) (if (string-equal "front" pos) (backward-word)))))
(When "^I select the last \"\\(.+\\)\"$" (When "^I select the last \"\\(.+\\)\"$"
(lambda (text) (lambda (text)
(goto-char (point-max)) (goto-char (point-max))
(let ((search (re-search-backward text nil t))) (let ((search (re-search-backward text nil t)))
(assert search nil "The text '%s' was not found in the current buffer." text)) (cl-assert search nil "The text '%s' was not found in the current buffer." text))
(set-mark (point)) (set-mark (point))
(re-search-forward text))) (re-search-forward text)))
@ -173,3 +175,8 @@
(setq p (1+ p)) (setq p (1+ p))
) )
(cl-assert (s-equals? expected visible-text) nil message expected visible-text)))) (cl-assert (s-equals? expected visible-text) nil message expected visible-text))))
;; Local Variables:
;; byte-compile-warnings: (not cl-functions)
;; End:

View File

@ -28,8 +28,6 @@
(require 'multiple-cursors-core) (require 'multiple-cursors-core)
(eval-when-compile (require 'cl))
(defun mc/next-fake-cursor-after-point () (defun mc/next-fake-cursor-after-point ()
(let ((pos (point)) (let ((pos (point))
(next-pos (1+ (point-max))) (next-pos (1+ (point-max)))
@ -63,7 +61,7 @@
:group 'multiple-cursors) :group 'multiple-cursors)
(defun mc/handle-loop-condition (error-message) (defun mc/handle-loop-condition (error-message)
(ecase mc/cycle-looping-behaviour (cl-ecase mc/cycle-looping-behaviour
(error (error error-message)) (error (error error-message))
(warn (message error-message)) (warn (message error-message))
(continue 'continue) (continue 'continue)
@ -72,22 +70,22 @@
(defun mc/first-fake-cursor-after (point) (defun mc/first-fake-cursor-after (point)
"Very similar to mc/furthest-cursor-before-point, but ignores (mark) and (point)." "Very similar to mc/furthest-cursor-before-point, but ignores (mark) and (point)."
(let* ((cursors (mc/all-fake-cursors)) (let* ((cursors (mc/all-fake-cursors))
(cursors-after-point (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 (sort* cursors-after-point '< :key 'mc/cursor-beg))) (cursors-in-order (cl-sort cursors-after-point '< :key 'mc/cursor-beg)))
(first cursors-in-order))) (car cursors-in-order)))
(defun mc/last-fake-cursor-before (point) (defun mc/last-fake-cursor-before (point)
"Very similar to mc/furthest-cursor-before-point, but ignores (mark) and (point)." "Very similar to mc/furthest-cursor-before-point, but ignores (mark) and (point)."
(let* ((cursors (mc/all-fake-cursors)) (let* ((cursors (mc/all-fake-cursors))
(cursors-before-point (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 (sort* cursors-before-point '> :key 'mc/cursor-end))) (cursors-in-order (cl-sort cursors-before-point '> :key 'mc/cursor-end)))
(first cursors-in-order))) (car cursors-in-order)))
(defun* mc/cycle (next-cursor fallback-cursor loop-message) (cl-defun mc/cycle (next-cursor fallback-cursor loop-message)
(when (null next-cursor) (when (null next-cursor)
(when (eql 'stop (mc/handle-loop-condition loop-message)) (when (eql 'stop (mc/handle-loop-condition loop-message))
(return-from mc/cycle nil)) (return-from mc/cycle nil))
@ -116,7 +114,6 @@
;; Local Variables: ;; Local Variables:
;; coding: utf-8 ;; coding: utf-8
;; byte-compile-warnings: (not cl-functions)
;; End: ;; End:
;;; mc-cycle-cursors.el ends here ;;; mc-cycle-cursors.el ends here

View File

@ -104,19 +104,19 @@ Use like case-fold-search, don't recommend setting it globally.")
(defun mc/mark-more-like-this (skip-last direction) (defun mc/mark-more-like-this (skip-last direction)
(let ((case-fold-search nil) (let ((case-fold-search nil)
(re (regexp-opt (mc/region-strings) mc/enclose-search-term)) (re (regexp-opt (mc/region-strings) mc/enclose-search-term))
(point-out-of-order (ecase direction (point-out-of-order (cl-ecase direction
(forwards (< (point) (mark))) (forwards (< (point) (mark)))
(backwards (not (< (point) (mark)))))) (backwards (not (< (point) (mark))))))
(furthest-cursor (ecase direction (furthest-cursor (cl-ecase direction
(forwards (mc/furthest-cursor-after-point)) (forwards (mc/furthest-cursor-after-point))
(backwards (mc/furthest-cursor-before-point)))) (backwards (mc/furthest-cursor-before-point))))
(start-char (ecase direction (start-char (cl-ecase direction
(forwards (mc/furthest-region-end)) (forwards (mc/furthest-region-end))
(backwards (mc/first-region-start)))) (backwards (mc/first-region-start))))
(search-function (ecase direction (search-function (cl-ecase direction
(forwards 'search-forward-regexp) (forwards 'search-forward-regexp)
(backwards 'search-backward-regexp))) (backwards 'search-backward-regexp)))
(match-point-getter (ecase direction (match-point-getter (cl-ecase direction
(forwards 'match-beginning) (forwards 'match-beginning)
(backwards 'match-end)))) (backwards 'match-end))))
(if (and skip-last (not furthest-cursor)) (if (and skip-last (not furthest-cursor))
@ -229,12 +229,12 @@ With zero ARG, skip the last one and mark next."
(defun mc/mark-lines (num-lines direction) (defun mc/mark-lines (num-lines direction)
(dotimes (i num-lines) (dotimes (i num-lines)
(mc/save-excursion (mc/save-excursion
(let ((furthest-cursor (ecase direction (let ((furthest-cursor (cl-ecase direction
(forwards (mc/furthest-cursor-after-point)) (forwards (mc/furthest-cursor-after-point))
(backwards (mc/furthest-cursor-before-point))))) (backwards (mc/furthest-cursor-before-point)))))
(if (overlayp furthest-cursor) (if (overlayp furthest-cursor)
(goto-char (overlay-get furthest-cursor 'point)))) (goto-char (overlay-get furthest-cursor 'point))))
(ecase direction (cl-ecase direction
(forwards (next-logical-line 1 nil)) (forwards (next-logical-line 1 nil))
(backwards (previous-logical-line 1 nil))) (backwards (previous-logical-line 1 nil)))
(mc/create-fake-cursor-at-point)))) (mc/create-fake-cursor-at-point))))

View File

@ -25,17 +25,7 @@
;;; Code: ;;; Code:
(if (require 'cl-lib nil t) (require 'cl-lib)
(eval-and-compile
(defalias 'count-if 'cl-count-if)
(defalias 'find-if 'cl-find-if)
(defalias 'incf 'cl-incf)
(defalias 'sort* 'cl-sort)
(defalias 'remove-if 'cl-remove-if)
(defalias 'remove-if-not 'cl-remove-if-not)
(defalias 'symbol-macrolet 'cl-symbol-macrolet))
(require 'cl))
(require 'rect) (require 'rect)
(defvar mc--read-char) (defvar mc--read-char)
@ -62,7 +52,7 @@
(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)
(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)))))
@ -183,7 +173,7 @@ highlights the entire width of the window."
(defun mc/create-cursor-id () (defun mc/create-cursor-id ()
"Returns a unique cursor id" "Returns a unique cursor id"
(incf mc--current-cursor-id)) (cl-incf mc--current-cursor-id))
(defvar mc--max-cursors-original nil (defvar mc--max-cursors-original nil
"This variable maintains the original maximum number of cursors. "This variable maintains the original maximum number of cursors.
@ -298,7 +288,7 @@ cursor with updated info."
(defun mc/cursor-with-id (id) (defun mc/cursor-with-id (id)
"Find the first cursor with the given id, or nil" "Find the first cursor with the given id, or nil"
(find-if #'(lambda (o) (and (mc/fake-cursor-p o) (cl-find-if #'(lambda (o) (and (mc/fake-cursor-p o)
(= id (overlay-get o 'mc-id)))) (= id (overlay-get o 'mc-id))))
(overlays-in (point-min) (point-max)))) (overlays-in (point-min) (point-max))))
@ -331,7 +321,7 @@ cursor with updated info."
(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+ (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
@ -570,7 +560,7 @@ for running commands with multiple cursors.")
(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."
(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"
" '(") " '(")
(newline-and-indent) (newline-and-indent)
@ -772,7 +762,6 @@ for running commands with multiple cursors.")
;; Local Variables: ;; Local Variables:
;; coding: utf-8 ;; coding: utf-8
;; byte-compile-warnings: (not cl-functions)
;; End: ;; End:
;;; multiple-cursors-core.el ends here ;;; multiple-cursors-core.el ends here

View File

@ -1,2 +1,3 @@
(define-package "multiple-cursors" "1.3.0" (define-package "multiple-cursors" "1.3.0"
"Multiple cursors for Emacs.") "Multiple cursors for Emacs."
'((cl-lib "0.5")))