From fe870a3154e86c87953202ed8d3af210c778fe9b Mon Sep 17 00:00:00 2001 From: "macoymadson@gmail.com" Date: Mon, 4 Mar 2019 14:50:28 -0800 Subject: [PATCH] Use next-logical-line when multiple-cursors is active This along with macoy-end-of-line makes multiple-cursors editing pretty robust against visual wrapping mucking with the edit --- Emacs/keybinds.el | 38 +++++++++++++++++++++++++++++--------- Emacs/visual-early.el | 8 ++++---- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Emacs/keybinds.el b/Emacs/keybinds.el index d6024e0..1dd6d61 100644 --- a/Emacs/keybinds.el +++ b/Emacs/keybinds.el @@ -100,17 +100,37 @@ ;; Go to first character of line, not beginning of line. Was move-beginning-of-line (global-set-key (kbd "") 'back-to-indentation) -;; Go to end of line if multiple-cursors is active. This is important because you -;; might be editing lines which wrap without your knowledge -(defun macoy-end-of-line () - (interactive) - (if (bound-and-true-p multiple-cursors-mode) - (call-interactively 'end-of-line) - (call-interactively 'end-of-visual-line) +(when (require 'multiple-cursors) + ;; Go to end of line if multiple-cursors is active. This is important because you + ;; might be editing lines which wrap without your knowledge + (defun macoy-end-of-line () + (interactive) + (if (bound-and-true-p multiple-cursors-mode) + (call-interactively 'end-of-line) + (call-interactively 'end-of-visual-line) + ) ) - ) -(global-set-key (kbd "") 'macoy-end-of-line) + (global-set-key (kbd "") 'macoy-end-of-line) + + (defun macoy-next-line (&optional arg) + "Go to next logical line if multiple-cursors is active. This is important because you might be +editing lines which wrap without your knowledge" + (interactive) + (if (bound-and-true-p multiple-cursors-mode) + (next-logical-line arg) + (next-line arg) + ) + ) + + (defun macoy-prev-line () + (interactive) + (macoy-next-line -1) + ) + + (global-set-key (kbd "") 'macoy-next-line) + (global-set-key (kbd "") 'macoy-prev-line) + ) ;; Toggle comment lines (same keybind as Sublime). This also works for regions (global-set-key (kbd "C-/") 'comment-line) diff --git a/Emacs/visual-early.el b/Emacs/visual-early.el index a51fde3..51d30c6 100644 --- a/Emacs/visual-early.el +++ b/Emacs/visual-early.el @@ -44,22 +44,22 @@ ;; (smooth-scrolling-mode 1) ;; This is a hack to work around smooth scrolling only being problematic on next-line and prev-line. ;; It's not really worth the effort, but I'm keeping this here in case I change my mind later -;; (defun macoy-prev-line () +;; (defun macoy-prev-line-noscroll () ;; (interactive) ;; (smooth-scrolling-mode 0) ;; (forward-line -1) ;; (smooth-scrolling-mode 1) ;; ) -;; (defun macoy-next-line () +;; (defun macoy-next-line-noscroll () ;; (interactive) ;; (smooth-scrolling-mode 0) ;; (forward-line) ;; (smooth-scrolling-mode 1) ;; ) -;; (global-set-key (kbd "") 'macoy-prev-line) -;; (global-set-key (kbd "") 'macoy-next-line) +;; (global-set-key (kbd "") 'macoy-prev-line-noscroll) +;; (global-set-key (kbd "") 'macoy-next-line-noscroll) ;; Make scrolling less jumpy: this makes it so emacs never centers the cursor if you go scroll off ;; screen, instead, it will scroll by one line. This isn't ideal (smooth-scrolling is ideal), but