]> code.delx.au - dotemacs/blob - lisp/my-defuns.el
massive config improvements, use git-submodule packaging
[dotemacs] / lisp / my-defuns.el
1 (defun copy-line (arg)
2 "Copy lines in the kill ring"
3 (interactive "p")
4 (kill-ring-save (line-beginning-position)
5 (line-beginning-position (+ 1 arg)))
6 (message "%d line%s copied" arg (if (= 1 arg) "" "s")))
7
8 (add-to-list 'delete-frame-functions #'kill-buffers-if-deleting-last-frame)
9
10 (defun frame-list-ignoring-initial-frame ()
11 (filtered-frame-list
12 (lambda (frame)
13 (not (equal "initial_terminal" (terminal-name frame))))))
14
15 (defun kill-buffers-if-deleting-last-frame (frame)
16 (when (equal (list frame) (frame-list-ignoring-initial-frame))
17 (dolist (buffer (buffer-list))
18 (kill-buffer-if-not-modified buffer) buffer)))
19
20 (defun kill-buffers-not-in-frame ()
21 "Kill buffers which are not loaded into some a frame"
22 (interactive)
23 (let ((kill-count 0))
24 (dolist (buffer (buffer-list))
25 (if (not (get-buffer-window buffer t))
26 (if (kill-buffer-if-not-modified buffer)
27 (incf kill-count))))
28 (message "Killed %d buffers" kill-count)))
29
30 (defun open-line-above ()
31 "Open a new line above point with indentation"
32 (interactive)
33 (beginning-of-line)
34 (newline)
35 (forward-line -1)
36 (indent-for-tab-command))
37
38 (defun open-line-below ()
39 "Open a new line below point with indentation"
40 (interactive)
41 (end-of-line)
42 (newline)
43 (indent-for-tab-command))
44
45 (defun scratch-buffer ()
46 "Create a new scratch buffer to work in. (could be *scratch* - *scratchX*)"
47 (interactive)
48 (let ((n 0)
49 bufname)
50 (while (progn
51 (setq bufname (concat "*scratch"
52 (if (= n 0) "" (int-to-string n))
53 "*"))
54 (setq n (1+ n))
55 (get-buffer bufname)))
56 (switch-to-buffer (get-buffer-create bufname))
57 (emacs-lisp-mode)
58 ))
59
60 (defun toggle-comment-on-line ()
61 "Toggles the comment on for the active region if present or the current line otherwise."
62 (interactive)
63 (if (and mark-active transient-mark-mode)
64 (comment-or-uncomment-region (region-beginning) (region-end))
65 (comment-or-uncomment-region (line-beginning-position) (line-end-position)))
66 (forward-line))