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.
162 questions
1
vote
1
answer
73
views
Elisp double quotes vs single quote
What's the difference between these two?
(setq foo "bar")
(setq foo 'bar)
0
votes
1
answer
32
views
Using path to lisp implementation that contains spaces with SLIME and inferior-lisp-program
I'm trying to setup a common lisp environment because I wanted to start learning it but been having some trouble setting it up. I noticed that spaces were the problem when I used debug-on-error and ...
1
vote
1
answer
112
views
Change quote type inside of LaTeX environment in Doom Emacs
I am using Doom Emacs on Windows. I prepare documents in LaTeX and have AUCTeX installed. I am using the minted package and would like doom emacs to simply insert a simple double quote to denote ...
0
votes
0
answers
35
views
How can I decorate org-mode quotes from `.emacs`, not per file?
In programming modes anything between quotation marks can be made to use a specific face by a simple switch.
(global-font-lock-mode t)
This is so nice to have that I'd like to duplicate it in org-...
0
votes
2
answers
97
views
How to remove trailing space from string and preserve faces
I have a string that can contain trailing spaces.
For instance hello, I have spaces
I wrote the following function to remove said spaces:
(defun filter-last-spaces (text)
(let*
(
...
0
votes
1
answer
45
views
How can I transform the evil-ex-history variable to enable the extraction of search and replace strings using mapcar?
When I try to use a mapcar to extract the strings like (mapcar 'car evil-ex-history) it creates an error because of the # character preceding the list.
Copying the expression, deleting the # character ...
0
votes
1
answer
246
views
How can I test for a null byte?
Windows 7,
emacs 29.1
Is there a way to tell emacs to test for a null without entering a null in elisp?
Putting a null anywhere in my elisp produces "Error: End of file during parsing".
...
1
vote
1
answer
333
views
How would you remove all emojis from string?
Basically what the title says, I'm looking for the best way to remove all emojis from a string.
4
votes
2
answers
609
views
Filter a list of strings to create a separate list of those that match a given prefix
If I have a list, (“apple” “pear” “grape” “apricot”) how do I create a new list with elements starting with the letter “a”? The new list will be: (“apple” “apricot”).
0
votes
0
answers
28
views
How to programmatically set the same flag for multiple transient-values? [duplicate]
How can I programmatically set the same argument (e.g., --gpg-sign=abc123) for multiple transient-values? If I try the following, it seems that the value of adamliter/my-gpg-key-sign-git-arg does not ...
3
votes
1
answer
115
views
Strange behaviour involving `display` property
I noticed a rather peculiar behavior when using the display property (using emacs 28.2). I tried to boil things down to a minimal example: The code
(defun finsert ()
(insert (propertize ".&...
1
vote
2
answers
304
views
replace nth-match of a regexp in a string
I'm looking for a function that can replace the nth-match in a string.
Here's an example. 2 is the index of the nth-match, [0-9]+ is the regular expression to search. foo is the replacement and "...
1
vote
0
answers
64
views
print hex-code in string
I hope "*ielm*"/eval-print-last-sexp print "\x80", but the result is
ELISP> "😅\x80"
"😅\200" ; Unicode characters should be displayed normally.
My current ...
1
vote
1
answer
158
views
How to return "string" after changing it's text properties?
When using the propertize function alone on an entire string, it works. How to return a string, after changing its different sections separately with add-face-text-property (probably later repeatedly ...
0
votes
1
answer
150
views
Is there a literal-string version of "looking-at"?
The function looking-at matches a regex, in some cases however I want to match against a literal string. While (looking-at (regexp-quote text)) works, it seems like there might be a way to do this ...
2
votes
2
answers
248
views
Marking as safe all possible lists of strings
Following this answer, I put the following lines in a .dir-locals.el file:
((latex-mode
(TeX-engine . default)
(mode . latex )
(TeX-master . "main")
(ispell-buffer-session-localwords
...
0
votes
0
answers
44
views
How to split org-roam-capture-templates in to multiple lines? [duplicate]
I have following config for my org-roam:
(use-package org-roam
:ensure t
:init
(setq org-roam-v2-ack t)
:custom
(org-roam-directory "~/roamnotes")
(org-roam-completion-everywhere ...
3
votes
1
answer
174
views
Face Text Property: void, nil, default
A string may hold a nil or default face text property, or its face text property is simply unspecified.
E.g.,
#("void nil default"
0 4 ; unspecified
()
5 8 ; nil face (...
-1
votes
1
answer
66
views
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?
1
vote
1
answer
52
views
String’s Elements Occupy 1/4 Space of Vector’s
In the GNU Emacs Lisp Reference Manual, 6.2 Arrays:
In practice, we always choose strings for such applications, for four reasons:
They occupy one-fourth the space of a vector of the same elements.
...
0
votes
1
answer
75
views
Why is my simple use of shell-command to change a global keybinding in Linux not working?
I want to be able to change a global keybinding by calling an Emacs function.
The command in question is:
gsettings set org.gnome.desktop.wm.keybindings switch-applications "['<Super>Tab']&...
1
vote
1
answer
236
views
Org mode agenda custom command that can match on one of multiple property values
The "Advanced Search" Org mode tutorial on Worg provides the following example to find all entries with either "Walter" or "Evensong" in the author field:
BIB_TITLE={...
0
votes
1
answer
102
views
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 "...
4
votes
3
answers
1k
views
How can I check whether a string represents a number in Elisp?
I want to check whether the string variable s is a number (integer or float) formatted as a string. I thought it could be done using string-to-number like this
(defun string-number-base-p (s)
(...
0
votes
1
answer
99
views
Why doesn't stringp evaluate the expression in this case?
I'm relatively new to Elisp and I'm trying to figure out a bug in my code, but I have no idea what to search or read in order to get an idea about it.
The bug is in this code:
(defvar some-variable &...
2
votes
1
answer
557
views
How can I construct a bash-safe filename from a string?
I want to generate very simple filenames from complex strings during a org-capture.
For instance the string
"Une idée nouvelle pour calculer $\\int_0^{\\infty} e^{-t^2} \\dd t$"
Should be ...
1
vote
1
answer
126
views
How to copy and modify a single line from a buffer?
I want to write a function that copies the current line from a buffer, but transforms it before in certain way. Specifically, I need to generate file names depending from lines of code. For example, ...
0
votes
1
answer
209
views
How to replace the region text with the text of a string, without deleting and reinserting parts that are the same
In a few functions I've written logic that does the following:
(defun replace-in-region (str beg end)
"Replace the region between BEG & END with STR."
(save-excursion
(goto-char ...
0
votes
2
answers
102
views
Interactive selection with hex codes
I want a function that can take a utf hexcode from the user, and use it to change the glasses-separator in glasses-mode. When I use completing-read using a list of hexcodes things for well and the ...
5
votes
2
answers
3k
views
Emacs 29 docstring single quote escaping rules, compiler level event?
I've seen the following warning from the Emacs 29 compiler:
In s-format:
s.el:614:2: Warning: docstring has wrong usage of unescaped single quotes (use
\= or different quoting)
I haven't been ...
2
votes
1
answer
97
views
How to preselect initial text in the minibuffer with Elisp?
I'm using read-string to read a string from the minibuffer, with an initial input. How can I highlight the initial input, so that I can start replacing it with one key stroke? IOW, given (read-string &...
0
votes
1
answer
413
views
How to convert string to ascii or unicode hex?
I somewhat routinely need to convert an arbitrarily long string to hex, usually encoded as ascii or unicode.
Is there a way to quickly and easily do this using vanilla Emacs? If not, is there a go to ...
0
votes
1
answer
40
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 ...
0
votes
1
answer
87
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 ...
2
votes
1
answer
138
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 & ...
0
votes
1
answer
210
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-...
2
votes
2
answers
408
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 ...
2
votes
1
answer
456
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 ...
0
votes
1
answer
293
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
0
answers
41
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
1
answer
256
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
2
answers
82
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
1
answer
714
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
1
answer
106
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.
...
6
votes
1
answer
2k
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-...
1
vote
1
answer
344
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
2
answers
522
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
1
answer
170
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
1
answer
146
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
2
answers
250
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&...