about summary refs log tree commit diff
path: root/emacs-elisp/config/functions.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs-elisp/config/functions.el')
-rw-r--r--emacs-elisp/config/functions.el50
1 files changed, 50 insertions, 0 deletions
diff --git a/emacs-elisp/config/functions.el b/emacs-elisp/config/functions.el
new file mode 100644
index 0000000..f8f587b
--- /dev/null
+++ b/emacs-elisp/config/functions.el
@@ -0,0 +1,50 @@
+;; Pop Out Buffer
+;;; Pops the current buffer out into it's own frame.
+(defun pop-out-buffer-into-frame ()
+  (interactive)
+  (let* ((current-buffer (current-buffer))
+         (previous-buffer (other-buffer (current-buffer) t)))  ;; Get the previous buffer in the window
+    ;; Switch the current window back to the previous buffer
+    (set-window-buffer (selected-window) previous-buffer)
+    ;; Create a new frame and show the original buffer there
+    (select-frame (make-frame))
+    (set-window-buffer (selected-window) current-Kill)))
+;; Kill Current Buffer
+;;; kill-this-buffer doesn't work in emacs 30 (relies on menubar visibility?) so this is a small implementation of window.el's /C-x 4 0/.
+(defun kill-current-buffer()
+  (interactive)
+  (let ((buffer-to-kill (current-buffer))))
+  (kill-buffer (current-buffer)))
+
+;; Duplicate Line (stolen from https://github.com/rexim/dotfiles)
+;;; TODO: Expand function to be able duplicate region if region selected
+(defun duplicate-line ()
+  (interactive)
+  (let ((column (- (point) (point-at-bol)))
+        (line (let ((s (thing-at-point 'line t)))
+                (if s (string-remove-suffix "\n" s) ""))))
+    (move-end-of-line 1)
+    (newline)
+    (insert line)
+    (move-beginning-of-line 1)
+    (forward-char column)))
+;; Use bind-key to override other bindings
+(keymap-global-set "C-c y d" 'duplicate-line)
+
+;; Vim's o and S-o (stolen from https://stackoverflow.com/a/2173393)
+(defun vi-open-line-above ()
+  (interactive)
+  (unless (bolp)
+    (beginning-of-line))
+  (newline)
+  (forward-line -1)
+  (indent-according-to-mode))
+
+(defun vi-open-line-below ()
+  (interactive)
+  (unless (eolp)
+    (end-of-line))
+  (newline-and-indent))
+
+(keymap-global-set "C-c O" 'vi-open-line-below)
+(keymap-global-set "C-c o" 'vi-open-line-above)