Questions tagged [string]

A string is a sequence of characters, which can be user data or used internally in Emacs. For example, string to search, replace, save in a register and so on, file name, etc.

Manipulating strings of characters in Emacs Lisp.

Useful links:

155 questions
14
votes
3 answers

How to wrap a single string literal across multiple lines?

Is it possible to write a single line for an Elisp string: "hello world" As: "hello world" Without inserting a newline character? (wrapping a string literal). I read that adding a tilde at the end of the line does this in some lisp's, but its not…
ideasman42
  • 8,786
  • 1
  • 32
  • 114
3
votes
1 answer

Alternative to `file-name-extension` that will include `~`

I am looking for an alternative to file-name-extension that will include an ending ~ if there is one. For example, if there is a file named foo.el~, the result should be el~. Rather than using the generic split-string, I was hoping there might be…
lawlist
  • 19,106
  • 5
  • 38
  • 120
2
votes
2 answers

Getting first number from string

The following function fails to return "16": (string-to-number "bm16") It seems to get tripped up if the first characters of a string aren't numbers. Is there a way to construct an elisp function which takes a string of text and returns the number…
George
  • 919
  • 5
  • 17
2
votes
1 answer

How to programmatically surround a string with escaped double-quote

It seems that my question should be common knowledge, and I thought I knew it (at some point in the distant past), but the answer escapes me tonight. I'd like to take a string like "foo" and programmatically convert it to "\"foo\"". Is there a…
lawlist
  • 19,106
  • 5
  • 38
  • 120
1
vote
1 answer

Stringify a list to a string without truncation

I am working on improving the org babel racket mode and am running into issues with inserting longer vars Whether I do (format "%S" '((2 0 0 4 2 0 0 3 0 0 4 0 0 7))) or (with-output-to-string (princ '((2 0 0 4 2 0 0 3 0 0 4 0 0 7)))) I…
George Mauer
  • 407
  • 3
  • 9
1
vote
3 answers

How to concatenate a string and a list?

I would like to concatenate a string (e.g. "abc") and a list (e.g. '(aa bb)) so as to obtain "abc aa bb".
Francesco Cadei
  • 347
  • 3
  • 17
1
vote
3 answers

Simple way to test if string contains float eg. "8.3"

I thought (defun string-integer-p (string) was cool, I found it in the emacswiki. Is there a variant of it I can use to test if string contains float eg. "8.3"
american-ninja-warrior
  • 3,903
  • 2
  • 24
  • 44
1
vote
1 answer

Is there a string manipulation difference between Emacs 24 and 25.1?

I'm test-driving Emacs 25.1 and have noticed that a simple concat command, which used to work in v.24 (and v.23), doesn't work in v.25.1: (setq yas-snippet-dirs (concat user-emacs-directory "snippets")) In v.25.1 I get the following error…
NVaughan
  • 1,481
  • 12
  • 27
0
votes
1 answer

How do I compare empty string with ""?

I want to understand why (when (string= issue "") (error "Issue number missing")) doesn't throw an error when issue is empty, but (when (= (length issue) 0) (error "Issue number missing")) works as expected. Documentation of string= states…
0
votes
2 answers

Problem reducing over string

I wanted to define a function that removes all spaces from a given string: (defun remove-whitespace (raw-string) (cl-reduce (lambda (acc char) (if (equal " " (char-to-string char)) acc (concat acc…
Namudon'tdie
  • 159
  • 6
0
votes
1 answer

Expand variables before concat'ing them

I have (setq TeX-auto-local "subdir") (setq TeX-macro-private '("dir/")) I want to set TeX-auto-private to dir/subdir by joining TeX-auto-local and TeX-macro-private together. I thought it was easy but I can't find a way.
Arch Stanton
  • 1,657
  • 11
  • 23
0
votes
1 answer

string-match matches buffer contents, instead of argument string

I am trying to parse file permissions using string-match. My code is, (setq fmode (nth 8 (file-attributes "/Users/sk/a.js"))) (message "file mode is as, - %s" fmode) (string-match "^.\\(...\\)\\(...\\)\\(...\\)$" fmode) (message "User permission - …
Saravana
  • 2,071
  • 13
  • 32
-1
votes
1 answer

How to convince emacs to interpret string of any characters as string

I want to insert this template: << prints("on_%s.gd:"%name, "msg: %s"%msg); >> How to convince emacs it's a string?
VanDeiMin
  • 1
  • 1