3 (defun my/copy-line (arg)
4 "Copy lines in the kill ring"
6 (kill-ring-save (line-beginning-position)
7 (line-beginning-position (+ 1 arg)))
8 (message "%d line%s copied" arg (if (= 1 arg) "" "s")))
10 (defun my/generate-frame-title ()
11 (if (buffer-file-name)
13 (file-name-nondirectory (buffer-file-name))
14 (if (buffer-modified-p)
17 (abbreviate-file-name (substring (file-name-directory (buffer-file-name)) 0 -1))
22 (if (buffer-modified-p)
26 (defun my/frame-initial-frame-p (frame)
27 "Returns true if the given frame is the magic 'initial frame' that always exists in GUI emacs sessions"
28 (equal "initial_terminal" (terminal-name frame)))
30 (defun my/frame-list-ignoring-initial-frame ()
31 (filtered-frame-list (lambda (frame) (not (my/frame-initial-frame-p frame)))))
33 (defun my/kill-buffer-safely (buffer)
34 "Kill the buffer if it is not special or modified"
36 (not (string-match "^ " (buffer-name buffer)))
37 (not (equal "*Messages*" (buffer-name buffer)))
39 (not (buffer-modified-p buffer))
40 (null (buffer-file-name buffer))))
41 (kill-buffer buffer)))
43 (defun my/kill-buffers-if-deleting-last-frame (frame)
44 "Kill all buffers when closing the last frame"
45 (when (equal (list frame) (my/frame-list-ignoring-initial-frame))
46 (dolist (buffer (buffer-list))
47 (my/kill-buffer-safely buffer))))
49 (defun my/kill-buffers-not-in-frame ()
50 "Kill buffers which are not loaded into some frame"
53 (dolist (buffer (buffer-list))
54 (let* ((window (get-buffer-window buffer t))
55 (frame (window-frame window)))
56 (if (or (null frame) (not (window-live-p window)) (my/frame-initial-frame-p frame))
57 (if (my/kill-buffer-safely buffer)
58 (cl-incf kill-count)))))
59 (message "Killed %d buffers" kill-count)))
61 (defun my/open-line-above ()
62 "Open a new line above point with indentation"
67 (indent-for-tab-command))
69 (defun my/open-line-below ()
70 "Open a new line below point with indentation"
74 (indent-for-tab-command))
76 (defun my/scratch-buffer ()
77 "Create a new scratch buffer to work in. (could be *scratch* - *scratchX*)"
82 (setq bufname (concat "*scratch"
83 (if (= n 0) "" (int-to-string n))
86 (get-buffer bufname)))
87 (switch-to-buffer (get-buffer-create bufname))
91 (defun my/toggle-comment-on-line ()
92 "Toggles the comment on for the active region if present or the current line otherwise."
94 (if (and mark-active transient-mark-mode)
95 (comment-or-uncomment-region (region-beginning) (region-end))
96 (comment-or-uncomment-region (line-beginning-position) (line-end-position)))
99 (defun my/terminal-update-title ()
100 "If using a terminal frame then sends the escape codes to update the title."
101 (if (eq 'terminal-init-xterm (terminal-parameter (frame-terminal) 'terminal-initted))
102 (send-string-to-terminal (concat "\033]0;" (my/generate-frame-title) "\007"))))
104 (defun my/use-eslint-from-node-modules ()
105 (let* ((root (locate-dominating-file
106 (or (buffer-file-name) default-directory)
109 (expand-file-name "node_modules/.bin/eslint" root))))
110 (when (and eslint (file-executable-p eslint))
111 (setq-local flycheck-javascript-eslint-executable eslint))))