;;; edit-config.el --- Conveniently edit config files -*- lexical-binding: t; -*- ;; Copyright (C) 2024 Tristan Riehs ;; Author: Tristan Riehs ;; Maintainer: Tristan Riehs ;; 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 . ;;; Commentary: ;; This package aims at providing a convenient way of editing the ;; various configuration files you have on your system. ;; You should first customize `edit-config-files', and then use M-x ;; `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 (when edit-config-files (completing-read "Config: " edit-config-files (if edit-config-missing 'edit-config--completing-read-predicate nil) t nil 'edit-config--hist)))) (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