From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sean Whitton via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: New for GNU ELPA: literate-scratch Date: Sun, 09 Jun 2024 13:53:08 +0800 Message-ID: <87ed96wtkr.fsf@melete.silentflame.com> Reply-To: Sean Whitton Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7276"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jun 09 07:54:08 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sGBVH-0001gm-PM for ged-emacs-devel@m.gmane-mx.org; Sun, 09 Jun 2024 07:54:08 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sGBUb-0003SV-1I; Sun, 09 Jun 2024 01:53:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sGBUZ-0003S6-6e for emacs-devel@gnu.org; Sun, 09 Jun 2024 01:53:23 -0400 Original-Received: from sendmail.purelymail.com ([34.202.193.197]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sGBUX-0000hy-GM for emacs-devel@gnu.org; Sun, 09 Jun 2024 01:53:22 -0400 DKIM-Signature: a=rsa-sha256; b=R7+vdGJPRitgnK82GqZHnf9oyimHF0lbyYmxPvDUTm0c0ggMLcXwbIjkQkzq/K00Of53+lK0ZgXppriQ8E5tdL4vi8Wcc8c1S4klHVSqEsMcbbcnHsOUzF4JfXU8tyrtefqRu6SAbq6SkexPpy7mBFrn3ho2wz9hp5LSFgenhOLTflEOeENcocC4vQcYUd+fjkeIWAQCcg2NaZhiktErnm+4ibWQvjXy8fca6Pjvhl90VJBjyzlmgfo2VJFp0r/oL6MhnMzdV+WfWG+Vc/kZlKxPguflnu58Ki2SfbM98opdTbHWJH96ULwQdGie7JOslb1iFWc3pJMTjC1Gn8Z2JA==; s=purelymail3; d=spwhitton.name; v=1; bh=CW1C2XgE1GwasLwClZxpsSpCgPjarIi+QvWOeeRvPus=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=gcuF/p5hT40b5YMRBsGyWffAlaznB01c6b94ptg/kr3Kq0/exgEUKGr8njXwL9DjTtImXy9IIJKmElQ4MOxsusTXOKUHgSljM38CadqsiAapoag+VeiwJc/+MVaIDx8KGUNrywCwIX0PvdD1F02bCTHgCn/AF4fO8+X7+eAaZ0McWeZGzNMVu+rED6wA8fBJbGuy2sSr3GJAXdqz07xaNuwHHrmJVyUt6erKzrNEln+2V76td3B9OhVllyv5HWj0GzTiLKVLqc/f32MTal8pesrRiySqVBKnsDXR9sK2TDAeUJf4rO3tzoDex+tTPAWyvXwP/0EEagWdmjevtoxlYg==; s=purelymail3; d=purelymail.com; v=1; bh=CW1C2XgE1GwasLwClZxpsSpCgPjarIi+QvWOeeRvPus=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: emacs-devel@gnu.org Original-Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 205391443 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sun, 09 Jun 2024 05:53:12 +0000 (UTC) Original-Received: by melete.silentflame.com (Postfix, from userid 1000) id 89AD07F5CFC; Sun, 9 Jun 2024 06:53:08 +0100 (BST) Received-SPF: pass client-ip=34.202.193.197; envelope-from=spwhitton@spwhitton.name; helo=sendmail.purelymail.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:319918 Archived-At: --=-=-= Content-Type: text/plain Hello, I'm planning to add this to GNU ELPA. Posting here for comments. --8<---------------cut here---------------start------------->8--- Variant Lisp Interaction mode for easier interleaving of paragraphs of plain text with Lisp code. This means you can have ;; This buffer is for text that is not saved ... ;; To create a file, visit it with C-x C-f and ... (here is some Lisp) Here is a plain text paragraph )( including some unmatched parentheses. Uh oh! Paredit won't like that. (here is some more Lisp) but (e.g.) Paredit won't complain about the unmatched parentheses. Indeed, the whole plain text paragraph is font-locked as a comment. If you use Paredit but want to be able to use *scratch* for both Lisp interaction and blocks of plain text, then this mode is for you. Also compatible with the orgalist-mode and orgtbl-mode minor modes. To enable this mode after installing this file, simply customise `initial-major-mode' to `literate-scratch-mode'. --8<---------------cut here---------------end--------------->8--- --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=literate-scratch.el Content-Transfer-Encoding: quoted-printable ;;; literate-scratch.el --- Lisp Interaction w/ text paragraphs -*- lexica= l-binding: t -*- ;; Copyright (C) 2023-2024 Free Software Foundation, Inc. ;; Author: Sean Whitton ;; Maintainer: Sean Whitton ;; Package-Requires: ((emacs "29.1")) ;; Version: 1.0pre ;; URL: https://git.spwhitton.name/dotfiles/tree/.emacs.d/site-lisp/literat= e-scratch.el ;; Keywords: lisp text ;; This file is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This file is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this file. If not, see . ;;; Commentary: ;; Variant Lisp Interaction mode for easier interleaving of paragraphs of ;; plain text with Lisp code. This means you can have ;; ;; ;; This buffer is for text that is not saved ... ;; ;; To create a file, visit it with C-x C-f and ... ;; ;; (here is some Lisp) ;; ;; Here is a plain text paragraph )( including some unmatched parenthes= es. ;; Uh oh! Paredit won't like that. ;; ;; (here is some more Lisp) ;; ;; but (e.g.) Paredit won't complain about the unmatched parentheses. ;; Indeed, the whole plain text paragraph is font-locked as a comment. ;; ;; If you use Paredit but want to be able to use *scratch* for both Lisp ;; interaction and blocks of plain text, then this mode is for you. ;; Also compatible with the orgalist-mode and orgtbl-mode minor modes. ;; ;; To enable this mode after installing this file, simply customise ;; `initial-major-mode' to `literate-scratch-mode'. ;;; News: ;; Ver 1.0 YYYY/MM/DD Sean Whitton ;; Initial release. ;;; Code: (defun literate-scratch--extend (start end) (save-excursion (let ((res1 (and (goto-char start) (not (looking-at paragraph-separate)) (and-let* ((new (car (bounds-of-thing-at-point 'paragraph)))) (and (< new start) (setq start new))))) (res2 (and (goto-char end) (not (looking-at paragraph-separate)) (and-let* ((new (cdr (bounds-of-thing-at-point 'paragraph)))) (and (> new end) (setq end new)))))) (and (or res1 res2) (cons start end))))) (defun literate-scratch--propertize (start end) (goto-char start) (let ((start (1- start))) (catch 'finish (while t (when-let* ((comment-start (nth 8 (syntax-ppss)))) (put-text-property (1- (point)) (point) 'syntax-table (eval-when-compile (string-to-syntax "!"))) (put-text-property comment-start (point) 'syntax-multiline t)) (forward-paragraph 1) (backward-paragraph 1) (unless (> end (point) start) (throw 'finish nil)) (setq start (point)) (unless (save-excursion (catch 'done (while t ;; Examine the syntax of the paragraph's first char. ;; If it's whitespace, we need to check the previous ;; paragraph, to handle multiple paragraphs within a defun. (let ((syn (char-syntax (char-after ;; (1+ point) unless at end-of-buf or on first line ;; of a paragraph beginning right at beg-of-buf. (and (not (eobp)) (not (and (bobp) (looking-at "[[:space:]]*[^[:space:]\n]"))) (1+ (point))))))) (cond ((bobp) (throw 'done (memq syn '(?\( ?<)))) ((memq syn '(?\( ?<)) (throw 'done t)) ((not (eq syn ?\s)) (throw 'done nil)))) (backward-paragraph 1)))) (put-text-property (point) (1+ (point)) 'syntax-table (eval-when-compile (string-to-syntax "!")))) (forward-paragraph 1)))) ;; Now also call the usual `syntax-propertize-function' for this mode. (elisp-mode-syntax-propertize start end)) (define-derived-mode literate-scratch-mode lisp-interaction-mode "Lisp Interaction" "Variant `lisp-interaction-mode' designed for the *scratch* buffer. Paragraphs that don't start with `(' or `;' are treated as block comments. This makes it easier to interleave paragraphs of plain text with Lisp. You can enable this mode by customizing the variable `initial-major-mode' to `literate-scratch-mode'." (add-hook 'syntax-propertize-extend-region-functions #'syntax-propertize-multiline t t) (add-hook 'syntax-propertize-extend-region-functions #'literate-scratch--extend t t) (setq-local syntax-propertize-function #'literate-scratch--propertize)) (provide 'literate-scratch) ;;; literate-scratch.el ends here --=-=-= Content-Type: text/plain -- Sean Whitton --=-=-=--