(require 'cl-lib) (defun copy-line (arg) "Copy lines in the kill ring" (interactive "p") (kill-ring-save (line-beginning-position) (line-beginning-position (+ 1 arg))) (message "%d line%s copied" arg (if (= 1 arg) "" "s"))) (add-to-list 'delete-frame-functions #'kill-buffers-if-deleting-last-frame) (defun frame-list-ignoring-initial-frame () (filtered-frame-list (lambda (frame) (not (equal "initial_terminal" (terminal-name frame)))))) (defun kill-buffers-if-deleting-last-frame (frame) (when (equal (list frame) (frame-list-ignoring-initial-frame)) (dolist (buffer (buffer-list)) (kill-buffer-if-not-modified buffer) buffer))) (defun kill-buffers-not-in-frame () "Kill buffers which are not loaded into some a frame" (interactive) (let ((kill-count 0)) (dolist (buffer (buffer-list)) (if (not (get-buffer-window buffer t)) (if (kill-buffer-if-not-modified buffer) (cl-incf kill-count)))) (message "Killed %d buffers" kill-count))) (defun open-line-above () "Open a new line above point with indentation" (interactive) (beginning-of-line) (newline) (forward-line -1) (indent-for-tab-command)) (defun open-line-below () "Open a new line below point with indentation" (interactive) (end-of-line) (newline) (indent-for-tab-command)) (defun scratch-buffer () "Create a new scratch buffer to work in. (could be *scratch* - *scratchX*)" (interactive) (let ((n 0) bufname) (while (progn (setq bufname (concat "*scratch" (if (= n 0) "" (int-to-string n)) "*")) (setq n (1+ n)) (get-buffer bufname))) (switch-to-buffer (get-buffer-create bufname)) (emacs-lisp-mode) )) (defun toggle-comment-on-line () "Toggles the comment on for the active region if present or the current line otherwise." (interactive) (if (and mark-active transient-mark-mode) (comment-or-uncomment-region (region-beginning) (region-end)) (comment-or-uncomment-region (line-beginning-position) (line-end-position))) (forward-line))