1 ;; -*- lexical-binding: t; -*-
3 (defvar lh/filepath-delims
6 (defun lh/region-bounds-full-lines (start end)
10 (line-beginning-position))
13 (line-end-position))))
15 (defun lh/move-region-up ()
17 (let* ((deactivate-mark nil)
18 (bounds (lh/region-bounds-full-lines (region-beginning) (region-end)))
19 (text (buffer-substring (car bounds) (cdr bounds))))
20 (delete-region (car bounds) (cdr bounds))
27 (defun lh/move-line-up ()
34 (defun lh/move-region-down ()
36 (let* ((deactivate-mark nil)
37 (bounds (lh/region-bounds-full-lines (region-beginning) (region-end)))
38 (text (buffer-substring (car bounds) (cdr bounds))))
39 (delete-region (car bounds) (cdr bounds))
47 (defun lh/move-line-down ()
55 (defun lh/extern-open-file (file)
56 (shell-command (concat "xdg-open " (shell-quote-argument file))))
58 (defun lh/extern-open-current-file ()
60 (let ((files (if (eq major-mode 'dired-mode)
61 (dired-get-marked-files)
62 (list (buffer-file-name)))))
63 (mapc #'lh/extern-open-file files)))
65 (defun lh/file-name-from-cursor ()
68 (search-backward-regexp lh/filepath-delims)
72 (search-forward-regexp lh/filepath-delims)
75 (buffer-substring start end))))
77 (defun lh/extern-open-file-at-cursor ()
79 (lh/extern-open-file (lh/file-name-from-cursor)))
81 (defun lh/base64-encode-file (filename)
83 (insert-file-contents filename)
84 (base64-encode-region (point-min) (point-max))
87 (defun lh/root-current-buffer (sudo)
88 (let ((old-point (point))
89 (old (current-buffer)))
90 (find-file (concat "/" sudo "::" (buffer-file-name)))
94 (defun lh/doas-current-buffer ()
96 (lh/root-current-buffer "doas"))
98 (defun lh/sudo-current-buffer ()
100 (lh/root-current-buffer "sudo"))
102 (defun lh/buffer-create-new ()
104 (let ((buf (generate-new-buffer "new")))
105 (switch-to-buffer buf)
106 (setq-local buffer-offer-save t)
109 (defun lh/pop-out-buffer ()
112 (switch-to-prev-buffer))