schemedoc / cookbook

New Scheme Cookbook
https://cookbook.scheme.org
29 stars 3 forks source link

Memory leak in Arthur Emacs code #67

Closed jcubic closed 1 year ago

jcubic commented 1 year ago

This is the code Arthur Emacs symbol mapping

(defvar pretty-scheme-keywords
  (mapcar (lambda (pair)
            (cons (concat "\\(" (regexp-quote (car pair)) "\\)")
                  (cdr pair)))
          '(("->"  . #x2192)
            ("<="  . #x2264)
            ("<==" . #x21D0)
            (">="  . #x2265)
            ("==>" . #x21D2)))
  "Alist from regexps to Unicode code points.")

(defun prettify-scheme ()
  (add-to-list 'prettify-symbols-alist '("lambda" . #x3BB))
  (font-lock-add-keywords
   nil
   (mapcar (lambda (keyword)
             `(,(car keyword)
               (0 (progn (compose-region (match-beginning 1) (match-end 1)
                                         ,(cdr keyword)
                                         'decompose-region)
                         nil))))
           pretty-scheme-keywords))
  (turn-on-font-lock))

(add-hook 'scheme-mode-hook 'prettify-scheme)

It seems that on each opening of Scheme file new lambda will be added to the list which makes the list grow and grow on each open file.

I think that this line:

(add-to-list 'prettify-symbols-alist '("lambda" . #x3BB))

Should be outside of the function is it's called only once.

arthurgleckler commented 1 year ago

Which list grows? I don't see it. add-to-list only adds an element that isn't already present, and font-locka-dd-keywords adds to a buffer-local variable.

jcubic commented 1 year ago

Oh, I didn't know that it's not really intuitive that the add-to-list ignores duplicates.

Thanks for the clarification, I'm closing then.