3

Okay, I'm not sure whether this question is more relevant to Common Lisp, or to Emacs.

I have reader macros in Common Lisp (found them here), that allow the declaration of hash-tables by:

#{'a 'b, 
'c 'd}

I'd like it to be indented as (both in emacs, and REPL - slime / portacle in particular):

#{'a 'b,
  'c 'd}

And I'd like some guidance. I looked at the top of this, but I don't quite understand how to do it for reader macros as well.

My current (relevant) code is as follows:

(defun read-left-brace (stream char n)
  (declare (ignore char))
  (let ((*readtable* (copy-readtable)))
    (set-macro-character +comma+ 'read-separator)
    (loop
      for key = (read-next-object-for-hash-table +right-brace+
                                                 +comma+
                                                 stream)
      while key
      for value = (read-next-object-for-hash-table +right-brace+
                                                   +comma+
                                                   stream)
      collect (list (eval key) (eval value)) into pairs
      finally (return (make-hash pairs)))))
0

The closest thing would be putting this in .emacs

(use-package lisp-mode
  :config
  (modify-syntax-entry ?\[ "(]" lisp-mode-syntax-table)
  (modify-syntax-entry ?\] ")[" lisp-mode-syntax-table)
  (modify-syntax-entry ?\{ "(}" lisp-mode-syntax-table)
  (modify-syntax-entry ?\} "){" lisp-mode-syntax-table))

Post that, the documentation for modify-syntax-entry should be helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.