[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 653d523 308/434: Added mc-hide-unmatched-
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 653d523 308/434: Added mc-hide-unmatched-lines mode |
Date: |
Sat, 7 Aug 2021 09:20:48 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 653d52352d4ae16178d2236d911c7fca3f9875fa
Author: lexa <lexa@cfotr.com>
Commit: lexa <lexa@cfotr.com>
Added mc-hide-unmatched-lines mode
This minor mode when enabled hides all lines where no cursors (and
also hum/lines-to-expand below and above) To make use of this mode
press "C-'" while multiple-cursor-mode is active. You can still
edit lines while you are in mc-hide-unmatched-lines mode. To leave
this mode press "<return>" or "C-g"
---
mc-hide-unmatched-lines-mode.el | 119 ++++++++++++++++++++++++++++++++++++++++
multiple-cursors-core.el | 3 +
multiple-cursors.el | 1 +
3 files changed, 123 insertions(+)
diff --git a/mc-hide-unmatched-lines-mode.el b/mc-hide-unmatched-lines-mode.el
new file mode 100644
index 0000000..67375bf
--- /dev/null
+++ b/mc-hide-unmatched-lines-mode.el
@@ -0,0 +1,119 @@
+;;; mc-hide-unmatched-lines.el
+
+;; Copyright (C) 2014 Aleksey Fedotov
+
+;; Author: Aleksey Fedotov <lexa@cfotr.com>
+;; Keywords: editing cursors
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This minor mode when enabled hides all lines where no cursors (and
+;; also hum/lines-to-expand below and above) To make use of this mode
+;; press "C-'" while multiple-cursor-mode is active. You can still
+;; edit lines while you are in mc-hide-unmatched-lines mode. To leave
+;; this mode press "<return>" or "C-g"
+;;
+
+;;; Code:
+
+
+(require 'multiple-cursors-core)
+
+(defvar hum/hide-unmatched-lines-mode-map (make-sparse-keymap)
+ "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 "<return>")
'hum/keyboard-quit)
+
+(defun hum/keyboard-quit ()
+ "Leave hide-unmatched-lines mode"
+ (interactive)
+ (mc-hide-unmatched-lines-mode 0))
+
+;; used only in in multiple-cursors-mode-disabled-hook
+(defun hum/disable-hum-mode ()
+ (mc-hide-unmatched-lines-mode 0)
+)
+
+(define-minor-mode mc-hide-unmatched-lines-mode
+ "Minor mode when enabled hides all lines where no cursos (and
+also hum/lines-to-expand below and above) To make use of this
+mode press \"C-'\" while multiple-cursor-mode is active. You can
+still edit lines while you are in mc-hide-unmatched-lines
+mode. To leave this mode press <return> or \"C-g\""
+ nil " hu"
+ hum/hide-unmatched-lines-mode-map
+ (if mc-hide-unmatched-lines-mode
+ ;;just in case if mc mode will be disabled while hide-unmatched-lines is
active
+ (progn
+ (hum/hide-unmatched-lines)
+ (add-hook 'multiple-cursors-mode-disabled-hook 'hum/disable-hum-mode t
t))
+ (progn
+ (hum/unhide-unmatched-lines)
+ (remove-hook 'multiple-cursors-mode-disabled-hook 'hum/disable-hum-mode))
+ )
+)
+
+(defconst hum/invisible-overlay-name 'hum/invisible-overlay-name)
+
+(defcustom hum/lines-to-expand 2
+ "How many lines below and above cursor to show"
+ :type '(integer)
+ :group 'multiple-cursors)
+
+(defcustom hum/placeholder "..."
+ "Placeholder which will be placed insted of hiden text"
+ :type '(string)
+ :group 'multiple-cursors
+)
+
+(defun hum/add-invisible-overlay (begin end)
+ (let ((overlay (make-overlay begin
+ end
+ (current-buffer)
+ t
+ nil
+ )))
+ (overlay-put overlay hum/invisible-overlay-name t)
+ (overlay-put overlay 'invisible t)
+ (overlay-put overlay 'intangible t)
+ (overlay-put overlay 'evaporate t)
+ (overlay-put overlay 'after-string hum/placeholder)
+ )
+ )
+
+
+(defun hum/hide-unmatched-lines ()
+ (let ((begin (point-min)))
+ (mc/for-each-cursor-ordered
+ (save-excursion
+ (goto-char (mc/cursor-beg cursor))
+ (if (< begin (line-beginning-position (- hum/lines-to-expand)))
+ (hum/add-invisible-overlay begin (line-end-position (-
hum/lines-to-expand)))
+ )
+ (setq begin (line-beginning-position (+ 2 hum/lines-to-expand)))
+ )
+ )
+ (hum/add-invisible-overlay begin (point-max))
+ )
+ )
+
+(defun hum/unhide-unmatched-lines ()
+ (remove-overlays nil nil hum/invisible-overlay-name t)
+ )
+
+(provide 'mc-hide-unmatched-lines-mode)
+(define-key mc/keymap (kbd "C-'") 'mc-hide-unmatched-lines-mode)
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index 974b1b8..bc8a279 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -596,6 +596,9 @@ for running commands with multiple cursors.")
mc/skip-to-next-like-this
mc/skip-to-previous-like-this
rrm/switch-to-multiple-cursors
+ mc-hide-unmatched-lines-mode
+ hum/keyboard-quit
+ hum/unhide-invisible-overlays
save-buffer
ido-exit-minibuffer
exit-minibuffer
diff --git a/multiple-cursors.el b/multiple-cursors.el
index 9c847ee..9c44db9 100644
--- a/multiple-cursors.el
+++ b/multiple-cursors.el
@@ -185,6 +185,7 @@
(require 'mc-mark-pop)
(require 'rectangular-region-mode)
(require 'mc-separate-operations)
+(require 'mc-hide-unmatched-lines-mode)
(provide 'multiple-cursors)
- [nongnu] elpa/multiple-cursors 4535033 235/434: Added a new function mc/mark-pop that sets cursors by popping marks off the mark stack., (continued)
- [nongnu] elpa/multiple-cursors 4535033 235/434: Added a new function mc/mark-pop that sets cursors by popping marks off the mark stack., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 4748386 238/434: Make mc/mark-pop only run once per invocation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors be7905d 258/434: Update README to note that there is a mode allowing search in multiple-cursors., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors a86daa7 270/434: Guard with 'if' rather than defun*/return-from, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 18d858f 272/434: Fall straight through in 'mc/mark-all-dwim' if multiple cursors are already active, as that means we can't sensibly edit lines or mark all in region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 2b536cb 283/434: Added mc/edit-lines-empty-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 75ece68 288/434: Merge pull request #118 from aspiers/fix-compile-warnings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 9f4502b 304/434: Change file load timing, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors e94567c 303/434: Add installation instructions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 98f2346 305/434: Merge pull request #152 from ShingoFukuyama/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 653d523 308/434: Added mc-hide-unmatched-lines mode,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors 3f1611c 345/434: Factor out a superfluous variable, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 68961b4 355/434: Avoid requiring cl at runtime, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 4c52fb1 358/434: Merge pull request #239 from ilohmar/dwim-mouse-select, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors e31b1eb 360/434: Merge pull request #240 from ilohmar/toggle-click-improvements, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6a62e60 367/434: Fix issue #131 (#247), ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 2329611 380/434: Merge remote-tracking branch 'upstream/master', ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 60b9ef8 385/434: Updated readme according to `mc/always-run-for-all, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ad95d28 386/434: Update docstring of `mc/cursor-is-bar`, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 21e4825 387/434: mc/mark-previous-like-this-word/symbol., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 95f2e41 391/434: Add @AndreaOrru to list of contributors, ELPA Syncer, 2021/08/07