Browse Source

Multiple cursors custom clipboard, misc changes

* Added custom multiple-cursors copy/cut/paste handlers to more closely
mimic sublime's MC behavior. The primary things I was fixing was a)
pasting the multiple selection after editing MC and reentering and b)
pasting a single selection in multiple places. I'm much happier with MC
now
* Changed "Buffer" prompt to "Switch Buffer"
* Changed theme
master
Macoy Madson 5 years ago
parent
commit
2ba70ae85f
  1. 130
      Emacs/emacsConfig.txt

130
Emacs/emacsConfig.txt

@ -31,6 +31,10 @@
;; - More minimal appearance
;; - Built-in help (Sublime's documentation can be spotty; Emacs docs can be too complicated)
;;
;; Setup
;; 1. Install all packages in emacsPackages.txt
;; 2. Add macoyCopy, macoyCut, and macoyPaste to mc/cmds-to-run-once and restart Emacs
;;
;; TODO (there are more scattered around this file):
;; - TAGS has to be set up per-project; doesn't allow cross-repository finding afaik
;; It does, you just need to set tags-table-list.
@ -48,6 +52,7 @@
;; - Copy line when nothing is marked
;; - Ido jump to file anywhere does more harm than good (especially when creating new files)
;; - Python indentation is godawful
;; - Multiple cursors copy and cut when whole line selected
;; Emacs Notes
;; C-h k <the keybind> to find what a key does
@ -214,8 +219,9 @@
;; Show whitespace (damnit emacs don't use spaces for indentation!) (doesn't quite work)
;;(require 'whitespace)
;;(global-whitespace-mode 0)
;;(setq whitespace-style '(face spaces indentation::space))
;;(setq whitespace-line-column 100)
(setq whitespace-style '(faces tabs tabs-mark spaces space-mark))
(setq whitespace-line-column 100)
(setq whitespace-newline nil)
;; Multiple cursors
(require 'multiple-cursors)
@ -443,7 +449,7 @@
(interactive)
(desktop-change-dir
(concat macoy-desktop-dir
(ido-completing-read "Desktop:"
(ido-completing-read "Switch Desktop:"
(remove "."
(remove ".."
(directory-files macoy-desktop-dir)))))))
@ -495,23 +501,123 @@
(global-set-key (kbd "M-<f7>") (lambda () (interactive) (buildStop)))
;;
;; Custom copy/cut/paste functions so one key can work for simpleclip and multiple-cursors
;; Custom multiple cursors cut/copy/paste handling
;;
(setq macoy-multiple-cursors-buffers nil)
(setq macoy-mc-buffer-index 0)
(defun macoy-mc-copy ()
(interactive)
(if (use-region-p)
(push (buffer-substring (region-beginning) (region-end)) macoy-multiple-cursors-buffers)
;; TODO: Copy whole line if no region
(message "TODO: Copy whole line if no region selected")
)
)
(defun macoy-mc-cut ()
(interactive)
;; TODO: Cut whole line if no region
(unless (use-region-p)
(message "TODO: Cut whole line if no region selected")
)
(when (use-region-p)
(push (buffer-substring (region-beginning) (region-end)) macoy-multiple-cursors-buffers)
(kill-region (region-beginning) (region-end)))
)
(defun macoy-mc-paste ()
(interactive)
;; Delete selected text before insert if necessary
(when (use-region-p)
(delete-region (region-beginning) (region-end))
)
;; If no macoy-multiple-cursors-buffers the user probably did a simple copy so paste that
(unless macoy-multiple-cursors-buffers
(call-interactively 'simpleclip-paste)
)
(when macoy-multiple-cursors-buffers
(insert (nth macoy-mc-buffer-index macoy-multiple-cursors-buffers))
;; Set up next cursor buffer index
;; Ensure we don't go out of range of the buffers
;; Sublime's behavior is to just paste all buffers at all marks, so our solution is different here
(setq macoy-mc-buffer-index (min
(+ macoy-mc-buffer-index 1)
(- (length macoy-multiple-cursors-buffers) 1)))
)
)
(defun macoy-multiple-cursors-copy()
"Copy at multiple cursors using macoy-multiple-cursors-buffers"
(interactive)
(setq macoy-multiple-cursors-buffers nil)
(mc/for-each-cursor-ordered
(mc/execute-command-for-fake-cursor 'macoy-mc-copy cursor))
;; Append happens in reverse
(setq macoy-multiple-cursors-buffers (reverse macoy-multiple-cursors-buffers))
;; Adding newline isn't correct but emacs won't copy the newline. It is slightly more useful
;; to paste things with the newlines when collapsing multiple selections
(simpleclip-set-contents (string-join macoy-multiple-cursors-buffers "\n"))
)
(defun macoy-multiple-cursors-cut()
"Copy at multiple cursors using macoy-multiple-cursors-buffers"
(interactive)
(setq macoy-multiple-cursors-buffers nil)
(mc/for-each-cursor-ordered
(mc/execute-command-for-fake-cursor 'macoy-mc-cut cursor))
(setq macoy-multiple-cursors-buffers (reverse macoy-multiple-cursors-buffers))
;; Adding newline isn't correct but emacs won't copy the newline. It is slightly more useful
;; to paste things with the newlines when collapsing multiple selections
(simpleclip-set-contents (string-join macoy-multiple-cursors-buffers "\n"))
)
(defun macoy-multiple-cursors-paste()
"Paste at multiple cursors using macoy-multiple-cursors-buffers"
(interactive)
(setq macoy-mc-buffer-index 0)
(mc/for-each-cursor-ordered
(mc/execute-command-for-fake-cursor 'macoy-mc-paste cursor))
)
(defun macoy-test-multiple-cursors-print-list()
"Print buffers"
(interactive)
(message "%d in buffer" (length macoy-multiple-cursors-buffers))
(dolist (buffer macoy-multiple-cursors-buffers)
(message "Buffer: %s" buffer))
)
;;
;; Custom copy/cut/paste functions so one key can work for simpleclip and multiple-cursors
;; Make sure to add these to mc/cmds-to-run-once and restart Emacs
(defun macoyCopy ()
(interactive)
;; Clear buffers here in case they aren't using multiple cursors
;; Then, if they paste in multiple-cursors-mode it will paste simpleclip
(setq macoy-multiple-cursors-buffers nil)
(if (bound-and-true-p multiple-cursors-mode)
(call-interactively 'kill-ring-save)
(call-interactively 'macoy-multiple-cursors-copy) ;; Was kill-ring-save
(call-interactively 'simpleclip-copy))
)
(defun macoyCut ()
(interactive)
;; Clear buffers here in case they aren't using multiple cursors
;; Then, if they paste in multiple-cursors-mode it will paste simpleclip
(setq macoy-multiple-cursors-buffers nil)
(if (bound-and-true-p multiple-cursors-mode)
(call-interactively 'kill-region)
(call-interactively 'macoy-multiple-cursors-cut) ;; Was kill-region
(call-interactively 'simpleclip-cut))
)
(defun macoyPaste ()
(interactive)
(if (bound-and-true-p multiple-cursors-mode)
(call-interactively 'yank)
(call-interactively 'macoy-multiple-cursors-paste) ;; Was yank
(call-interactively 'simpleclip-paste))
)
@ -523,9 +629,9 @@
(define-key map (kbd "C-d") 'mc/mark-next-like-this)
(define-key map (kbd "C-M-a") 'macoy-clang-format-region-or-buffer)
;; Custom copy/paste functions for working with simpleclip and multiple-cursors
(define-key map (kbd "C-c") (lambda () (interactive) (macoyCopy)))
(define-key map (kbd "C-v") (lambda () (interactive) (macoyPaste)))
(define-key map (kbd "C-x") (lambda () (interactive) (macoyCut)))
(define-key map (kbd "C-c") 'macoyCopy)
(define-key map (kbd "C-v") 'macoyPaste)
(define-key map (kbd "C-x") 'macoyCut)
;; In case you need the dumb copy paste (or multiple cursors clipboard after exiting mc)
(define-key map (kbd "C-S-c") 'kill-ring-save)
(define-key map (kbd "C-S-v") 'yank)
@ -685,7 +791,7 @@
'(back-button-local-forward-keystrokes (quote ("S-<delete>")))
'(back-button-local-keystrokes (quote ("C-S-x <C-SPC>")))
'(back-button-smartrep-prefix "C-S-x")
'(custom-enabled-themes (quote (base16-gruvbox-dark-pale)))
'(custom-enabled-themes (quote (base16-ashes)))
'(desktop-registry-registry
(quote
((".emacs.d" . "c:/Users/mmadson/AppData/Roaming/.emacs.d")
@ -747,7 +853,7 @@ static char *gnus-pointer[] = {
("melpa" . "http://melpa.org/packages/"))))
'(package-selected-packages
(quote
(etags-select desktop-registry simpleclip yasnippet swiper company ac-etags auto-complete clang-format avy ace-jump-mode ag xah-find dtrt-indent flx-ido ido-vertical-mode sublime-themes smooth-scrolling alect-themes base16-theme powerline darktooth-theme dumb-jump projectile smex fiplr helm-dash better-defaults multiple-cursors zenburn-theme marmalade-demo)))
(adaptive-wrap web-beautify etags-select desktop-registry simpleclip yasnippet swiper company ac-etags auto-complete clang-format avy ace-jump-mode ag xah-find dtrt-indent flx-ido ido-vertical-mode sublime-themes smooth-scrolling alect-themes base16-theme powerline darktooth-theme dumb-jump projectile smex fiplr helm-dash better-defaults multiple-cursors zenburn-theme marmalade-demo)))
'(pos-tip-background-color "#36473A")
'(pos-tip-foreground-color "#FFFFC8")
'(projectile-globally-ignored-directories

Loading…
Cancel
Save