config-files.el (2889B)
1 ;;; config-files.el --- -*- lexical-binding: t; -*- 2 ;;; Commentary: 3 ;;; Files related configurations 4 ;;; Code: 5 6 ;; (use-package autoinsert 7 ;; :init 8 ;; (setq-default auto-insert-query nil 9 ;; auto-insert-alist nil) 10 ;; :config 11 ;; (auto-insert-mode 1)) 12 13 (require 'hardhat) 14 (global-hardhat-mode) 15 16 (use-package files 17 :commands (revert-buffer) 18 :bind (("<f5>" . revert-buffer)) 19 :config 20 (setq-default view-read-only t)) 21 22 (use-package envrc 23 :defer 2 24 :if (executable-find "direnv") 25 :bind (:map envrc-mode-map 26 ("C-c e" . envrc-command-map)) 27 :config (envrc-global-mode)) 28 29 (use-package highlight-indentation 30 :unless noninteractive 31 :commands (highlight-indentation-mode highlight-indentation-current-column-mode) 32 :config 33 (set-face-background 'highlight-indentation-face "#e3e3d3") 34 (set-face-background 'highlight-indentation-current-column-face "#c3b3b3")) 35 36 (defun vde/delete-this-file () 37 "Delete the current file, and kill the buffer." 38 (interactive) 39 (or (buffer-file-name) (error "No file is currently being edited")) 40 (when (yes-or-no-p (format "Really delete '%s'?" 41 (file-name-nondirectory buffer-file-name))) 42 (delete-file (buffer-file-name)) 43 (kill-this-buffer))) 44 45 (defun vde/rename-this-file-and-buffer (new-name) 46 "Renames both current buffer and file it's visiting to NEW-NAME." 47 (interactive "sNew name: ") 48 (let ((name (buffer-name)) 49 (filename (buffer-file-name))) 50 (unless filename 51 (error "Buffer '%s' is not visiting a file!" name)) 52 (if (get-buffer new-name) 53 (message "A buffer named '%s' already exists!" new-name) 54 (progn 55 (when (file-exists-p filename) 56 (rename-file filename new-name 1)) 57 (rename-buffer new-name) 58 (set-visited-file-name new-name))))) 59 60 (bind-key "C-c f D" #'vde/delete-this-file) 61 (bind-key "C-c f R" #'vde/rename-this-file-and-buffer) 62 63 ;; Additional bindings for built-ins 64 (bind-key "C-c f v d" #'add-dir-local-variable) 65 (bind-key "C-c f v l" #'add-file-local-variable) 66 (bind-key "C-c f v p" #'add-file-local-variable-prop-line) 67 68 (defun vde/reload-dir-locals-for-current-buffer () 69 "Reload dir locals for the current buffer." 70 (interactive) 71 (let ((enable-local-variables :all)) 72 (hack-dir-local-variables-non-file-buffer))) 73 74 (defun vde/reload-dir-locals-for-all-buffers-in-this-directory () 75 "Reload dir-locals for all buffers in current buffer's `default-directory'." 76 (interactive) 77 (let ((dir default-directory)) 78 (dolist (buffer (buffer-list)) 79 (with-current-buffer buffer 80 (when (equal default-directory dir)) 81 (vde/reload-dir-locals-for-current-buffer))))) 82 83 (bind-key "C-c f v r" #'vde/reload-dir-locals-for-current-buffer) 84 (bind-key "C-c f v r" #'vde/reload-dir-locals-for-all-buffers-in-this-directory) 85 86 (provide 'config-files) 87 ;;; config-files.el ends here