From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.bugs Subject: bug#22873: #22873 (multiple fake cursors) Date: Wed, 27 Dec 2017 17:20:46 -0800 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Trace: blaine.gmane.org 1514423958 28095 195.159.176.226 (28 Dec 2017 01:19:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 28 Dec 2017 01:19:18 +0000 (UTC) Cc: Marcin Borkowski , 22873@debbugs.gnu.org, Richard Stallman To: "John Wiegley" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 28 02:19:13 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUMqm-0006xq-C0 for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Dec 2017 02:19:13 +0100 Original-Received: from localhost ([::1]:56212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUMsk-0002md-Sz for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Dec 2017 20:21:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUMsb-0002kX-M5 for bug-gnu-emacs@gnu.org; Wed, 27 Dec 2017 20:21:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUMsY-00088G-7n for bug-gnu-emacs@gnu.org; Wed, 27 Dec 2017 20:21:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45650) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eUMsX-00087z-Uu for bug-gnu-emacs@gnu.org; Wed, 27 Dec 2017 20:21:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eUMsX-00081m-Mo for bug-gnu-emacs@gnu.org; Wed, 27 Dec 2017 20:21:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Keith David Bershatsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 28 Dec 2017 01:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22873 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22873-submit@debbugs.gnu.org id=B22873.151442405330823 (code B ref 22873); Thu, 28 Dec 2017 01:21:01 +0000 Original-Received: (at 22873) by debbugs.gnu.org; 28 Dec 2017 01:20:53 +0000 Original-Received: from localhost ([127.0.0.1]:54331 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUMsO-000815-Go for submit@debbugs.gnu.org; Wed, 27 Dec 2017 20:20:52 -0500 Original-Received: from gateway34.websitewelcome.com ([192.185.148.196]:20565) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUMsM-00080w-9y for 22873@debbugs.gnu.org; Wed, 27 Dec 2017 20:20:51 -0500 Original-Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 1FCB953CB0 for <22873@debbugs.gnu.org>; Wed, 27 Dec 2017 19:20:48 -0600 (CST) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id UMsJeyIglmzEzUMsJeSt0a; Wed, 27 Dec 2017 19:20:48 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com ; s=default; h=Content-Type:MIME-Version:Subject:Cc:To:From:Message-ID:Date: Sender:Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=rnRMbSukj55AMN9ZEwjrQDGwiladvvtPhGMpr/ApL8M=; b=IFKfxEa/TypDqpHNm8NpNAhrj1 Ol9O3TkHIOZq5+juRXNegHLTIu7QdcNX125vliS8CcGRFwgdBXhE+wDBp5Jsz66OZmoIcPiLjPpdE XfXlDopE8eVWgxzk2UlJTig2uZJC3IpEqtodOw6zr6Zdck9oZZ9WfZd/3cKUwo9eKh1w86vABi/jj w4aDxUedr3/YJnBuJ5IK978+LQ1847ptqmFvKDrpvRHB2NI6Io0sDOAw43MjS98lPlEqOD0mPwNDq q3wSF0/eRYJfzFGYPPxEL9See6IJ8hMqmJWIBXmY/cFKAmJ3Tl0Mto4p8SX5UaErtNXyVNBdKHpu7 J2JKoZLw==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:52472 helo=server.private) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.89) (envelope-from ) id 1eUMsJ-000qGA-0g; Wed, 27 Dec 2017 19:20:47 -0600 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3053.hostgator.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-BWhitelist: no X-Source-IP: 45.48.239.195 X-Source-L: No X-Exim-ID: 1eUMsJ-000qGA-0g X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: cpe-45-48-239-195.socal.res.rr.com (server.private) [45.48.239.195]:52472 X-Source-Auth: lawlist X-Email-Count: 4 X-Source-Cap: bGF3bGlzdDtsYXdsaXN0O2dhdG9yMzA1My5ob3N0Z2F0b3IuY29t X-Local-Domain: yes X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:141554 Archived-At: John: Here is an example modification to the most recent version Magnar's multiple-cursors package to make use of #22873 with the patch.diff from earlier today for Emacs 26. I like yellow for even numbered columns and red for odd numbered columns, and I like the vertical bar fake cursor, so that is what is used in this example. (require 'multiple-cursors-core) (require 'cl) ;; for oddp and evenp (add-hook 'multiple-cursors-mode-disabled-hook (lambda () (kill-local-variable 'mc-glyph-list))) (defvar mc/use-built-in-cursors t "Whether to use the built-in fake cursors.") (defun mc/create-fake-cursor-at-point (&optional id) "Add a fake cursor and possibly a fake active region overlay based on point and mark. Saves the current state in the overlay to be restored later." (unless mc--max-cursors-original (setq mc--max-cursors-original mc/max-cursors)) (when mc/max-cursors (unless (< (mc/num-cursors) mc/max-cursors) (if (yes-or-no-p (format "%d active cursors. Continue? " (mc/num-cursors))) (setq mc/max-cursors (read-number "Enter a new, temporary maximum: ")) (mc/remove-fake-cursors) (error "Aborted: too many cursors")))) (let ((overlay (if mc/use-built-in-cursors (make-overlay (point) (point)) (mc/make-cursor-overlay-at-point)))) (overlay-put overlay 'mc-id (or id (mc/create-cursor-id))) (overlay-put overlay 'type 'fake-cursor) (overlay-put overlay 'priority 100) (mc/store-current-state-in-overlay overlay) (when (use-region-p) (overlay-put overlay 'region-overlay (mc/make-region-overlay-between-point-and-mark))) overlay)) (defun mc/execute-this-command-for-all-cursors-1 () "Used with post-command-hook to execute supported commands for all cursors. It uses two lists of commands to know what to do: the run-once list and the run-for-all list. If a command is in neither of these lists, it will prompt for the proper action and then save that preference. Some commands are so unsupported that they are even prevented for the original cursor, to inform about the lack of support." (unless mc--executing-command-for-fake-cursor (if (eq 1 (mc/num-cursors)) ;; no fake cursors? disable mc/mode (mc/mode 0) (when this-original-command (let ((original-command (or mc--this-command (command-remapping this-original-command) this-original-command))) ;; skip keyboard macros, since they will generate actual commands that are ;; also run in the command loop - we'll handle those later instead. (when (functionp original-command) ;; if it's a lambda, we can't know if it's supported or not ;; - so go ahead and assume it's ok, because we're just optimistic like that (if (or (not (symbolp original-command)) ;; lambda registered by smartrep (string-prefix-p "(" (symbol-name original-command))) (mc/execute-command-for-all-fake-cursors original-command) ;; smartrep `intern's commands into own obarray to help ;; `describe-bindings'. So, let's re-`intern' here to ;; make the command comparable by `eq'. (setq original-command (intern (symbol-name original-command))) ;; otherwise it's a symbol, and we can be more thorough (if (get original-command 'mc--unsupported) (message "%S is not supported with multiple cursors%s" original-command (get original-command 'mc--unsupported)) (when (and original-command (not (memq original-command mc--default-cmds-to-run-once)) (not (memq original-command mc/cmds-to-run-once)) (or (memq original-command mc--default-cmds-to-run-for-all) (memq original-command mc/cmds-to-run-for-all) (mc/prompt-for-inclusion-in-whitelist original-command))) (mc/execute-command-for-all-fake-cursors original-command)))) (when mc/use-built-in-cursors (let* ((win (selected-window)) (window-start (window-start win)) (window-end (window-end win)) (overlays (mc/all-fake-cursors)) (lst (mapcar (lambda (x) (let* ((pos (overlay-start x)) (current-column (if (and (>= pos window-start) (<= pos window-end)) (save-excursion (goto-char pos) (current-column)) 0))) (cond ((oddp current-column) (list pos "bar" "#FF0000")) ;; red or [1.0 0.0 0.0] ((evenp current-column) (list pos "bar" "yellow"))))) ;; [1.0 1.0 0.0] overlays))) (setq mc-glyph-list lst))))))))) (defun mc/execute-this-command-for-all-cursors-1 () "Used with post-command-hook to execute supported commands for all cursors. It uses two lists of commands to know what to do: the run-once list and the run-for-all list. If a command is in neither of these lists, it will prompt for the proper action and then save that preference. Some commands are so unsupported that they are even prevented for the original cursor, to inform about the lack of support." (unless mc--executing-command-for-fake-cursor (if (eq 1 (mc/num-cursors)) ;; no fake cursors? disable mc-mode (multiple-cursors-mode 0) (when this-original-command (let ((original-command (or mc--this-command (command-remapping this-original-command) this-original-command))) ;; skip keyboard macros, since they will generate actual commands that are ;; also run in the command loop - we'll handle those later instead. (when (functionp original-command) ;; if it's a lambda, we can't know if it's supported or not ;; - so go ahead and assume it's ok, because we're just optimistic like that (if (or (not (symbolp original-command)) ;; lambda registered by smartrep (string-prefix-p "(" (symbol-name original-command))) (mc/execute-command-for-all-fake-cursors original-command) ;; smartrep `intern's commands into own obarray to help ;; `describe-bindings'. So, let's re-`intern' here to ;; make the command comparable by `eq'. (setq original-command (intern (symbol-name original-command))) ;; otherwise it's a symbol, and we can be more thorough (if (get original-command 'mc--unsupported) (message "%S is not supported with multiple cursors%s" original-command (get original-command 'mc--unsupported)) (when (and original-command (not (memq original-command mc--default-cmds-to-run-once)) (not (memq original-command mc/cmds-to-run-once)) (or mc/always-run-for-all (memq original-command mc--default-cmds-to-run-for-all) (memq original-command mc/cmds-to-run-for-all) (mc/prompt-for-inclusion-in-whitelist original-command))) (mc/execute-command-for-all-fake-cursors original-command)))))) (when mc/use-built-in-cursors (let* ((win (selected-window)) (window-start (window-start win)) (window-end (window-end win)) (overlays (mc/all-fake-cursors)) (lst (mapcar (lambda (x) (let* ((pos (overlay-start x)) (current-column (if (and (>= pos window-start) (<= pos window-end)) (save-excursion (goto-char pos) (current-column)) 0))) (cond ((oddp current-column) (list pos "bar" "#FF0000")) ;; red or [1.0 0.0 0.0] ((evenp current-column) (list pos "bar" "yellow"))))) ;; [1.0 1.0 0.0] overlays))) (setq mc-glyph-list lst))) ))))