|
|
@@ -1,13 +1,5 @@
|
|
|
;;; utils.el --- General utility functions -*- lexical-binding: t; -*-
|
|
|
|
|
|
-(defun dired-follow-symlink ()
|
|
|
- "In dired, visit the file or directory at point by its true physical path."
|
|
|
- (interactive)
|
|
|
- (let ((filename (dired-get-file-for-visit)))
|
|
|
- (if filename
|
|
|
- (find-file (file-truename filename))
|
|
|
- (message "No file at point"))))
|
|
|
-
|
|
|
(defun my/delete-word-backward ()
|
|
|
"Delete the previous 'block' of characters without killing them.
|
|
|
Blocks are defined by: whitespace, alphanumerics, or groups of symbols."
|
|
|
@@ -39,37 +31,13 @@ Blocks are defined by: whitespace, alphanumerics, or groups of symbols."
|
|
|
|
|
|
(delete-region (point) end)))))
|
|
|
|
|
|
-(defun my-set-buffer-font ()
|
|
|
- "Set a specific font for the current buffer only."
|
|
|
- (buffer-face-set '(:family "Noto Sans" :height 140)))
|
|
|
-
|
|
|
-(defun my/toggle-quote-wrap-all-in-region (beg end)
|
|
|
- "Toggle wrapping all items in region with double quotes."
|
|
|
- ;;https://xenodium.com/emacs-quote-wrap-all-in-region
|
|
|
- (interactive (list (mark) (point)))
|
|
|
- (unless (region-active-p)
|
|
|
- (user-error "no region to wrap"))
|
|
|
- (let ((deactivate-mark nil)
|
|
|
- (replacement (string-join
|
|
|
- (mapcar (lambda (item)
|
|
|
- (if (string-match-p "^\".*\"$" item)
|
|
|
- (string-trim item "\"" "\"")
|
|
|
- (format "\"%s\"" item)))
|
|
|
- (split-string (buffer-substring beg end)))
|
|
|
- " ")))
|
|
|
- (delete-region beg end)
|
|
|
- (insert replacement)))
|
|
|
-
|
|
|
-(defun my/meow-wrap-arbitrary (s e)
|
|
|
- "Wrap the current meow selection with arbitrary strings."
|
|
|
- (interactive "r")
|
|
|
- (let ((start-str (read-string "Start: "))
|
|
|
- (end-str (read-string "End: ")))
|
|
|
- (save-excursion
|
|
|
- (goto-char e)
|
|
|
- (insert end-str)
|
|
|
- (goto-char s)
|
|
|
- (insert start-str))))
|
|
|
+(defun dired-follow-symlink ()
|
|
|
+ "In dired, visit the file or directory at point by its true physical path."
|
|
|
+ (interactive)
|
|
|
+ (let ((filename (dired-get-file-for-visit)))
|
|
|
+ (if filename
|
|
|
+ (find-file (file-truename filename))
|
|
|
+ (message "No file at point"))))
|
|
|
|
|
|
(defun my/column-align-regexp ()
|
|
|
"Aligns the matched regexp to `comment-column`.
|
|
|
@@ -81,7 +49,7 @@ it ensures exactly one space of separation."
|
|
|
(target-col (if (and (boundp 'comment-column)
|
|
|
(numberp comment-column))
|
|
|
comment-column
|
|
|
- 40))
|
|
|
+ 80))
|
|
|
(start (region-beginning))
|
|
|
(end (region-end)))
|
|
|
|
|
|
@@ -116,26 +84,6 @@ it ensures exactly one space of separation."
|
|
|
;; Optional: Bind it to a key for easier access
|
|
|
;; (global-set-key (kbd "C-c a l") 'my/column-align-regexp)
|
|
|
|
|
|
-
|
|
|
-(defun diff-buffers (buffer-a buffer-b)
|
|
|
- "Generate a diff between BUFFER-A and BUFFER-B using standard diff.
|
|
|
-Prompts for the two buffers, defaulting to the current buffer and the
|
|
|
-most recently active one."
|
|
|
- (interactive
|
|
|
- (let* ((current (current-buffer))
|
|
|
- (other (other-buffer current t))
|
|
|
- (buf-a (read-buffer "New buffer (to diff): " current t))
|
|
|
- (buf-b (read-buffer "Old buffer (against): " other t)))
|
|
|
- (list (get-buffer buf-a) (get-buffer buf-b))))
|
|
|
-
|
|
|
- (let ((name-a (buffer-name buffer-a))
|
|
|
- (name-b (buffer-name buffer-b)))
|
|
|
- (diff buffer-b buffer-a nil t)
|
|
|
- ;; Rename the diff output buffer to make it clear what was diffed
|
|
|
- (when (get-buffer "*Diff*")
|
|
|
- (with-current-buffer "*Diff*"
|
|
|
- (rename-buffer (format "*Diff: %s vs %s*" name-b name-a) t)))))
|
|
|
-
|
|
|
(defun my/list-no-prefix-bindings (keymap &optional map-name)
|
|
|
"Extract and display all single-key (no-prefix) bindings from KEYMAP.
|
|
|
Outputs a clean list into a dedicated buffer."
|
|
|
@@ -169,6 +117,11 @@ Outputs a clean list into a dedicated buffer."
|
|
|
(setq buffer-read-only t))
|
|
|
(pop-to-buffer buf))))
|
|
|
|
|
|
+(defun my/insert-file-path (file)
|
|
|
+ "Read a file name from the minibuffer and insert its absolute path at point."
|
|
|
+ (interactive "fInsert path to file: ")
|
|
|
+ (insert (expand-file-name file)))
|
|
|
+
|
|
|
(provide 'utils)
|
|
|
|
|
|
|