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.

Filter by
Sorted by
Tagged with
1
vote
1answer
69 views

Elisp: How to accumulate function return into a list

I have this small snippet of Elisp code that decodes kernel traces: (defvar projbase "/my/proj/base") (setq my_shell_output (substring (shell-command-to-string (concat "/home/demetra/scripts/...
6
votes
2answers
1k views

What's the idiomatic (or best) way to trim surrounding whitespace from a string?

I'm working with strings which may have any number of prefix and suffix spaces, tabs, newlines, etc. Currently I have this: (replace-regexp-in-string "^[^[:alnum:]]*\\(.*\\)[^[:alnum:]]*$" "\\1" ...
1
vote
1answer
39 views

Break a long string in a concatenation of shorter ones

Is there a predefined way to split "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud ...
4
votes
3answers
276 views

How to modify a string without altering its text properties

If I propertize a string and save it to a variable, how can I change the string within that variable without altering its text properties? For example: (setq myvar (propertize "testing" ...
0
votes
1answer
25 views

Check if a character is in a string

It is easy to present list of allowed characters as string, like " \n\t". (char-before) return integer. How can I check that a character is in a string? There is What is the easiest way to check if ...
0
votes
2answers
44 views

Sort lines in a string

Given I have a string that maybe came from a buffer, or a clipboard, or wherever; how do I sort-lines in it? Given that sort-lines only works with a region, I assume I have to put it to a temporary ...
1
vote
1answer
43 views

how to convert “foobar?” into 'foobar?

I'm trying to turn a string containing a question mark into the corresponding symbol but: (intern "foobar?") returns 'foobar\? How can i do the same thing without the backslash? Also i'm interested ...
0
votes
0answers
193 views

Format strings for org-agenda-prefix-format

I want to customize org-agenda-prefix-format but am unable to find something in the reference explaining the syntax and the format strings I can use. The manual simply states: You can also ...
0
votes
1answer
34 views

Search for occurrence of character within a string without using the common lisp library?

I need to extract certain information from buffer names, and I'm doing so by extracting substrings based on the position of unique characters within a buffer name string. So, I currently am doing ...
0
votes
1answer
30 views

Getting characters from current position to end of line as a substring

Is there a standard Elisp function which can return as a substring (without any of the text-properties) the characters from the current position of point to the last nonwhite space character on that ...
1
vote
3answers
64 views

Function that does `M-x replace-regexp` or `M-x occur` with a fixed pattern and replacement strings

I often use M-x replace-regexp and M-x occur with some fixed regexp pattern and replacement string on many files. Doing it manually by opening each file in an Emacs buffer and hitting the keys is ...
0
votes
1answer
35 views

How the get the text value of a complete value of a variable?

here a little example to explain my problem : How to get "marge" or ("marge") from oef-highlighted-variable ? oef-highlighted-variable #("marge" 0 5 (fontified nil face oef-font-variable-name-face)) ...
0
votes
3answers
140 views

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".
2
votes
1answer
27 views

repeat string-inflection command

I would like to repeat M-x string-inflection-camelcase on several words. For example in: foo_bar baz qux-quux quuz CORGE_GRAULT GARPLY I place my cursor on foo_bar and then enter M-x string-...
2
votes
1answer
94 views

Normalize string to make it file/path safe

Often I find my self doing this C-x C-f to create a file, while in the mini buffer prompt, paste a url like "https://github.com/seamusabshere/cache_method/issues/15" from the clipboard. Since "https:...
2
votes
0answers
55 views

Calculate current-column including display properties

I am trying to calculate the width of text within either a buffer or a string after it has been displayed, i.e. after taking into account the width of any display properties, such as embedded images, ...
4
votes
1answer
83 views

Width of string as if it were displayed

From the documentation of string-width string: This function returns the width in columns of the string string, if it were displayed in the current buffer and the selected window. For me this ...
2
votes
2answers
40 views

Arbitrary length lists as argument for interactive function

Say I have a defun with a dolist inside that I want to be able to pass a string that is then converted to a list with a length equal to the number of words in said string via the minibuffer, so ...
2
votes
1answer
120 views

Concat in Org Easy Templates [duplicate]

I have a variety of org easy templates. I have a new file template which includes a #+DATE header that I'd like to populate with the current date [at the time the template is called]. The ...
1
vote
3answers
106 views

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"
2
votes
0answers
34 views

Collapse xml-node-children from `xml.el` into a string

An API I have used for years (via an elisp package) recently started inserting formatting tags (particularly for <i></i> italics) into the 'ArticleTitle' field of entries. The assumption ...
2
votes
2answers
65 views

How can I use a char as a counter?

I have this LaTeX code: \begin{enumerate}[a] \affiliation{...} \affiliation{...} \affiliation{...} ... \affiliation{...} \end{enumerate} and, using a script written in Emacs Lisp, I want to ...
1
vote
1answer
123 views

Why do regexp that matches text in buffer does not (necessarily) match same text in string?

I have a regexp, org-parse-regexp which matches org items which I define to be a heading and a source block (actually, I include more stuff but I want to keep it simple). I've tested it using re-...
1
vote
2answers
78 views

match-data fails to consider only last search with string-match and persists across sessions

Using emacs 25.3.1, I am trying to access the match data after I search a string with string-match. But the match data is wrong. To find out why I tried out the manual's simple example. (string-...
0
votes
0answers
44 views

How can I get my target string point/marker without moving the pointer?

Lets say I have the following LaTeX code: \ref{AAA}, \ref{BBB} ... \ref{BBB,CCC,DDD} \begin{the bibliography}{99} \bibitem{AAA} \bibitem{BBB} and I want to write a function that does: (perform-...
2
votes
1answer
188 views

Interpolate environment variables in string

I am trying to write a function that will interpolate the enviroment variables stored in process-environment in a string. For example, if I have the string "This is $Foo and ${Bar}_none and '$skip'" ...
3
votes
3answers
152 views

Is there a way to autoindent single quoted lines automatically for python code?

The python.el mode has several ways to fill docstrings, but I would like to fill single quoted lines. Is there a function that would change this: variable = { 'key': ' this is a very long ...
2
votes
1answer
311 views

prettify-symbols-mode and multi-character replacements?

With ``prettify-symbols-mode'' it is possible to replace strings by a character, or a character composition, e.g. ;; \lambda → λ (push '("\\lambda" . ?λ) prettify-symbols-alist) Optionally, it ...
6
votes
3answers
88 views

Split a complicated string?

Q: how do I split a complicated string when whitespace delimiters aren't discriminating enough? Background I'm working with BibTeX files. I want to split an author string of the form "first-name ...
2
votes
2answers
542 views

Split line every n characters

I have a long binary string that I would like to split every 32 characters. Is there a command that can do this for me? I have tried word wrapping, but it splits per word. It has no effect since a ...
0
votes
1answer
132 views

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 ...
2
votes
2answers
95 views

What is the best way to search forward/backward for a token?

Sometimes I want to search for a specific word but I don't want to find words which have my search string as a substring. For example, if I search for "pan" (bread, in Spanish), I don't want to find ...
2
votes
2answers
91 views

Evaluate parts inside text-property string using read syntax?

I just discovered that it is possible to define strings with text properties using the special read syntax. Now I'm trying to evaluate a value of a property within the string definition so something ...
6
votes
3answers
2k views

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 ...
1
vote
1answer
49 views

Using a backslash with occur

How can I use occur (M-s o) to search for a string that contains a backslash, e.g. \def?
2
votes
1answer
55 views

Strange behaviour of match-string/string-match

I have this code (defun string-match-test () (interactive) (string-match "12345" (buffer-string)) (setq STRING (match-string 0)) (read-string STRING) (goto-char (point-max)) (insert ...
1
vote
1answer
89 views

Passing a string with substitutions to the “perform-replace” command

I want to generalize this query-replace regexp: (perform-replace "Geophysical[\s\t\n]*Research[\s\t\n]*Letters" "Geophys.\\\\ Res.\\\\ Lett." t t nil 1 nil (point-...
1
vote
1answer
134 views

Get multibyte string byte

Given a multibyte string "x=π", how to get 4-th byte of the string, without creating string copy with something like string-as-unibyte? Pseudo code: (string-nth-byte 4 "x=π"). Expected result: 128. ...
1
vote
1answer
95 views

major-mode as argument to string-match vs string-equal

Why is (string-match "lisp" major-mode) not working, while (string-equal "lisp-interaction-mode" major-mode) is working? string-match results in debugger message: (wrong-type-argument stringp lisp-...
0
votes
1answer
45 views

buffer-file-name can return propertized text?

Once upon a time I was surprised to see buffer-file-name sometimes return propertized text like #("/tmp/foo" 1 4 (face flx-highlight-face)) instead of "/tmp/foo". I got in the habit of defensively "...
0
votes
1answer
714 views

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 ...
1
vote
1answer
249 views

Using quail input-method to insert a string

The standard way to define an abbreviation using quail is as follows: (quail-define-rules ("a" ?s )) Inserting "a" gives "s". I am wondering if one can insert an arbitrary string using quail, I ...
1
vote
1answer
163 views

Single function to return file contents as a string

I'm wondering if there's a terse (i.e. single function) approach for reading a file's content given its path and returning it as a string. My go-to has been: (with-temp-buffer (insert-file-...
1
vote
3answers
35 views

How to know if user input a string or a number using interactive

I want to check if a user input a word or a number. And I write the function look like this: (defun check-input (arg) "description" (interactive "senter arg: ") (setq isnum (string-match "\\'[0-...
17
votes
1answer
2k views

How to strip decorations (text properties) from a string?

By a "decorated string" I mean something like #("foo" 0 4 (fontified t face font-lock-function-name-face)) ...as opposed to the "plain string" "foo" (If Elisp code reads a string directly from a ...
1
vote
0answers
22 views

Cperl font lock regions in here docs

I am having a problem in cperl-mode described in this question. Basically inserting a newline at the start of a line in here doc in cperl-mode is breaking the syntax highlighting. One of the answers ...
1
vote
1answer
131 views

Building a list of strings with a regexp while loop

I'd like to perform a regexp search, capture part of a matched string, and save that part to a list. (Eventually the plan is to save this list to a file in a particular format, but for now a simple ...
1
vote
1answer
71 views

Cperl-mode syntax highlighting breaks when inserting a newline into a here doc

in cperl-mode, here docs are colored with a font-lock-string-face. However if you used any function that inserts a newline on a blank line (e.g. M-: (insert "\n")) it will cause all code after the ...
0
votes
0answers
68 views

Get emacs to read unquoted strings in json

I am trying to use emacs-lisp to interact with a MongoDB. Here is an example of a string that mongo returns, that emacs cannot read. The problem is the unquoted ObjectId and ISODate items (if I put ...
0
votes
1answer
66 views

Why is “*\\Completions\\*” formatting used when specifying buffer names for display-buffer-alist?

From GNU Emacs Manual: 20.6.2: If you prefer Emacs to display a temporary buffer in a different fashion, we recommend to customize the variable display-buffer-alist (see Choosing a Window for ...