blob: 7f54d9993b760fb9f66bb9196765ed0022972c55 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
;;; edit-config.el --- Conveniently edit config files -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Tristan Riehs
;; Author: Tristan Riehs <tristan.riehs@bordeaux-inp.fr>
;; Keywords: convenience
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This package aims at providing a convenient way of editing the various
;; configuration files you have on your system. The main thins you should
;; be interested in are `edit-config-files' and `edit-config'.
;;; Code:
(defgroup edit-config nil
"Conveniently edit config files."
:group 'emacs
:prefix "edit-config")
(defcustom edit-config-missing nil
"Whether to propose files that do not exist.
If set to nil, configuration files that are present in
`edit-config-files' and do not exist on the current machine will no be
proposed by the interactive prompt of `edit-config'. This allows you to
put all the configuration files you have on all your machines, without
polluting the prompt when using a machine that does not have all of
them. If set to non-nil, they will all be proposed anyway."
:group 'edit-config
:type 'boolean)
(defcustom edit-config-files nil
"The list of config files.
Each element of this list has the form (LABEL . FILENAME). LABEL is what
is displayed in the prompt of `edit-config', and FILENAME is the actual
configuration file."
:group 'edit-config
:type '(alist :key-type string :value-type string))
(defun edit-config--completing-read-predicate (config)
"Predicate to use in `edit-config'.
Used when prompting only when `edit-config-missing' is non-nil. See
`edit-config-files' for the structure of CONFIG."
(file-exists-p (cdr config)))
(defvar edit-config--hist nil
"History for `edit-config'.")
;;;###autoload
(defun edit-config (label)
"Edit the config file associated to LABEL."
(interactive
(list (if edit-config-files
(completing-read "Config: "
edit-config-files
(if edit-config-missing
'edit-config--completing-read-predicate
nil)
t
nil
'edit-config--hist)
nil)))
(if label
(find-file (alist-get label edit-config-files nil nil 'string-equal))
(message "No config file to propose, have you you customized \
`edit-config-files' ?")))
(provide 'edit-config)
;;; edit-config.el ends here
|