summaryrefslogtreecommitdiff
path: root/lisp/autoinsert.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/autoinsert.el')
-rw-r--r--lisp/autoinsert.el66
1 files changed, 30 insertions, 36 deletions
diff --git a/lisp/autoinsert.el b/lisp/autoinsert.el
index 1e606dde208..a77ca091d29 100644
--- a/lisp/autoinsert.el
+++ b/lisp/autoinsert.el
@@ -1,4 +1,4 @@
-;;; autoinsert.el --- automatic mode-dependent insertion of text into new files
+;;; autoinsert.el --- automatic mode-dependent insertion of text into new files -*- lexical-binding: t -*-
;; Copyright (C) 1985-1987, 1994-1995, 1998, 2000-2019 Free Software
;; Foundation, Inc.
@@ -49,6 +49,8 @@
;;; Code:
+(require 'seq)
+
(defgroup auto-insert nil
"Automatic mode-dependent insertion of text into new files."
:prefix "auto-insert-"
@@ -72,22 +74,19 @@ With \\[auto-insert], this is always treated as if it were t."
:type '(choice (const :tag "Insert if possible" t)
(const :tag "Do nothing" nil)
(other :tag "insert if possible, mark as unmodified."
- not-modified))
- :group 'auto-insert)
+ not-modified)))
(defcustom auto-insert-query 'function
"Non-nil means ask user before auto-inserting.
When this is `function', only ask when called non-interactively."
:type '(choice (const :tag "Don't ask" nil)
(const :tag "Ask if called non-interactively" function)
- (other :tag "Ask" t))
- :group 'auto-insert)
+ (other :tag "Ask" t)))
(defcustom auto-insert-prompt "Perform %s auto-insertion? "
"Prompt to use when querying whether to auto-insert.
If this contains a %s, that will be replaced by the matching rule."
- :type 'string
- :group 'auto-insert)
+ :type 'string)
(defcustom auto-insert-alist
@@ -141,14 +140,14 @@ If this contains a %s, that will be replaced by the matching rule."
"
.\\\" You may distribute this file under the terms of the GNU Free
.\\\" Documentation License.
-.TH " (file-name-base)
+.TH " (file-name-base (buffer-file-name))
" " (file-name-extension (buffer-file-name))
" " (format-time-string "%Y-%m-%d ")
"\n.SH NAME\n"
- (file-name-base)
+ (file-name-base (buffer-file-name))
" \\- " str
"\n.SH SYNOPSIS
-.B " (file-name-base)
+.B " (file-name-base (buffer-file-name))
"\n"
_
"
@@ -211,7 +210,7 @@ If this contains a %s, that will be replaced by the matching rule."
\(provide '"
- (file-name-base)
+ (file-name-base (buffer-file-name))
")
\;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")
(("\\.texi\\(nfo\\)?\\'" . "Texinfo file skeleton")
@@ -219,7 +218,7 @@ If this contains a %s, that will be replaced by the matching rule."
"\\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename "
- (file-name-base) ".info\n"
+ (file-name-base (buffer-file-name)) ".info\n"
"@settitle " str "
@c %**end of header
@copying\n"
@@ -316,8 +315,7 @@ described above, e.g. [\"header.insert\" date-and-author-update]."
;; There's no custom equivalent of "repeat" for vectors.
:value-type (choice file function
(sexp :tag "Skeleton or vector")))
- :version "25.1"
- :group 'auto-insert)
+ :version "25.1")
;; Establish a default value for auto-insert-directory
@@ -325,8 +323,7 @@ described above, e.g. [\"header.insert\" date-and-author-update]."
"Directory from which auto-inserted files are taken.
The value must be an absolute directory name;
thus, on a GNU or Unix system, it must end in a slash."
- :type 'directory
- :group 'auto-insert)
+ :type 'directory)
;;;###autoload
@@ -338,23 +335,23 @@ Matches the visited file name against the elements of `auto-insert-alist'."
(or (eq this-command 'auto-insert)
(and auto-insert
(bobp) (eobp)))
- (let ((alist auto-insert-alist)
- case-fold-search cond desc action)
- (goto-char 1)
- ;; find first matching alist entry
- (while alist
- (if (atom (setq cond (car (car alist))))
- (setq desc cond)
- (setq desc (cdr cond)
- cond (car cond)))
- (if (if (symbolp cond)
- (derived-mode-p cond)
- (and buffer-file-name
- (string-match cond buffer-file-name)))
- (setq action (cdr (car alist))
- alist nil)
- (setq alist (cdr alist))))
-
+ (let* ((case-fold-search nil)
+ (desc nil)
+ ;; Find first matching alist entry.
+ (action
+ (seq-some
+ (pcase-lambda (`(,cond . ,action))
+ (if (atom cond)
+ (setq desc cond)
+ (setq desc (cdr cond)
+ cond (car cond)))
+ (when (if (symbolp cond)
+ (derived-mode-p cond)
+ (and buffer-file-name
+ (string-match cond buffer-file-name)))
+ action))
+ auto-insert-alist)))
+ (goto-char 1)
;; Now, if we found something, do it
(and action
(or (not (stringp action))
@@ -412,9 +409,6 @@ or if CONDITION had no actions, after all other CONDITIONs."
;;;###autoload
(define-minor-mode auto-insert-mode
"Toggle Auto-insert mode, a global minor mode.
-With a prefix argument ARG, enable Auto-insert mode if ARG is
-positive, and disable it otherwise. If called from Lisp, enable
-the mode if ARG is omitted or nil.
When Auto-insert mode is enabled, when new files are created you can
insert a template for the file depending on the mode of the buffer."