emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/sweeprolog fdad71bea4: ADDED: auto-insert integration for


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog fdad71bea4: ADDED: auto-insert integration for filling in Prolog module headers
Date: Sat, 1 Oct 2022 07:59:09 -0400 (EDT)

branch: elpa/sweeprolog
commit fdad71bea443d9ba5f89ce63c46855c6767fd54f
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    ADDED: auto-insert integration for filling in Prolog module headers
    
    * sweeprolog-module-header-comment-skeleton: new user option
---
 NEWS.org      | 15 ++++++++++++++-
 README.org    | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 sweeprolog.el | 41 ++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 107 insertions(+), 3 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index 8daebe8300..ca378a40ce 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -5,7 +5,20 @@
 #+options:               ':t toc:nil num:nil ^:{}
 #+startup:               content indent
 
-This file describes changes in =sweep= up to version =0.4.4=.
+This file contains the release notes for =sweep=, an embedding of
+SWI-Prolog in Emacs.
+
+For further details, please consult the manual:
+<https://eshelyaron.com/sweep.html>.
+
+* Version 0.4.6 on 2022-10-01
+
+** Added integration with =auto-insert=
+
+=sweeprolog.el= now extends =auto-insert-alist= with a Prolog module
+template associated with =sweeprolog-mode=.  The module template is
+inserted into empty =sweeprolog-buffers= when =auto-insert-mode= is
+enabled.
 
 * New commands in =sweep= version =0.4.0=
 ** New command =sweeprolog-load-buffer=.
diff --git a/README.org b/README.org
index 5bea55ab1d..554adb51e9 100644
--- a/README.org
+++ b/README.org
@@ -528,7 +528,6 @@ For more information about quasi-quotations in SWI-Prolog, 
see
 
[[https://www.swi-prolog.org/pldoc/man?section=quasiquotations][library(quasi_quotations)
 in the SWI-Prolog manual]].
 
 
-
 ** Term-based editing and motion commands
 :PROPERTIES:
 :CUSTOM_ID: term-based-commands
@@ -631,6 +630,59 @@ otherwise.  To choose a different buffer to load while 
visiting a
 More relevant information about loading code in SWI-Prolog can be
 found in [[https://www.swi-prolog.org/pldoc/man?section=consulting][Loading 
Prolog source files]] in the SWI-Prolog manual.
 
+** Using templates for creating new modules
+:PROPERTIES:
+:CUSTOM_ID: auto-insert
+:END:
+
+#+CINDEX: auto-insert
+=sweep= integrates with the Emacs =auto-insert= facility to simplify
+creation of new SWI-Prolog modules.  =auto-insert= allows for populating
+newly created files with templates defined by the relevant major mode.
+
+=sweep= associates a Prolog module skeleton with =sweeprolog-mode=, the
+skeleton begins with a "file header" multi-line comment which includes
+the name and email address of the user based on the values of
+=user-full-name= and =user-mail-address= respectively.  A =module/2=
+directive is placed after the file header, with the module name set to
+the base name of the file.  Lastly the skeleton inserts a =PlDoc= module
+comment to be filled with the module's documentation (see 
[[https://www.swi-prolog.org/pldoc/man?section=sectioncomments][File
+comments in the SWI-Prolog manual]]).
+
+As an example, after inserting the module skeleton, a new Prolog file
+=foo.pl= will have the following contents:
+
+#+begin_src prolog
+  /*
+      Author:        John Doe
+      Email:         john.doe@example.com
+
+  ,*/
+
+  :- module(foo, []).
+
+  /** <module> foo
+
+  ,*/
+
+#+end_src
+
+#+VINDEX: sweeprolog-module-header-comment-skeleton
+The multi-line comment included above the =module/2= directive can be
+extended by customizing the user option
+=sweeprolog-module-header-comment-skeleton=, which see.  This can be
+useful for including e.g. copyright text in the file header.
+
+To open a new Prolog file, use the standard =C-x C-f= (=find-file=) and
+select a location for the new file.  In the new =sweeprolog-mode=
+buffer, type =M-x auto-insert= to insert the Prolog module skeleton.
+
+To automatically insert the module skeleton when opening new files in
+=sweeprolog-mode=, enable the minor mode =auto-insert-mode=.  For detailed
+information about =auto-insert= and its customization options, see
+[[info:autotype#Autoinserting][Autoinserting in the Autotyping manual]].
+
+
 * The Prolog top-level
 :PROPERTIES:
 :CUSTOM_ID: prolog-top-level
diff --git a/sweeprolog.el b/sweeprolog.el
index 51ffa58841..5c58aea506 100644
--- a/sweeprolog.el
+++ b/sweeprolog.el
@@ -6,7 +6,7 @@
 ;; Maintainer: Eshel Yaron <~eshel/dev@lists.sr.ht>
 ;; Keywords: prolog languages extensions
 ;; URL: https://git.sr.ht/~eshel/sweep
-;; Package-Version: 0.4.5
+;; Package-Version: 0.4.6
 ;; Package-Requires: ((emacs "28"))
 
 ;; This file is NOT part of GNU Emacs.
@@ -29,11 +29,29 @@
 
 (require 'comint)
 (require 'xref)
+(require 'autoinsert)
 
 (defgroup sweeprolog nil
   "SWI-Prolog Embedded in Emacs."
   :group 'prolog)
 
+(defcustom sweeprolog-module-header-comment-skeleton ?\n
+  "Additional content for the topmost comment in module headers.
+
+The SWI-Prolog module header inserted by \\[auto-insert] includes
+a multiline comment at the very start of the buffer which
+contains the name and mail address of the author based on the
+user options `user-full-name' and `user-mail-address'
+respectively, followed by the value of this variable, is
+interpreted as a skeleton (see `skeleton-insert').  In its
+simplest form, this may be a string or a character.
+
+This user option may be useful, for example, to include copyright
+notices with the module header."
+  :package-version '((sweeprolog . "0.4.6"))
+  :type 'any
+  :group 'sweeprolog)
+
 (defcustom sweeprolog-indent-offset 4
   "Number of columns to indent lines with in `sweeprolog-mode' buffers."
   :package-version '((sweeprolog . "0.3.1"))
@@ -1650,6 +1668,9 @@ Interactively, a prefix arg means to prompt for BUFFER."
     [ "Find Prolog module"     sweeprolog-find-module     t ]
     [ "Find Prolog predicate"  sweeprolog-find-predicate  t ]
     [ "Open top-level"         sweeprolog-top-level       t ]
+    [ "Insert module template"
+      auto-insert
+      (eq major-mode 'sweeprolog-mode) ]
     "--"
     [ "Reset sweep"            sweeprolog-restart         t ]
     [ "View sweep messages"    sweeprolog-view-messages   t ]))
@@ -2310,6 +2331,24 @@ variable at point, if any."
   (when sweeprolog-enable-cursor-sensor
     (cursor-sensor-mode 1)))
 
+(add-to-list 'auto-insert-alist
+             '((sweeprolog-mode . "SWI-Prolog module header")
+               (or (and (buffer-file-name)
+                        (file-name-sans-extension (file-name-base 
(buffer-file-name))))
+                   (read-string "Module name: "))
+               "/*"
+               "\n    Author:        "
+               (progn user-full-name)
+               "\n    Email:         "
+               (progn user-mail-address)
+               (progn sweeprolog-module-header-comment-skeleton)
+               "\n*/"
+               "\n\n:- module("
+               str
+               ", [])."
+               "\n\n/** <module> "
+               str
+               "\n\n*/\n\n"))
 
 (provide 'sweeprolog)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]