Browse Source

Clipboard no selection support, org quick jump to file

* Added copy/cut support for when no region is active. I replicated
Sublime Text's behaviors
* Added ido menu for jumping to my org files. I think I'll genericize
this later
master
macoymadson@gmail.com 3 years ago
parent
commit
eb973500fc
  1. 1
      Emacs/build-systems.el
  2. 116
      Emacs/clipboard.el
  3. 4
      Emacs/core-settings.el
  4. 8
      Emacs/keybinds.el
  5. 34
      Emacs/org-customizations.el

1
Emacs/build-systems.el

@ -37,7 +37,6 @@
(setq macoy-build-system-default nil)
;; TODO: Figure out why this doesn't work
(defun macoy-build-system-build ()
"Build the build system defined in `macoy-build-system-default'"
(interactive)

116
Emacs/clipboard.el

@ -2,51 +2,82 @@
;; Custom multiple cursors cut/copy/paste handling
;;
(when (and (require 'simpleclip) (require 'multiple-cursors))
;; To replicate Sublime behavior, if copy or cut is executed, do the operation for the whole line.
;; When pasting, paste that line above the current line, regardless of point position
(setq macoy-clipboard-no-selection-line-paste nil)
(setq macoy-multiple-cursors-buffers nil)
(setq macoy-mc-buffer-index 0)
;;
;; Internal, per-cursor cxp functions for multiple-cursors
;;
(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")
)
)
(progn (push (buffer-substring (region-beginning) (region-end)) macoy-multiple-cursors-buffers)
(setq macoy-clipboard-no-selection-line-paste nil))
;; Nothing marked? Copy whole line
(progn
(push (buffer-substring (line-beginning-position) (line-end-position)) macoy-multiple-cursors-buffers)
(setq macoy-clipboard-no-selection-line-paste t))))
(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")
)
(push (buffer-substring (line-beginning-position) (line-end-position)) macoy-multiple-cursors-buffers)
;; (kill-region (line-beginning-position) (line-end-position))
(kill-whole-line)
(setq macoy-clipboard-no-selection-line-paste t))
(when (use-region-p)
(push (buffer-substring (region-beginning) (region-end)) macoy-multiple-cursors-buffers)
(kill-region (region-beginning) (region-end)))
)
(kill-region (region-beginning) (region-end))
(setq macoy-clipboard-no-selection-line-paste nil)))
;; Respect macoy-clipboard-no-selection-line-paste
(defun macoy-simpleclip-paste ()
(interactive)
(save-excursion
(if macoy-clipboard-no-selection-line-paste
(progn
(back-to-indentation)
(newline)
(call-interactively 'indent-for-tab-command)
(previous-line)
(call-interactively 'simpleclip-paste)
(call-interactively 'indent-for-tab-command))
(call-interactively 'simpleclip-paste))))
(defun macoy-mc-paste ()
(interactive)
;; Delete selected text before insert if necessary
(when (use-region-p)
(delete-region (region-beginning) (region-end))
)
(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)
)
(call-interactively 'macoy-simpleclip-paste))
(when macoy-multiple-cursors-buffers
(insert (nth macoy-mc-buffer-index macoy-multiple-cursors-buffers))
(save-excursion
(if macoy-clipboard-no-selection-line-paste
(progn
(back-to-indentation)
(newline)
(call-interactively 'indent-for-tab-command)
(previous-line)
(insert (nth macoy-mc-buffer-index macoy-multiple-cursors-buffers))
(call-interactively 'indent-for-tab-command))
(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)))
)
)
(- (length macoy-multiple-cursors-buffers) 1)))))
;;
;; Cxp functions at all cursors (uses internal functions)
;;
;; For versions newer than 25.3 or something :(
(defun string-join (sl delim)
@ -62,8 +93,7 @@
(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"))
)
(simpleclip-set-contents (string-join macoy-multiple-cursors-buffers "\n")))
(defun macoy-multiple-cursors-cut()
"Cut at multiple cursors using `macoy-multiple-cursors-buffers'"
@ -74,24 +104,47 @@
(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"))
)
(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))
)
(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))
)
(message "Buffer: %s" buffer)))
;;
;; Internal, non-mc cx functions (to duplicate no region line copy behavior)
;;
(defun macoy-nonmc-copy ()
(interactive)
(if (use-region-p)
(progn (simpleclip-set-contents (buffer-substring (region-beginning) (region-end)))
(setq macoy-clipboard-no-selection-line-paste nil))
;; Nothing marked? Copy whole line
(progn (simpleclip-set-contents
(buffer-substring (line-beginning-position)
(line-end-position)))
(setq macoy-clipboard-no-selection-line-paste t))))
(defun macoy-nonmc-cut ()
(interactive)
(unless (use-region-p)
(simpleclip-set-contents (buffer-substring (line-beginning-position) (line-end-position)))
;; (kill-region (line-beginning-position) (line-end-position))
(kill-whole-line)
(setq macoy-clipboard-no-selection-line-paste t))
(when (use-region-p)
(simpleclip-cut (region-beginning) (region-end))
(setq macoy-clipboard-no-selection-line-paste nil)))
;;
;; Custom copy/cut/paste functions so one key can work for simpleclip and multiple-cursors
@ -104,8 +157,7 @@
(setq macoy-multiple-cursors-buffers nil)
(if (bound-and-true-p multiple-cursors-mode)
(call-interactively 'macoy-multiple-cursors-copy) ;; Was kill-ring-save
(call-interactively 'simpleclip-copy))
)
(call-interactively 'macoy-nonmc-copy)))
(defun macoyCut ()
(interactive)
@ -114,13 +166,11 @@
(setq macoy-multiple-cursors-buffers nil)
(if (bound-and-true-p multiple-cursors-mode)
(call-interactively 'macoy-multiple-cursors-cut) ;; Was kill-region
(call-interactively 'simpleclip-cut))
)
(call-interactively 'macoy-nonmc-cut)))
(defun macoyPaste ()
(interactive)
(if (bound-and-true-p multiple-cursors-mode)
(call-interactively 'macoy-multiple-cursors-paste) ;; Was yank
(call-interactively 'simpleclip-paste))
)
(call-interactively 'macoy-simpleclip-paste)))
)

4
Emacs/core-settings.el

@ -99,8 +99,10 @@
)
)
;; Store recently closed files so we can easily reopen them
;; Store recently opened files so we can easily reopen them
(recentf-mode 1)
;; Store more recent files
(setq recentf-max-saved-items 100)
;; Smex: Smart M-x completion
(when (require 'smex)

8
Emacs/keybinds.el

@ -253,10 +253,10 @@
(define-key map (kbd "C-v") 'macoyPaste)
(unless macoy-edebug-prefix-hack
(define-key map (kbd "C-u") 'macoyCut)) ;; Actually C-x after keyboard-translate
;; 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)
(define-key map (kbd "C-S-x") 'kill-region)
;; In case you need the dumb copy paste
;; (define-key map (kbd "C-S-c") 'kill-ring-save)
;; (define-key map (kbd "C-S-v") 'yank)
;; (define-key map (kbd "C-S-x") 'kill-region)
(define-key map (kbd "M-a") 'macoy-tags-query-replace)
(define-key map (kbd "M-j") 'pop-global-mark)
;; Overrides c-indent-line-or-region (this should be in C mode only, plus <tab>)

34
Emacs/org-customizations.el

@ -51,15 +51,39 @@
(setq org-completion-use-ido t)
(setq org-outline-path-complete-in-steps nil)
;; If non-nil, the effect of TAB in a code block is as if it were
;; issued in the language major mode buffer.
(setq org-src-tab-acts-natively t)
;; My org files
(setq macoy-org-dir nil)
(when (string-equal (user-login-name) "macoy")
(setq org-agenda-files (list "~/Dropbox/Org/1_Calendar.org"
"~/Dropbox/Org/0_Dump.org"))
)
(setq macoy-org-dir "~/Dropbox/Org/")
(setq org-agenda-files (list (concat macoy-org-dir "1_Calendar.org")
(concat macoy-org-dir "0_Dump.org"))))
(when (string-equal (user-login-name) "mmadson")
(setq org-agenda-files (list "C:/Users/mmadson/Dropbox/Org/1_Calendar.org"
"C:/Users/mmadson/Dropbox/Org/0_Dump.org"))
(setq macoy-org-dir "C:/Users/mmadson/Dropbox/Org/")
(setq org-agenda-files (list (concat macoy-org-dir "1_Calendar.org")
(concat macoy-org-dir "0_Dump.org"))))
(when macoy-org-dir
(defun macoy-get-org-file-list ()
(remove "."
(remove ".."
(directory-files macoy-org-dir nil "\\.org"))))
(defun macoy-switch-macoy-org ()
"Use ido to list macoy-orgs to switch to"
(interactive)
(let ((selected-macoy-org
(concat macoy-org-dir
(ido-completing-read "Open Org: "
(macoy-get-org-file-list)))))
(find-file selected-macoy-org)))
(global-set-key (kbd "M-p") 'macoy-switch-macoy-org)
)
;; From https://orgmode.org/manual/Languages.html#Languages

Loading…
Cancel
Save