Get real string length in emacs

2.4k Views Asked by At

What is the proper way to compute the actual string length in emacs? By actual I mean I want the number of chars inserted into a buffer after doing something like (insert "\nhi") or (insert "\x100").

For example, I have a snippet for writing expand-abbrev-hook's but it doesn't get the string length right when there are escaped characters, eg.

# -*- mode: snippet -*-
# name: expand abbrev
# key: eah
# --
("${1:abbrev}" ["${2:pre}${3:post}" ${3:$(length yas-text)} nil nil] expand-abbrev-hook :system t)

The value computed in $3 should land the cursor back between $2 and $3 after expansion, but if there are strings with "\n" for example, then length is off a bit.

0

There are 0 best solutions below