-
Notifications
You must be signed in to change notification settings - Fork 14
/
corgi-commands.el
100 lines (87 loc) · 3.38 KB
/
corgi-commands.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;;; corgi-commands.el --- Custom commands included with Corgi
;;
;; Filename: corgi-commands.el
;; Package-Requires: ()
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; Commands that are not available in vanilla emacs, and that are not worth
;; pulling in a separate package to provide them. These should eventually end up
;; in their own utility package, we do not want too much of this stuff directly
;; in the emacs config.
;;
;;; Code:
(require 'seq)
(defun corgi/switch-to-previous-buffer ()
"Switch to previously open buffer.
Repeated invocations toggle between the two most recently open buffers."
(interactive)
(switch-to-buffer (other-buffer (current-buffer))))
(defun corgi/switch-to-last-elisp-buffer ()
(interactive)
(when-let ((the-buf (seq-find (lambda (b)
(with-current-buffer b
(derived-mode-p 'emacs-lisp-mode)))
(buffer-list))))
(pop-to-buffer the-buf)))
(defun corgi/double-columns ()
"Simplified version of spacemacs/window-split-double-column"
(interactive)
(delete-other-windows)
(let* ((previous-files (seq-filter #'buffer-file-name
(delq (current-buffer) (buffer-list)))))
(set-window-buffer (split-window-right)
(or (car previous-files) "*scratch*"))
(balance-windows)))
(defun corgi/open-init-el ()
"Open the user's init.el file"
(interactive)
(find-file (expand-file-name "init.el" user-emacs-directory)))
(defun corgi/-locate-file (fname)
"Like corkey/-locate-file"
(cond
((symbolp fname)
(corgi/-locate-file (concat (symbol-name fname) ".el")))
((file-exists-p (expand-file-name fname user-emacs-directory))
(expand-file-name fname user-emacs-directory))
(t (locate-library fname))))
(defun corgi/open-keys-file ()
"Open the Corgi built-in key binding file"
(interactive)
(find-file (corgi/-locate-file 'corgi-keys)))
(defun corgi/open-signals-file ()
"Open the Corgi built-in signals file"
(interactive)
(find-file (corgi/-locate-file 'corgi-signals)))
(defun corgi/open-user-keys-file ()
"Open the user key binding file in the emacs user directory
Will create one if it doesn't exist."
(interactive)
(let ((keys-file (corgi/-locate-file 'user-keys)))
(when (not keys-file)
(copy-file (corgi/-locate-file 'user-keys-template)
(expand-file-name "user-keys.el" user-emacs-directory)))
(find-file (corgi/-locate-file 'user-keys))))
(defun corgi/open-user-signals-file ()
"Open the user signal file in the emacs user directory
Will create one if it doesn't exist."
(interactive)
(let ((signals-file (corgi/-locate-file 'user-signals)))
(when (not signals-file)
(copy-file (corgi/-locate-file 'user-signals-template)
(expand-file-name "user-signals.el" user-emacs-directory)))
(find-file (corgi/-locate-file 'user-signals))))
;; Taking this out, see explanation in corgi-keys.el
;;
;; (defun corgi/emulate-tab ()
;; "Emulates pressing <tab>, used for binding to TAB for tab key
;; support in terminals."
;; (interactive)
;; (let ((cmd (key-binding (kbd "<tab>"))))
;; (when (commandp cmd)
;; (call-interactively cmd))))
(provide 'corgi-commands)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; corgi-commands.el ends here