X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/be520aca79dd429d55012a1916bdc97f06773fc5..1f85b7ca034ee4f96d796d95ec86bc4fa0ba8aa3:/lisp/autoinsert.el diff --git a/lisp/autoinsert.el b/lisp/autoinsert.el index 5793c3180b..43fa31288e 100644 --- a/lisp/autoinsert.el +++ b/lisp/autoinsert.el @@ -1,12 +1,12 @@ ;;; autoinsert.el --- automatic mode-dependent insertion of text into new files -;; Copyright (C) 1985-1987, 1994-1995, 1998, 2000-2011 -;; Free Software Foundation, Inc. +;; Copyright (C) 1985-1987, 1994-1995, 1998, 2000-2016 Free Software +;; Foundation, Inc. ;; Author: Charlie Martin ;; Adapted-By: Daniel Pfeiffer ;; Keywords: convenience -;; Maintainer: FSF +;; Maintainer: emacs-devel@gnu.org ;; This file is part of GNU Emacs. @@ -36,7 +36,7 @@ ;; setq auto-insert-directory to an appropriate slash-terminated value ;; ;; You can also customize the variable `auto-insert-mode' to load the -;; package. Alternatively, add the following to your .emacs file: +;; package. Alternatively, add the following to your init file: ;; (auto-insert-mode 1) ;; ;; Author: Charlie Martin @@ -67,7 +67,7 @@ Insertion is possible when something appropriate is found in `auto-insert-alist'. When the insertion is marked as unmodified, you can save it with \\[write-file] RET. This variable is used when the function `auto-insert' is called, e.g. -when you do (add-hook 'find-file-hook 'auto-insert). +when you do (add-hook \\='find-file-hook \\='auto-insert). 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) @@ -91,23 +91,24 @@ If this contains a %s, that will be replaced by the matching rule." (defcustom auto-insert-alist - '((("\\.\\([Hh]\\|hh\\|hpp\\)\\'" . "C / C++ header") - (upcase (concat (file-name-nondirectory - (file-name-sans-extension buffer-file-name)) - "_" - (file-name-extension buffer-file-name))) + '((("\\.\\([Hh]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'" . "C / C++ header") + (replace-regexp-in-string + "[^A-Z0-9]" "_" + (replace-regexp-in-string + "\\+" "P" + (upcase (file-name-nondirectory buffer-file-name)))) "#ifndef " str \n "#define " str "\n\n" _ "\n\n#endif") - (("\\.\\([Cc]\\|cc\\|cpp\\)\\'" . "C / C++ program") + (("\\.\\([Cc]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'" . "C / C++ program") nil "#include \"" - (let ((stem (file-name-sans-extension buffer-file-name))) - (cond ((file-exists-p (concat stem ".h")) - (file-name-nondirectory (concat stem ".h"))) - ((file-exists-p (concat stem ".hh")) - (file-name-nondirectory (concat stem ".hh"))))) + (let ((stem (file-name-sans-extension buffer-file-name)) + ret) + (dolist (ext '("H" "h" "hh" "hpp" "hxx" "h++") ret) + (when (file-exists-p (concat stem "." ext)) + (setq ret (file-name-nondirectory (concat stem "." ext)))))) & ?\" | -10) (("[Mm]akefile\\'" . "Makefile") . "makefile.inc") @@ -135,19 +136,19 @@ If this contains a %s, that will be replaced by the matching rule." (("\\.[1-9]\\'" . "Man page skeleton") "Short description: " - ".\\\" Copyright (C), " (substring (current-time-string) -4) " " + ".\\\" Copyright (C), " (format-time-string "%Y") " " (getenv "ORGANIZATION") | (progn user-full-name) " .\\\" You may distribute this file under the terms of the GNU Free .\\\" Documentation License. -.TH " (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) +.TH " (file-name-base) " " (file-name-extension (buffer-file-name)) " " (format-time-string "%Y-%m-%d ") "\n.SH NAME\n" - (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) + (file-name-base) " \\- " str "\n.SH SYNOPSIS -.B " (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) +.B " (file-name-base) "\n" _ " @@ -164,9 +165,12 @@ If this contains a %s, that will be replaced by the matching rule." (("\\.el\\'" . "Emacs Lisp header") "Short description: " - ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str " + ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str + (make-string (max 2 (- 80 (current-column) 27)) ?\s) + "-*- lexical-binding: t; -*-" '(setq lexical-binding t) + " -;; Copyright (C) " (substring (current-time-string) -4) " " +;; Copyright (C) " (format-time-string "%Y") " " (getenv "ORGANIZATION") | (progn user-full-name) " ;; Author: " (user-full-name) @@ -207,7 +211,7 @@ If this contains a %s, that will be replaced by the matching rule." \(provide '" - (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) + (file-name-base) ") \;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n") (("\\.texi\\(nfo\\)?\\'" . "Texinfo file skeleton") @@ -215,14 +219,13 @@ If this contains a %s, that will be replaced by the matching rule." "\\input texinfo @c -*-texinfo-*- @c %**start of header @setfilename " - (file-name-sans-extension - (file-name-nondirectory (buffer-file-name))) ".info\n" + (file-name-base) ".info\n" "@settitle " str " @c %**end of header @copying\n" (setq short-description (read-string "Short description: ")) ".\n\n" - "Copyright @copyright{} " (substring (current-time-string) -4) " " + "Copyright @copyright{} " (format-time-string "%Y") " " (getenv "ORGANIZATION") | (progn user-full-name) " @quotation @@ -302,7 +305,18 @@ ACTION may be a skeleton to insert (see `skeleton-insert'), an absolute file-name or one relative to `auto-insert-directory' or a function to call. ACTION may also be a vector containing several successive single actions as described above, e.g. [\"header.insert\" date-and-author-update]." - :type 'sexp + :type '(alist :key-type + (choice (regexp :tag "Regexp matching file name") + (symbol :tag "Major mode") + (cons :tag "Condition and description" + (choice :tag "Condition" + (regexp :tag "Regexp matching file name") + (symbol :tag "Major mode")) + (string :tag "Description"))) + ;; 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) @@ -397,9 +411,10 @@ or if CONDITION had no actions, after all other CONDITIONs." ;;;###autoload (define-minor-mode auto-insert-mode - "Toggle Auto-insert mode. -With prefix ARG, turn Auto-insert mode on if and only if ARG is positive. -Returns the new status of Auto-insert mode (non-nil means on). + "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."