Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
6 votes
Accepted

Split a complicated string?

Behold: (defun fancy-split (input) (let (tokens) (with-temp-buffer (insert input) (goto-char (point-min)) (while (not (eobp)) (cond ((looking-at "{") ...
wasamasa's user avatar
  • 22.2k
5 votes

find end of string constant

Some remarks at first: This question should not only be about finding the end of a string. Also finding the beginning of a string is quite complicated if you want to do it right. There may be double-...
Tobias's user avatar
  • 33.2k
5 votes

Split command line into a list of arguments

Does this do what you want? (split-string-and-unquote "program arg1 arg2 \"long argument with spaces\" \"arg\"3") There seemed to be an error in your string with an unmatched \" at the end that ...
John Kitchin's user avatar
  • 11.9k
4 votes
Accepted

find end of string constant

I use this regexp string: "\"\\(?:[^\\\"]\\|\\\\\\(?:.\\|[\n]\\)\\)*\"". It matches two " chars enclosing zero or more occurrences of either a non-", non-backslash or a backslash followed by any ...
Drew's user avatar
  • 77.8k
3 votes
Accepted

Check whether a string is a date in a specific format, e.g. "%Y-%m-%d"

It seems format-time-string uses the same format as strftime(3), and strptime(3) is the reverse of strftime(3), so I wrote an Emacs dynamic module just for strptime(3), for example, (strptime "2020-...
xuchunyang's user avatar
  • 14.6k
3 votes
Accepted

Pretty print s expressions from the command line

I think you should be able to do something like this: emacsclient -e '(pp (with-temp-buffer (insert-file-contents "my-file-containing sexp") (read (current-buffer))))' The problem is that this will ...
sds's user avatar
  • 6,124
2 votes

Split command line into a list of arguments

Since version 28.1, you can use split-string-shell-command which does just that. (split-string-shell-command "program arg1 arg2 \"long argument with spaces\" arg\\\"3") > (&...
Adam Oudad's user avatar
2 votes

Split command line into a list of arguments

Since there doesn't appear to be a function for the job, I wrote one: (defun shell-command-line-to-argument-list (command-line) (let (args arg inquote) (with-temp-buffer (insert command-...
Lassi's user avatar
  • 377
2 votes

Split a complicated string?

Here's something you could do using PEG parser. PEG parsers are a formalism allowing for generation of parsers without a tedious process like the one associated with YACC-style parsers. PEG-style ...
wvxvw's user avatar
  • 11.4k
2 votes

Split a complicated string?

Here's a recursive function that returns the name as a list of its components. (defun name-to-list (name &optional acc) "Takes a BibTeX-style name and returns a list of the name components." (...
Dan's user avatar
  • 33.1k
2 votes
Accepted

Can syntax parsing recognize the SQL '' (escape apostrophe/single quote) construct within SQL strings?

The syntax tables themselves can't handle this right, but Emacs offers syntax-propertize to circumvent this kind of limitation by giving special syntax to specific occurrences of characters in buffers....
Stefan's user avatar
  • 26.5k
2 votes
Accepted

What is a good strategy to locating function arguments in a buffer?

There is the general rule that any widely used programming language such as R has an Emacs language mode and those modes also have functions that parse function arguments. For R there is the huge ...
Tobias's user avatar
  • 33.2k
2 votes

Check whether a string is a date in a specific format, e.g. "%Y-%m-%d"

A combination of regexp-quote and format-spec should help in your case. Especially, format-spec works with format specifiers of the format sequences consisting of one % character and one letter. (...
Tobias's user avatar
  • 33.2k
2 votes
Accepted

JSON parsing fails: json-parse-error "too big integer"

Emacs supports bignums, but presumably libjansson does not (and json-parse-buffer is handing off to that C library to do the heavy lifting). There seems to be an upstream issue for that: https://...
phils's user avatar
  • 51.5k
2 votes

Lisp function to parse shebang line?

You could always look at how auto-mode-interpreter-regexp and interpreter-mode-alist are used by set-auto-mode.
phils's user avatar
  • 51.5k
2 votes
Accepted

How can I make `forward-sexp` handle other balanced character-pairs such as < and > or << and >>?

I have been able to get forward-sexp to recognize the < and > pair by modifying the syntax table the erlang-mode uses: The erlang.el file has a function that sets the syntax table when the ...
PRouleau's user avatar
  • 796
1 vote
Accepted

Add parsing of latex-style .el file to LaTeX-hook using AUCTeX

Since AUCTeX release 13.2.3 (2023-12-07) support for completion, fontification etc. for ltcmd (former xparse) is available out of the box (see https://tex.stackexchange.com/a/703376/105447), so you ...
gusbrs's user avatar
  • 786
1 vote

Can syntax parsing recognize the SQL '' (escape apostrophe/single quote) construct within SQL strings?

Thanks, Stefan, it seems to work like a charm! I.e. the parser state is exactly as expected, and e.g. forward-sexp now jumps over 'McDonald''s', which it did not do without the syntax propertizing. ...
fsavigny's user avatar
1 vote

What is a good strategy to locating function arguments in a buffer?

Under the theory that some answer is better than none, I've posted my hacky solution to this, however I would welcome a better answer than this one. (defun find-next-fcn-arg-separator () "Find the ...
dpritch's user avatar
  • 445

Only top scored, non community-wiki answers of a minimum length are eligible