Skip to content

Defvars cleanup #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
7 changes: 3 additions & 4 deletions purescript-font-lock.el
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

(require 'font-lock)
(require 'cl-lib)
(require 'purescript-vars)

(defcustom purescript-font-lock-prettify-symbols-alist
`(("/\\" . ,(decode-char 'ucs #X2227))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -307,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)))
Expand Down
6 changes: 2 additions & 4 deletions purescript-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1486,9 +1485,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)))
Expand Down
23 changes: 8 additions & 15 deletions purescript-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@

(require 'syntax)
(require 'cl-lib)
(require 'simple)
(require 'purescript-vars)

(defvar delete-active-region)

;; Dynamically scoped variables.
;; Dynamically scoped internal variables.
(defvar following-token)
(defvar current-token)
(defvar left-indent)
Expand All @@ -47,7 +47,7 @@
(defvar parse-line-number)
(defvar possible-indentations)
(defvar indentation-point)
(defvar purescript-literate)
(defvar-local purescript-indent-last-position nil)

(defgroup purescript-indentation nil
"PureScript indentation."
Expand Down Expand Up @@ -118,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.
Expand All @@ -129,16 +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)
(set (make-local-variable 'purescript-indent-last-position)
nil)))
(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 ()
Expand Down
19 changes: 2 additions & 17 deletions purescript-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
(require 'dabbrev)
(require 'compile)
(require 'outline)
(require 'purescript-vars)
(require 'purescript-align-imports)
(require 'purescript-sort-imports)
(require 'purescript-string)
Expand Down Expand Up @@ -101,17 +102,6 @@ sure all purescript customize definitions have been loaded."
purescript-yas))
(customize-browse 'purescript))

;; Are we looking at a literate script?
(defvar 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.")
(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
"Default value for `purescript-literate'.
Expand Down Expand Up @@ -289,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"
Expand Down Expand Up @@ -337,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
Expand Down
33 changes: 33 additions & 0 deletions purescript-vars.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;;; purescript-vars.el --- Variable definitions for PureScript Mode -*- lexical-binding: t -*-

;; Author: 1997-1998 Graeme E Moss <gem@cs.york.ac.uk>
;; 1997-1998 Tommy Thorn <thorn@irisa.fr>
;; 2003 Dave Love <fx@gnu.org>
;; 2025 Konstantin Kharlamov <Hi-Angel@yandex.ru>

;; 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 <http://www.gnu.org/licenses/>.

(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)