all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: arthur miller <arthur.miller@live.com>
To: emacs-devel <emacs-devel@gnu.org>
Subject: Sv: Sv: Sv: Sv: Christmas wish: Literate Elisp
Date: Sun, 22 Dec 2019 07:01:03 +0000	[thread overview]
Message-ID: <VI1P194MB0429B0265C9E8D00C0595D30962F0@VI1P194MB0429.EURP194.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <VI1P194MB0429F37A29A2720037CAD9F9962C0@VI1P194MB0429.EURP194.PROD.OUTLOOK.COM>


[-- Attachment #1.1: Type: text/plain, Size: 3101 bytes --]

My 2nd patch was wrong as I noticed too late yesterady, sorry for that.
Unfortunately I didn't have time to fix it. Here is one that works (at least
in my emacs), if any one would like to test the idea and play with idea of
using literal elisp. It is not only about being able to omit ';' in comments.

The idea is that normally in elisp, compiler skips comment-lines and
evaluate everything else. Here compiler evaluates code-lines and skips
everythign else. While it might seems like a same thing, it is not! There is
a certain inversion and slight difference because of that apparently subtle
difference. For instance, sine but code is ignored, this lets one use
org-mode as a kind of annotation tool or organisational tool for the
code. Normally the parser would choke and produced  error
messages if it was feeded with org headings and so n.

Another possibility is to maybe be able use elisp as a template or
annotation language or code generator for some other languages. For
example one could write a C code and use elisp macros or code
generators which expand to C after eval-buffer, kind -of what org-mode
does, but it would maybe make it easier or open some more possibilites
if one combines org-mode with directly evaluable elisp. Don't know, haven't
had time yet.

Anyway, I hope you can give it a try and discuss the idea not the
implementeation, implementation is just a sketch to give you something
to play with. It is unnecessary to theorycraft essays about all kind of
space problems before one tries it, in my opinion.

Cheers
________________________________
Från: arthur miller <arthur.miller@live.com>
Skickat: den 21 december 2019 17:03
Till: Stefan Monnier <monnier@iro.umontreal.ca>
Ämne: Sv: Sv: Sv: Sv: Christmas wish: Literate Elisp


> I personally would oppose these few-lines of new code in lread.c at
> least until this new feature is properly supported in the rest of the
> Elisp-manipulating tools we have (starting with the byte-compiler, but
> including checkdoc, autoload, ...) and until there's some clear evidence
> that it's useful (i.e. used by more than one person).

Completely agree on that one.

Unfortunately the time and effort and my struggle to just patch
bytecompiler.el to do this tells me I am not the right person to jump on
implementing "the skip" approach you suggest. Maybe some code, or
at least approach used in bytecompiler and eval can be even reused for
this, but to me personally it would take too much time and effort.

The other approach of copying file to temp buffer and modifying the file
is certainly less jobb and easier to implement. I also agree that it is suitable
for small toys and demo examples. It couldn't be difficult to implement, one
would need to keep track of balanced paranthesis + some few other small
things which isn't very difficult. While I can certainly hack elisp to a degree,
I am still not the right person to implement something you would distribute in
Emacs anyway, so if somebod else is interesting to implement this approach
it would be great.



[-- Attachment #1.2: Type: text/html, Size: 8056 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: lread.patch --]
[-- Type: text/x-patch; name="lread.patch", Size: 1067 bytes --]

--- lread.c	2019-12-20 01:07:33.264089317 +0100
+++ mylread.c	2019-12-22 07:35:31.479305940 +0100
@@ -1955,6 +1955,8 @@
   /* True on the first time around.  */
   bool first_sexp = 1;
   Lisp_Object macroexpand = intern ("internal-macroexpand-for-load");
+  Lisp_Object litcode = intern ("emacs-lisp-allow-literal-comments");
+  Lisp_Object allow_literal_comments = find_symbol_value(litcode);
 
   if (NILP (Ffboundp (macroexpand))
       || (STRINGP (sourcename) && suffix_p (sourcename, ".elc")))
@@ -2053,6 +2055,20 @@
 	  || c == NO_BREAK_SPACE)
 	goto read_next;
 
+      if (EQ (allow_literal_comments, Qt))
+        {
+          if (c != '(')
+            {
+              if(c == '#' || c == '\'' || c == '\`') c = READCHAR;
+              if(c == '(') UNREAD(c);
+              else
+                {
+                  while ((c = READCHAR) != '\n' && c != -1);
+                  goto read_next;
+                }
+            }
+        }
+
       if (! HASH_TABLE_P (read_objects_map)
 	  || XHASH_TABLE (read_objects_map)->count)
 	read_objects_map

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: bytecomp.patch --]
[-- Type: text/x-patch; name="bytecomp.patch", Size: 3106 bytes --]

--- bytecomp.el	2019-12-20 01:05:44.575414147 +0100
+++ mybytecomp.el	2019-12-22 07:35:59.509753178 +0100
@@ -154,6 +154,14 @@
   :type '(choice (const nil) function)
   :version "23.2")
 
+(defcustom byte-compile-allow-literal-comments nil
+  "If not nil, byte compiler will allow you to type
+   top-level comments without using semicolon in emacs lisp."
+  :group 'bytecomp
+  :type 'boolean
+  :safe #'booleanp
+  :version "27.1")
+
 ;; This enables file name handlers such as jka-compr
 ;; to remove parts of the file name that should not be copied
 ;; through to the output file name.
@@ -2079,8 +2087,8 @@
 	(print-level nil)
 	;; Prevent edebug from interfering when we compile
 	;; and put the output into a file.
-;; 	(edebug-all-defs nil)
-;; 	(edebug-all-forms nil)
+        ;; 	(edebug-all-defs nil)
+        ;; 	(edebug-all-forms nil)
 	;; Simulate entry to byte-compile-top-level
         (byte-compile-jump-tables nil)
         (byte-compile-constants nil)
@@ -2127,19 +2135,35 @@
 			       (= (following-char) ?\;))
 		   (forward-line 1))
 		 (not (eobp)))
-	  (setq byte-compile-read-position (point)
+
+          (setq byte-compile-read-position (point)
 		byte-compile-last-position byte-compile-read-position)
-          (let* ((lread--unescaped-character-literals nil)
-                 (form (read inbuffer))
-                 (warning (byte-run--unescaped-character-literals-warning)))
-            (when warning (byte-compile-warn "%s" warning))
-	    (byte-compile-toplevel-file-form form)))
-	;; Compile pending forms at end of file.
-	(byte-compile-flush-pending)
-	;; Make warnings about unresolved functions
-	;; give the end of the file as their position.
-	(setq byte-compile-last-position (point-max))
-	(byte-compile-warn-about-unresolved-functions))
+
+	  (if byte-compile-allow-literal-comments
+              (progn
+                (if (= (following-char) ?\()
+                    (progn
+
+                      (let* ((lread--unescaped-character-literals nil)
+                             (form (read inbuffer))
+                             (warning (byte-run--unescaped-character-literals-warning)))
+                        (when warning (byte-compile-warn "%s" warning))
+	                (byte-compile-toplevel-file-form form)))
+                  (forward-line 1)))
+            (progn
+
+              (let* ((lread--unescaped-character-literals nil)
+                     (form (read inbuffer))
+                     (warning (byte-run--unescaped-character-literals-warning)))
+                (when warning (byte-compile-warn "%s" warning))
+	        (byte-compile-toplevel-file-form form)))))
+
+        ;; Compile pending forms at end of file.
+        (byte-compile-flush-pending)
+        ;; Make warnings about unresolved functions
+        ;; give the end of the file as their position.
+        (setq byte-compile-last-position (point-max))
+        (byte-compile-warn-about-unresolved-functions))
       ;; Fix up the header at the front of the output
       ;; if the buffer contains multibyte characters.
       (and byte-compile-current-file

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: simple.patch --]
[-- Type: text/x-patch; name="simple.patch", Size: 479 bytes --]

--- simple.el	2019-12-20 01:06:16.849343961 +0100
+++ mysimple.el	2019-12-20 01:03:05.212467674 +0100
@@ -127,6 +127,14 @@
   :safe #'booleanp
   :version "27.1")
 
+(defcustom emacs-lisp-allow-literal-comments nil
+  "If not nil, elisp will allow you to type in top-level comments
+   without using semicolon."
+  :group 'lisp
+  :type 'boolean
+  :safe #'booleanp
+  :version "27.1")
+
 (defvar next-error-highlight-timer nil)
 
 (defvar next-error-overlay-arrow-position nil)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: chatty.el --]
[-- Type: text/x-emacs-lisp; name="chatty.el", Size: 720 bytes --]

;; -*- mode: org; -*-

Elisp now alows comments without ;.

' can also use start literal comments with
# also works

* Some elisp here
(setq emacs-lisp-allow-literal-comments t)
(setq byte-compile-allow-literal-comments t)
(message "I can now run simple elisp on my own!")

* More stuff here
#+BEGIN_SRC emacs-lisp
(message "Hello, World!")
#+END_SRC

It is of course possible to intertwene code
with comments anywhere in the file.

(message "Hello Again!")

Of course we can also comment-out code
just as before:

;;(message "I am silent")
In code blocs the ';' is still a comment delimiter:
(message
 ;; Here is a line comment
 "I am a bit chatty today!")

That's it for today folks!

(message "Bye bye cruel world!")

  parent reply	other threads:[~2019-12-22  7:01 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-12 15:45 Christmas wish: Literate Elisp arthur miller
2019-12-12 17:29 ` Stefan Monnier
2019-12-14  4:40   ` Sv: " arthur miller
2019-12-14 14:08     ` Stefan Monnier
2019-12-15  8:37       ` arthur miller
2019-12-16 12:01       ` Sv: " arthur miller
2019-12-16 13:41         ` Stefan Monnier
2019-12-16 14:02           ` Sv: " arthur miller
2019-12-16 16:07             ` Jonathan Leech-Pepin
2019-12-17  2:09               ` arthur miller
2019-12-17 11:06                 ` Adam Porter
2019-12-18 16:29                   ` Sv: " arthur miller
2019-12-18 18:49                     ` Adam Porter
2019-12-18 20:04                       ` Sv: " arthur miller
2019-12-18 23:18                         ` Adam Porter
2019-12-18 23:53                           ` Sv: " arthur miller
2019-12-20 15:58                             ` Unknown
2019-12-18 21:18                       ` Sv: Sv: Sv: " Stefan Monnier
2019-12-18 22:43                         ` Christmas wish: Literate Elisp (Intro) VanL
2019-12-19  0:05                           ` Sv: " arthur miller
2019-12-18 22:59                         ` Sv: Sv: Sv: Christmas wish: Literate Elisp Adam Porter
2019-12-18 23:18                           ` Sv: " arthur miller
2019-12-18 23:52                             ` Adam Porter
2019-12-19  0:02                               ` Sv: " arthur miller
2019-12-19  0:42                                 ` chad
2019-12-19  1:50                                   ` Jean-Christophe Helary
2019-12-20  0:55                                     ` Sv: " arthur miller
2019-12-20 15:00                                       ` Stefan Monnier
2019-12-20 15:50                                         ` Stefan Monnier
2019-12-20 15:50                                         ` Sv: " arthur miller
2019-12-20 16:17                                           ` Stefan Monnier
2019-12-20 16:34                                             ` Eduardo Ochs
2019-12-21  1:18                                               ` Sv: " arthur miller
2019-12-21  5:24                                                 ` Eduardo Ochs
2019-12-21  5:52                                                   ` Sv: " arthur miller
     [not found]                                                   ` <VI1P194MB042965777086C4466B7FF5EC962C0@VI1P194MB0429.EURP194.PROD.OUTLOOK.COM>
2019-12-21 15:29                                                     ` arthur miller
     [not found]                                             ` <VI1P194MB0429A123183C15AF8EC3956B962C0@VI1P194MB0429.EURP194.PROD.OUTLOOK.COM>
     [not found]                                               ` <jwv7e2pln3s.fsf-monnier+emacs@gnu.org>
     [not found]                                                 ` <VI1P194MB0429F37A29A2720037CAD9F9962C0@VI1P194MB0429.EURP194.PROD.OUTLOOK.COM>
2019-12-22  7:01                                                   ` arthur miller [this message]
2019-12-20 16:51   ` Phillip Lord
2019-12-21  1:16     ` Tim Cross
2019-12-21  4:24       ` Sv: " arthur miller
2019-12-21  6:41         ` Tim Cross
2019-12-21  9:39           ` VanL
2019-12-21 14:17             ` Sv: " arthur miller
2019-12-14  4:16 ` Richard Stallman
2019-12-14  5:05   ` Sv: " arthur miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=VI1P194MB0429B0265C9E8D00C0595D30962F0@VI1P194MB0429.EURP194.PROD.OUTLOOK.COM \
    --to=arthur.miller@live.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.