Hacker News new | ask | show | jobs
by natrys 1039 days ago
Yeah that's the classic comma in CSV problem. The solution is to indeed use a proper grammar/parser. The "forward-sexp" understands that as per major-mode rule as you say. Another more modern and declarative solution would be to take advantage of the full parse tree at your disposal thanks to tree-sitter (available in Emacs 29.1). Then you can simply do:

    (let ((list (treesit-thing-at-point "list" 'nested))
          (query "(list (string (string_content) @item))"))
      (cl-loop for (_ . item) in (treesit-query-capture list query)
               collect (treesit-node-text item t)))