From 4e94b7d5a337ab7e491410c760b3c71f1e4c4e60 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sat, 10 May 2025 15:56:25 +0700 Subject: [PATCH 01/10] purescript-mode.el: make purescript-literate truly buffer-local It was defined with `defvar` and then made into buffer-local with (make-variable-buffer-local). The call though was only executed once, which is likely an omission as even the documentation states the variable supposed to be buffer-local. So fix that and make it truly buffer-local. --- purescript-mode.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/purescript-mode.el b/purescript-mode.el index dd18942..b7b12d5 100644 --- a/purescript-mode.el +++ b/purescript-mode.el @@ -102,7 +102,7 @@ sure all purescript customize definitions have been loaded." (customize-browse 'purescript)) ;; Are we looking at a literate script? -(defvar purescript-literate nil +(defvar-local purescript-literate nil "*If not nil, the current buffer contains a literate PureScript script. Possible values are: `bird' and `tex', for Bird-style and LaTeX-style literate scripts respectively. Set by `purescript-mode' and @@ -110,7 +110,6 @@ literate scripts respectively. Set by `purescript-mode' and not contain either \"\\begin{code}\" or \"\\end{code}\" on a line on its own, nor does it contain \">\" at the start of a line -- the value of `purescript-literate-default' is used.") -(make-variable-buffer-local 'purescript-literate) (put 'purescript-literate 'safe-local-variable 'symbolp) ;; Default literate style for ambiguous literate buffers. (defcustom purescript-literate-default 'bird From 9412ed0d9092238dc4c4f4d432e94edcd4706fce Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sat, 10 May 2025 16:50:57 +0700 Subject: [PATCH 02/10] purescript-indent.el: make purescript-indent-mode truly buffer-local It was defined with `defvar` and then made into buffer-local with (make-variable-buffer-local). The call though was only executed once, which is likely an omission. Fix that and make it truly buffer-local. --- purescript-indent.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/purescript-indent.el b/purescript-indent.el index 05a1c34..250e6d3 100644 --- a/purescript-indent.el +++ b/purescript-indent.el @@ -1486,9 +1486,8 @@ One indentation cycle is used." ;;; purescript-indent-mode -(defvar purescript-indent-mode nil +(defvar-local purescript-indent-mode nil "Non-nil if the semi-intelligent PureScript indentation mode is in effect.") -(make-variable-buffer-local 'purescript-indent-mode) (defvar purescript-indent-map (let ((map (make-sparse-keymap))) From 7ec3407c11d171475d44279774f46a50d06f634f Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sat, 10 May 2025 16:42:19 +0700 Subject: [PATCH 03/10] Export purescript-literate from a shared location This gets rid of repeated "defvar"s in different files by instead importing the variable from a shared location. --- Makefile | 1 + purescript-font-lock.el | 3 +-- purescript-indent.el | 3 +-- purescript-indentation.el | 2 +- purescript-mode.el | 11 +---------- purescript-vars.el | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 purescript-vars.el diff --git a/Makefile b/Makefile index 3740ef0..71a73de 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ ELFILES = \ purescript-utils.el \ purescript-decl-scan.el \ purescript-yas.el \ + purescript-vars.el \ tests/purescript-sort-imports-tests.el \ tests/purescript-indentation-tests.el \ tests/purescript-font-lock-tests.el \ diff --git a/purescript-font-lock.el b/purescript-font-lock.el index 77f9bae..63a636e 100644 --- a/purescript-font-lock.el +++ b/purescript-font-lock.el @@ -69,6 +69,7 @@ (require 'font-lock) (require 'cl-lib) +(require 'purescript-vars) (defcustom purescript-font-lock-prettify-symbols-alist `(("/\\" . ,(decode-char 'ucs #X2227)) @@ -263,8 +264,6 @@ Returns keywords suitable for `font-lock-keywords'." :type 'boolean :group 'purescript) -(defvar purescript-literate) - (defun purescript-syntactic-face-function (state) "`font-lock-syntactic-face-function' for PureScript." (cond diff --git a/purescript-indent.el b/purescript-indent.el index 250e6d3..c21b265 100644 --- a/purescript-indent.el +++ b/purescript-indent.el @@ -88,11 +88,10 @@ ;;; Code: +(require 'purescript-vars) (require 'purescript-string) (require 'cl-lib) -(defvar purescript-literate) - (defgroup purescript-indent nil "PureScript indentation." :group 'purescript diff --git a/purescript-indentation.el b/purescript-indentation.el index a48a726..be3e62e 100644 --- a/purescript-indentation.el +++ b/purescript-indentation.el @@ -34,6 +34,7 @@ (require 'syntax) (require 'cl-lib) +(require 'purescript-vars) (defvar delete-active-region) @@ -47,7 +48,6 @@ (defvar parse-line-number) (defvar possible-indentations) (defvar indentation-point) -(defvar purescript-literate) (defgroup purescript-indentation nil "PureScript indentation." diff --git a/purescript-mode.el b/purescript-mode.el index b7b12d5..aca85a2 100644 --- a/purescript-mode.el +++ b/purescript-mode.el @@ -34,6 +34,7 @@ (require 'dabbrev) (require 'compile) (require 'outline) +(require 'purescript-vars) (require 'purescript-align-imports) (require 'purescript-sort-imports) (require 'purescript-string) @@ -101,16 +102,6 @@ sure all purescript customize definitions have been loaded." purescript-yas)) (customize-browse 'purescript)) -;; Are we looking at a literate script? -(defvar-local purescript-literate nil - "*If not nil, the current buffer contains a literate PureScript script. -Possible values are: `bird' and `tex', for Bird-style and LaTeX-style -literate scripts respectively. Set by `purescript-mode' and -`literate-purescript-mode'. For an ambiguous literate buffer -- i.e. does -not contain either \"\\begin{code}\" or \"\\end{code}\" on a line on -its own, nor does it contain \">\" at the start of a line -- the value -of `purescript-literate-default' is used.") -(put 'purescript-literate 'safe-local-variable 'symbolp) ;; Default literate style for ambiguous literate buffers. (defcustom purescript-literate-default 'bird "Default value for `purescript-literate'. diff --git a/purescript-vars.el b/purescript-vars.el new file mode 100644 index 0000000..8417113 --- /dev/null +++ b/purescript-vars.el @@ -0,0 +1,33 @@ +;;; purescript-vars.el --- Variable definitions for PureScript Mode -*- lexical-binding: t -*- + +;; Author: 1997-1998 Graeme E Moss +;; 1997-1998 Tommy Thorn +;; 2003 Dave Love +;; 2025 Konstantin Kharlamov + +;; This file is not part of GNU Emacs. + +;; 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, 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 program. If not, see . + +(defvar-local purescript-literate nil + "If not nil, the current buffer contains a literate PureScript script. +Possible values are: `bird' and `tex', for Bird-style and LaTeX-style +literate scripts respectively. Set by `purescript-mode' and +`literate-purescript-mode'. For an ambiguous literate buffer -- i.e. does +not contain either \"\\begin{code}\" or \"\\end{code}\" on a line on +its own, nor does it contain \">\" at the start of a line -- the value +of `purescript-literate-default' is used.") +(put 'purescript-literate 'safe-local-variable 'symbolp) + +(provide 'purescript-vars) From cd2ee96628677b3fde08dab96bdb9f107c7391f7 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sat, 10 May 2025 17:26:27 +0700 Subject: [PATCH 04/10] purescript-font-lock.el: assume purescript-literate is always bound Now that it's exported from a common location, there's no reason it shouldn't be (besides a bug of course). --- purescript-font-lock.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/purescript-font-lock.el b/purescript-font-lock.el index 63a636e..8899bc2 100644 --- a/purescript-font-lock.el +++ b/purescript-font-lock.el @@ -306,13 +306,13 @@ Returns keywords suitable for `font-lock-keywords'." ;;;###autoload (defun purescript-font-lock-choose-keywords () - (cl-case (bound-and-true-p purescript-literate) + (cl-case purescript-literate (bird purescript-font-lock-bird-literate-keywords) ((latex tex) purescript-font-lock-latex-literate-keywords) (t purescript-font-lock-keywords))) (defun purescript-font-lock-choose-syntactic-keywords () - (cl-case (bound-and-true-p purescript-literate) + (cl-case purescript-literate (bird purescript-bird-syntactic-keywords) ((latex tex) purescript-latex-syntactic-keywords) (t purescript-basic-syntactic-keywords))) From d2111a77a5f1b050a0a74939c5146d68d070df9d Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sat, 10 May 2025 16:55:21 +0700 Subject: [PATCH 05/10] purescript-mode.el: remove unused eldoc-print-current-symbol-info-function --- purescript-mode.el | 2 -- 1 file changed, 2 deletions(-) diff --git a/purescript-mode.el b/purescript-mode.el index aca85a2..4257794 100644 --- a/purescript-mode.el +++ b/purescript-mode.el @@ -279,8 +279,6 @@ details." turn-on-purescript-simple-indent turn-on-purescript-unicode-input-method)) -(defvar eldoc-print-current-symbol-info-function) - ;; The main mode functions ;;;###autoload (define-derived-mode purescript-mode prog-mode "PureScript" From e3862d04e2a2e3a0e95aca99996dd7ea80e3b4ab Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sat, 10 May 2025 16:57:10 +0700 Subject: [PATCH 06/10] purescript-indentation.el: rm defvar for delete-active-region All supported Emacs versions have the variable, so no need to have it defined still. --- purescript-indentation.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/purescript-indentation.el b/purescript-indentation.el index be3e62e..3662c85 100644 --- a/purescript-indentation.el +++ b/purescript-indentation.el @@ -34,10 +34,9 @@ (require 'syntax) (require 'cl-lib) +(require 'simple) (require 'purescript-vars) -(defvar delete-active-region) - ;; Dynamically scoped variables. (defvar following-token) (defvar current-token) From 029c1509d2b0876e004dd2e7d9e1ae73bb8ac636 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sat, 10 May 2025 17:03:26 +0700 Subject: [PATCH 07/10] purescript-indentation.el: group together all internal defvars --- purescript-indentation.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/purescript-indentation.el b/purescript-indentation.el index 3662c85..6a84507 100644 --- a/purescript-indentation.el +++ b/purescript-indentation.el @@ -37,7 +37,7 @@ (require 'simple) (require 'purescript-vars) -;; Dynamically scoped variables. +;; Dynamically scoped internal variables. (defvar following-token) (defvar current-token) (defvar left-indent) @@ -47,6 +47,7 @@ (defvar parse-line-number) (defvar possible-indentations) (defvar indentation-point) +(defvar purescript-indent-last-position) (defgroup purescript-indentation nil "PureScript indentation." @@ -117,9 +118,6 @@ (define-key keymap [?\C-d] 'purescript-indentation-delete-char) keymap)) -;; Used internally -(defvar purescript-indent-last-position) - ;;;###autoload (define-minor-mode purescript-indentation-mode "PureScript indentation mode that deals with the layout rule. From e23a52893b830d8165c02b594cbe3602f9f9757b Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sat, 10 May 2025 17:06:03 +0700 Subject: [PATCH 08/10] purescript-indentation.el: simplify localizing indent-last-position --- purescript-indentation.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/purescript-indentation.el b/purescript-indentation.el index 6a84507..4faeab3 100644 --- a/purescript-indentation.el +++ b/purescript-indentation.el @@ -47,7 +47,7 @@ (defvar parse-line-number) (defvar possible-indentations) (defvar indentation-point) -(defvar purescript-indent-last-position) +(defvar-local purescript-indent-last-position nil) (defgroup purescript-indentation nil "PureScript indentation." @@ -133,9 +133,7 @@ autofill-mode." (set (make-local-variable 'indent-line-function) 'purescript-indentation-indent-line) (set (make-local-variable 'normal-auto-fill-function) - 'purescript-indentation-auto-fill-function) - (set (make-local-variable 'purescript-indent-last-position) - nil))) + 'purescript-indentation-auto-fill-function))) ;;;###autoload (defun turn-on-purescript-indentation () From a4434b5095b396b616248eb7f40ade0b8e479fd1 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sat, 10 May 2025 17:14:41 +0700 Subject: [PATCH 09/10] purescript-indentation.el: replace killing/make-local with just setq-local There's no reason for killing (I even checked other major modes), and the make-local-variable may be replaced by just setq-local. --- purescript-indentation.el | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/purescript-indentation.el b/purescript-indentation.el index 4faeab3..ddfef9e 100644 --- a/purescript-indentation.el +++ b/purescript-indentation.el @@ -126,14 +126,12 @@ set and deleted as if they were real tabs. It supports autofill-mode." :lighter " Ind" :keymap purescript-indentation-mode-map - (kill-local-variable 'indent-line-function) - (kill-local-variable 'normal-auto-fill-function) (when purescript-indentation-mode (setq max-lisp-eval-depth (max max-lisp-eval-depth 600)) ;; set a higher limit for recursion - (set (make-local-variable 'indent-line-function) - 'purescript-indentation-indent-line) - (set (make-local-variable 'normal-auto-fill-function) - 'purescript-indentation-auto-fill-function))) + (setq-local indent-line-function + #'purescript-indentation-indent-line) + (setq-local normal-auto-fill-function + #'purescript-indentation-auto-fill-function))) ;;;###autoload (defun turn-on-purescript-indentation () From d31134c0b23aa339c4707c3f96b5c5c134d81c69 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sat, 10 May 2025 17:29:44 +0700 Subject: [PATCH 10/10] purescript-mode.el: remove warning about purescript-font-lock-symbols It's been there since 2019 and the variable has been no-op since then as well. I think it's fair to assume anyone who were still using the variable either moved on, or if they didn't notice anything, they will probably keep not noticing anything, because the variable has been no-op for so long. --- purescript-mode.el | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/purescript-mode.el b/purescript-mode.el index 4257794..e1218cb 100644 --- a/purescript-mode.el +++ b/purescript-mode.el @@ -325,10 +325,7 @@ see documentation for that variable for more details." (setq-local beginning-of-defun-function 'purescript-beginning-of-defun) (setq prettify-symbols-alist purescript-font-lock-prettify-symbols-alist ;; make (ff-find-other-file) find .js FFI file, given .purs - ff-other-file-alist '((".purs\\'" (".js")))) - (when (bound-and-true-p purescript-font-lock-symbols) - (warn "`purescript-font-lock-symbols' is obsolete: please enable `prettify-symbols-mode' locally or globally instead.")) - ) + ff-other-file-alist '((".purs\\'" (".js"))))) (defun purescript-fill-paragraph (justify) (save-excursion