Parsing parentheses: smie vs syntax table gives one example of how to use syntax-propertize-function but I wonder if someone could help me with another example. I'm working with clojure-mode. Here's a recipe to reproduce the problem:

;; load with emacs -Q -l clojure-init.el

(package-initialize nil)
(setq package-enable-at-startup nil)
(unless (assoc-default "melpa" package-archives)
  (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)

(unless (package-installed-p 'use-package)
  (package-install 'use-package))

(setq use-package-verbose t)
(require 'use-package)

(use-package clojure-mode
  :ensure t :defer t)

Then M-x clojure-mode RET and insert

(["phonemes" java.lang.String] ["rhymingPair" [Ljava.lang.String;])

You'll see that backward-sexp / forward-sexp breaks in the viscinity of the [Ljava... and that the last few characters are understood as a comment. More specifically, ["rhymingPair" [Ljava.lang.String;] should be understood as one valid sexp.

  • Unless I missed out on some secret clojure-syntax, what you've entered is no valid clojure code and the last few characters are indeed a comment.
    – politza
    Jun 19, 2015 at 21:09
  • (type (into-array String ["Awesome"])) returns [Ljava.lang.String; and (list (type (into-array String ["Awesome"])) 1) returns ([Ljava.lang.String; 1). So if you believe in homoiconicity then it is valid code. That said, ([Ljava.lang.String; 1) can't be entered on the REPL in CIDER. I don't know if that's a CIDER bug or a bona fide feature of Clojure. The main point is that I have a bunch of output from Clojure that contains this symbol, and I'd like to be able to navigate it in Emacs via forward- and backward-sexp commands. Jun 19, 2015 at 23:34
  • if you believe in homoiconicity -- You've watched to many clojure videos.
    – politza
    Jun 20, 2015 at 9:48
  • "I don't know if that's a CIDER bug or a bona fide feature of Clojure." Then start a regular repl and try it. ;-)
    – Malabarba
    Jun 21, 2015 at 0:31
  • I did, and also raised this thread groups.google.com/forum/#!topic/clojure/F8isrR-u-qQ getting a pointer to bitbucket.org/morgon/jfreeze Jun 21, 2015 at 14:49

1 Answer 1

(defun clojure-syntax-propertize-array-class (beg end)
  "Put word `syntax-table' property on \"[Lfoo.Bar;\"."
  (let ((word-syntax (string-to-syntax "w")))
     beg end 'syntax-table nil)
      (goto-char beg)
      (while (re-search-forward
              (rx (and (group ?\[)
                       (* (or (syntax ?w) ?.))
                       (group ?\;)))
              end t)
        (dotimes (i 2)
           (match-beginning (1+ i))
           (match-end (1+ i))
           'syntax-table word-syntax))))))

(define-minor-mode clojure-weird-syntax-mode
  nil nil nil nil
    (jit-lock-register 'clojure-syntax-propertize-array-class)
    (setq-local parse-sexp-lookup-properties t))
    (jit-lock-unregister 'clojure-syntax-propertize-array-class)
    (kill-local-variable 'parse-sexp-lookup-properties))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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