X-Git-Url: https://git.korewanetadesu.com/?p=apt-sources-list.git;a=blobdiff_plain;f=apt-sources-list.el;h=ed4c876fb1651c81fff1297af13c64fb7441081d;hp=f17f5a4c311c0839c4ea05bbc1bd14defde89624;hb=44112833b3fa7f4d7e43708e5996782e22bb2fa3;hpb=de03d5bc13ed0e5b057618b6931e059fdcaf83cc diff --git a/apt-sources-list.el b/apt-sources-list.el index f17f5a4..ed4c876 100644 --- a/apt-sources-list.el +++ b/apt-sources-list.el @@ -44,6 +44,7 @@ ;;; Code: +(require 'cl-lib) (require 'subr-x) (eval-when-compile (require 'rx)) @@ -111,7 +112,7 @@ single “%s” which will be replaced with the source name." (one-or-more (not (any " \t\n#")))) (one-or-more blank) (group - (or (and (one-or-more (not (any " \t\n#"))) "/") + (or (and (zero-or-more (not (any " \t\n#"))) "/") (and (zero-or-more (not (any " \t\n#"))) (not (any " \t\n/#")) (one-or-more blank) @@ -133,19 +134,22 @@ single “%s” which will be replaced with the source name." (5 'apt-sources-list-components t t))) "Faces for parts of sources.list lines.") -(defun apt-sources-list-insert (uri &rest properties) - "Insert a new package source at URI, with extra PROPERTIES. +(cl-defun apt-sources-list-insert + (uri &key name (type "deb") options + (suite (car apt-sources-list-suites)) + (components (car apt-sources-list-components))) + "Insert a new package source at URI. When called interactively without a prefix argument, assume the type is “deb” and no special options. -When called from Lisp, optional properties include: +When called from Lisp, optional arguments include: -‘:name’ - a source name to include in a leading comment -‘:type’ - “deb” or “deb-src”, defaulting to “deb” -‘:options’ - an options string, without […] delimiters -‘:suite’ - defaults to the first of ‘apt-sources-list-suites’ -‘:components’ - defaults to the first of ‘apt-sources-list-components’ +NAME - a source name to include in a leading comment +TYPE - “deb” or “deb-src”, defaulting to “deb” +OPTIONS - an options string, without […] delimiters +SUITE - defaults to the first item of ‘apt-sources-list-suites’ +COMPONENTS - defaults to the first item of ‘apt-sources-list-components’ You should read the official APT documentation for further explanation of the format." @@ -169,22 +173,11 @@ explanation of the format." :options (unless (string-blank-p options) options) :suite suite :components components))) - (insert (let ((name (plist-get properties :name))) - (if name - (concat (format apt-sources-list-name-format name) "\n") - "")) - (or (plist-get properties :type) "deb") - (let ((options (plist-get properties :options))) - (if options (format " [%s] " options) " ")) - uri - " " - (or (plist-get properties :suite) - (car apt-sources-list-suites)) - (if (string-suffix-p "/" (or (plist-get properties :suite) - (car apt-sources-list-suites))) - "" - (format " %s" (or (plist-get properties :components) - (car apt-sources-list-components)))))) + (when name + (insert (format apt-sources-list-name-format name) "\n")) + (insert type (if options (format " [%s] " options) " ") uri " " + suite (if (string-suffix-p "/" suite) "" + (format " %s" components)))) (defun apt-sources-list-forward-source (&optional n) "Go N source lines forward (backward if N is negative)." @@ -369,6 +362,7 @@ is not a correctly-formatted APT source." (setq-local comment-start-skip "#+ *") (font-lock-add-keywords nil apt-sources-list-font-lock-keywords)) +;;;###autoload (add-to-list 'auto-mode-alist (cons (rx (or (and (any "./") "sources.list")