summary refs log tree commit diff stats
path: root/lisp/+compat.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/+compat.el')
-rw-r--r--lisp/+compat.el64
1 files changed, 0 insertions, 64 deletions
diff --git a/lisp/+compat.el b/lisp/+compat.el deleted file mode 100644 index 286d5da..0000000 --- a/lisp/+compat.el +++ /dev/null
@@ -1,64 +0,0 @@
1;;; +compat.el --- Thin backward-compatibility shim -*- lexical-binding: t; -*-
2
3;;; Commentary:
4
5;; I use different versionso of Emacs. Sometimes I have to copy-paste functions
6;; from newer Emacs to make my customizations work. This is that file.
7
8;; This is probably ill-advised.
9
10;;; Code:
11
12;;; Load stuff in +compat/ subdirectory
13(dolist (file (directory-files (locate-user-emacs-file "lisp/+compat") :full "\\.el\\'"))
14 (load file :noerror))
15
16;;; Only define things if not already defined
17(defmacro +compat-defun (name &rest args)
18 `(if (fboundp ',name)
19 (message "+compat: `%s' already bound." ',name)
20 (defun ,name ,@args)))
21
22(defmacro +compat-defmacro (name &rest args)
23 `(if (fboundp ',name)
24 (message "+compat: `%s' already bound." ',name)
25 (defmacro ,name ,@args)))
26
27;;; Single functions
28
29(+compat-defmacro dlet (binders &rest body)
30 "Like `let' but using dynamic scoping."
31 (declare (indent 1) (debug let))
32 ;; (defvar FOO) only affects the current scope, but in order for
33 ;; this not to affect code after the main `let' we need to create a new scope,
34 ;; which is what the surrounding `let' is for.
35 ;; FIXME: (let () ...) currently doesn't actually create a new scope,
36 ;; which is why we use (let (_) ...).
37 `(let (_)
38 ,@(mapcar (lambda (binder)
39 `(defvar ,(if (consp binder) (car binder) binder)))
40 binders)
41 (let ,binders ,@body)))
42
43;; https://git.savannah.gnu.org/cgit/emacs.git/diff/?id=772b189143453745a8e014e21d4b6b78f855bba3
44(+compat-defun rename-visited-file (new-location)
45 "Rename the file visited by the current buffer to NEW-LOCATION.
46This command also sets the visited file name. If the buffer
47isn't visiting any file, that's all it does.
48
49Interactively, this prompts for NEW-LOCATION."
50 (interactive
51 (list (if buffer-file-name
52 (read-file-name "Rename visited file to: ")
53 (read-file-name "Set visited file name: "
54 default-directory
55 (expand-file-name
56 (file-name-nondirectory (buffer-name))
57 default-directory)))))
58 (when (and buffer-file-name
59 (file-exists-p buffer-file-name))
60 (rename-file buffer-file-name new-location))
61 (set-visited-file-name new-location nil t))
62
63(provide '+compat)
64;;; +compat.el ends here