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
0
votes
1answer
34 views

Elisp function to remove commas in the region

I'm learning writing Elisp functions to perform small tasks and get to a place where executing a function on the region will replace it with the value returned by the function. Below is a short ...
0
votes
0answers
27 views

Why text properties are overridden in this context?

I'm trying to understand why text properties are overridden when creating a list inside a function. I'm wondering if it is expected or a bug. For example, if I create a list of fruits like this, each ...
0
votes
1answer
53 views

How to insert the result of evaluating a sexp in a string?

I am new to Emacs and I am reading Elisp guide inside Emacs. I am at the Args as Variable or list chapter. There is listed below code- (concat "The " (number-to-string (+ 2 value)) "...
0
votes
2answers
51 views

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 ...
0
votes
1answer
59 views

How to change encoding of a string (to fix bad encoding)?

I'm really confused about this issue since it should be doable, but i fail to understand it. I have some file with broken encoding (a pdf file, actually), which I copy some text from. When I paste ...
0
votes
1answer
29 views

capture the content of buffer as a list

I want to pass a buffer's content into a list. I figured out how to read the content of the buffer I want to use but cannot figure out how to correctly capture the content and then use it as a list. ...
3
votes
1answer
155 views

How can I convert a string form of a list to an actual list?

I would like to convert these two strings "(a b c)" "(9 . 3)" to these (a b c) (9 . 3) I'd had some luck with the first one evaluating this, (mapcar 'intern (split-string (string-...
0
votes
0answers
23 views

how to add double quotes in strings with single quotes using electric-pair-mode

if i write a double quote in a string with single quotes, i want electric-pair-mode to write another double quote. Example: <?php class test { public function test2() { ...
1
vote
1answer
25 views

Storing some text from a buffer into a variable

What is the "standard" way to store some text obtained from a buffer into a variable? The only way I could think of was to use something along the lines of (let ((beg (point))) (end-of-line) ...
2
votes
2answers
56 views

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 ...
0
votes
1answer
50 views

Best practice for long string literals in emacs lis?

What are best practices for handling long string literals in Emacs Lisp? E.g. (... stuff that causes indentation ... (error "`my-config-alist' mapped command `%s' to `%S' ...
2
votes
1answer
55 views

How to replace the first element of the `kill-ring` by a modification of it?

I am trying to modify the string that is to yanked My goal is to modify certains paths before yanking, in order to transform them in relative to path actual buffer file. Following this post, I tried ...
1
vote
2answers
87 views

How to evaluate a list containing strings or un-evaluated blocks into a string? (like format-mode-line)

The mode-line-format can be a list of strings, but it can also include un-evaluated blocks, e.g: (setq mode-line-format (list "Hello" '(:eval (my-function-call)) "There&...
1
vote
1answer
178 views

org-babel-tangle error

I am experiencing a very unusual (concerning) error with my org-mode installation, and I am afraid that something might be broken. First, I have this setup in my .emacs file ;; Use my org-mode file as ...
0
votes
0answers
30 views

Extract year from different date strings in alist

I have a function that tries to extract the year from date strings stored in an alist below: (setq entry '(("date" . "1998/03") ("origdate" . "1930"))) (...
0
votes
1answer
24 views

"if" clause within s-format string

Is it possible to add an "if" clause to a s-format string? The code below is adapted from bibtex-completion-apa-format-reference in the helm-bibtex package. (s-format "${...
1
vote
1answer
40 views

Defining keyboard shortcuts from an argument in a function

I would like to write a command that defines key bindings for me, so that I can feed in key y (for example) and have it define key bindings for M-y, C-y etc. I'm trying to concat the command argument ...
0
votes
2answers
100 views

Get bibtex key from helm-bibtex

I would like to get the bibtex key of references in my .bib database as a string via helm-bibtex. (defun get-bibtex-key () (interactive) (with-temp-buffer (helm-bibtex) (if (string-prefix-...
4
votes
1answer
701 views

Regex for the last line of a string

I'm trying to search for the last line in a string (lines separated by \n) using string match but I cannot make it work as intended. The code below evaluates to 0 while I would have expected 4. I ...
1
vote
2answers
211 views

Colored string in mode line

I have: (setq mode-line-end-spaces "string") That displays string in the mode-line. How can I get string in red there?
1
vote
1answer
103 views

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-...
0
votes
1answer
165 views

split-string: splitting on backslash character

I intend to apply the split-string function to the following string "\ghjky\dfsgi\45fdj\854f" using the character "\" as a separator in order to get the list ("ghjky" "dfsgi" "45fdj" "854f"). I ...
0
votes
1answer
33 views

Convert function-quoted form #'... to string

I have tried (symbol-name x), but it doesn't work if the argument is a lambda: ok: #'execute-extended-command not ok: #'(lambda (&optional frame) (interactive) (message "hi 8"))
0
votes
1answer
55 views

How to bind-pack list of null terminated strings?

According to the bindat spec docs, there are two specs to pack strings. They are str and strz. Both are for a fixed length string. Now, suppose I want to pack ("some" "list" "of" "string), I should ...
0
votes
1answer
59 views

Adding string to each item in list?

So simple question, i'm not sure which function would be best to do this. How do you add a string to each item in a list? So example: (setq list '("Sample Data" "More Fun")) And then say I want to ...
2
votes
2answers
241 views

How to get the position after matching and replacing a regular expression (replace-match)?

SHORT How to substitute (nicely) a regular expression by a string in pure elisp, like the unix command sed. LONG I'm using the function replace-match after string-match, but I can't get the right ...
2
votes
2answers
104 views

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

I am trying to enhance SQL mode such that editing of files of SQL code becomes more convenient, especially as far as jumping around is concerned (e.g. things like sql-goto-end-of-string etc.). I have ...
1
vote
0answers
42 views

Emacs freezes when using split-string in recursive function

I'm trying to figure out why my emacs keeps freezing when running this set of functions to split a string into a list of pairs. Is there some significant overhead happening when using string-split? Is ...
1
vote
1answer
191 views

re-search-forward Regex behavior for OR boolean

We usually use \| to depict OR in Regex. Using a\|b as input to Regexp I-search and Occur both gave the desired result. But re-search-forward seems unable to recognize this notation. abcdcba (re-...
0
votes
2answers
71 views

How to replace first 100 digits with letters?

I want to replace the first 104 digits as it follows: 1 --> a ... 26 --> z 27 --> aa ... 52 --> az 53 --> ba ... 104 --> bz I have tried as it follows: (...
0
votes
1answer
184 views

Unescape elisp string

I have a function which returns a file path, but the returned value has backslash excaped 'special' characters e.g. "/home/fred/Documents/This\ file\ \(20200120\).txt" but the function where I want ...
1
vote
2answers
124 views

How to compare an item against others, that's compatible with string-equal?

When comparing the last-command against multiple possible strings, it doesn't seem possible to use the member function. Is there a way to simplify this using something like member? (when (or (...
2
votes
1answer
139 views

Difference between (quote string) and "string"

Experiment on interative ielm ELISP> (print 'list) list list ELISP> (print "list") "list" "list" Any differences with the two results? by the way, one extra times printed.
5
votes
1answer
199 views

Set difference for sets of strings

Why the following in emacs-lisp works as expected: (set-difference '(1 2) '(1)) => (2) But if strings used it doesn't: (set-difference '("foo" "bar") '("foo")) => ("foo" "bar") How do can I ...
1
vote
1answer
499 views

Non-hex digit used for Unicode escape error when setting org-latex-classes

When I try to set org-latex-classes with the following code: (setq org-latex-classes '(("article" " \\documentclass[12pt,a4paper]{article} \usepackage{xeCJK} %\usepackage[heading]{...
2
votes
1answer
290 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
2k 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
55 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 ...
3
votes
3answers
567 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
141 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 ...
1
vote
2answers
97 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
60 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
764 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
213 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
100 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
195 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
44 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)) ...
1
vote
3answers
912 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
56 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
180 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:...