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
1 answer
19 views

Allowing user input for opening and closing brackets

The following code selects a string with two delimiters from the predefined list stored in delimiter-strings. The first delimiter being the opening bracketing mark, the second delimiter being the ...
user avatar
  • 159
0 votes
1 answer
31 views

Command that accepts a string and a selected region

Would like to have a function that selects a string (from a list or from a user-defined string, using the mini-buffer) and a selected region. User would input (), [], {} specifying the opening and ...
user avatar
  • 159
2 votes
1 answer
37 views

Fast character replacement table for strings?

Does Emacs have an API for creating a character translation table which can then be efficiently applied to strings? A data structure for example that can be created using a set of source & ...
user avatar
  • 7,059
0 votes
1 answer
53 views

Extract JSON from multi-line string, removing leading/trailing garbage

I am struggling to come up with a universal regexp that will remove/isolate all leading/trailing garbage from a multi-line string, leaving only the JSON. Without opening up a temporary buffer to re-...
user avatar
  • 17.6k
1 vote
1 answer
85 views

Does Emacs have a builtin way to fix curly quotes' orientation?

I am working on a package that makes an API call and gets strings with improperly oriented curly quotes, e. g., The word ’syneresis’ comes from Greek roots meaning ’take’ and ’together’. Is there a ...
user avatar
  • 715
1 vote
1 answer
56 views

How to fill a string programmatically like fill-region in elisp?

Here is what I want: (fill-string ";; This is a long string to be inserted into a buffer somewhere. Okay that's it.") This should insert line breaks according to the fill-column. Something ...
user avatar
  • 715
0 votes
1 answer
79 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 ...
user avatar
  • 169
0 votes
0 answers
31 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 ...
user avatar
  • 1
0 votes
1 answer
80 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)) "...
user avatar
0 votes
2 answers
52 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 ...
user avatar
0 votes
1 answer
106 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 ...
user avatar
  • 101
0 votes
1 answer
32 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. ...
user avatar
4 votes
1 answer
392 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-...
user avatar
  • 303
1 vote
1 answer
47 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) ...
user avatar
  • 231
2 votes
2 answers
68 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 ...
user avatar
  • 785
0 votes
1 answer
59 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' ...
user avatar
  • 1,481
2 votes
1 answer
68 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 ...
user avatar
1 vote
2 answers
94 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&...
user avatar
  • 7,059
2 votes
1 answer
441 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 ...
user avatar
  • 546
0 votes
0 answers
34 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"))) (...
user avatar
  • 635
0 votes
1 answer
27 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 "${...
user avatar
  • 635
1 vote
1 answer
49 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 ...
user avatar
0 votes
2 answers
135 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-...
user avatar
  • 635
4 votes
1 answer
1k 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 ...
user avatar
1 vote
2 answers
238 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?
user avatar
1 vote
1 answer
179 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-...
user avatar
0 votes
1 answer
268 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 ...
user avatar
0 votes
1 answer
35 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"))
user avatar
  • 620
0 votes
1 answer
60 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 ...
user avatar
  • 103
0 votes
1 answer
101 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 ...
user avatar
2 votes
2 answers
310 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 ...
user avatar
2 votes
2 answers
123 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 ...
user avatar
1 vote
0 answers
50 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 ...
user avatar
  • 303
1 vote
1 answer
308 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-...
user avatar
  • 635
0 votes
2 answers
82 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: (...
user avatar
0 votes
1 answer
306 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 ...
user avatar
  • 557
1 vote
2 answers
138 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 (...
user avatar
  • 7,059
2 votes
1 answer
192 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.
user avatar
  • 1,079
5 votes
1 answer
226 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 ...
user avatar
  • 1,073
1 vote
1 answer
668 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]{...
user avatar
  • 635
2 votes
1 answer
396 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/...
user avatar
8 votes
2 answers
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" ...
user avatar
1 vote
1 answer
61 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 ...
user avatar
  • 111
3 votes
3 answers
628 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" ...
user avatar
  • 131
0 votes
1 answer
255 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 ...
user avatar
  • 3,122
1 vote
2 answers
139 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 ...
user avatar
  • 483
1 vote
1 answer
61 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 ...
user avatar
0 votes
0 answers
817 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 ...
user avatar
0 votes
1 answer
309 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 ...
user avatar
0 votes
1 answer
262 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 ...
user avatar