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