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
1 answer
61 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.
thanosapollo's user avatar
4 votes
2 answers
397 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”).
zeynel's user avatar
  • 371
0 votes
0 answers
24 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 ...
Adam Liter's user avatar
3 votes
1 answer
48 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 ".&...
dmw64's user avatar
  • 177
0 votes
1 answer
111 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 "...
rdrg109's user avatar
  • 408
1 vote
0 answers
36 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 ...
shynur's user avatar
  • 5,194
1 vote
1 answer
104 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 ...
Herman's user avatar
  • 27
0 votes
1 answer
63 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 ...
ideasman42's user avatar
  • 8,756
2 votes
2 answers
178 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 ...
tigerjack's user avatar
  • 163
0 votes
0 answers
41 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 ...
Garid's user avatar
  • 629
2 votes
1 answer
133 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 (...
shynur's user avatar
  • 5,194
-1 votes
1 answer
55 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?
VanDeiMin's user avatar
1 vote
1 answer
40 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. ...
shynur's user avatar
  • 5,194
0 votes
1 answer
51 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']&...
Orixi's user avatar
  • 5
1 vote
1 answer
115 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={...
Snelephant's user avatar
0 votes
1 answer
63 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 "...
Reverent Lapwing's user avatar
2 votes
3 answers
497 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) (...
orgtre's user avatar
  • 1,072
0 votes
1 answer
41 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 &...
user5954246's user avatar
2 votes
1 answer
280 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 ...
B. Pillet's user avatar
1 vote
1 answer
82 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, ...
Alessandro Bertulli's user avatar
0 votes
1 answer
87 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 ...
ideasman42's user avatar
  • 8,756
0 votes
2 answers
71 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 ...
Dilna's user avatar
  • 1
4 votes
2 answers
2k 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 ...
ocodo's user avatar
  • 1,222
1 vote
1 answer
60 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 &...
Arch Stanton's user avatar
  • 1,647
0 votes
1 answer
200 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 ...
holocronweaver's user avatar
0 votes
1 answer
28 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 ...
Dilna's user avatar
  • 1
0 votes
1 answer
57 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 ...
Dilna's user avatar
  • 1
2 votes
1 answer
100 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 & ...
ideasman42's user avatar
  • 8,756
0 votes
1 answer
138 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-...
lawlist's user avatar
  • 19.1k
2 votes
2 answers
263 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 ...
scribe's user avatar
  • 1,025
2 votes
1 answer
285 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 ...
scribe's user avatar
  • 1,025
0 votes
1 answer
217 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 ...
linuxfan's user avatar
  • 209
0 votes
0 answers
34 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 ...
Kafey's user avatar
  • 1
0 votes
1 answer
190 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)) "...
deepanshu's user avatar
  • 141
0 votes
2 answers
57 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 ...
Namudon'tdie's user avatar
0 votes
1 answer
367 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 ...
heinwol's user avatar
  • 101
0 votes
1 answer
58 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. ...
Guillaume's user avatar
  • 189
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-...
C11g's user avatar
  • 333
1 vote
1 answer
208 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) ...
Florian's user avatar
  • 241
2 votes
2 answers
336 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 ...
George's user avatar
  • 919
0 votes
1 answer
113 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' ...
kdb's user avatar
  • 1,561
2 votes
1 answer
106 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 ...
user1683620's user avatar
1 vote
2 answers
167 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&...
ideasman42's user avatar
  • 8,756
2 votes
1 answer
1k 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 ...
Ajned's user avatar
  • 734
0 votes
0 answers
38 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"))) (...
Sati's user avatar
  • 775
0 votes
1 answer
32 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 "${...
Sati's user avatar
  • 775
1 vote
1 answer
53 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 ...
randouser's user avatar
  • 111
0 votes
2 answers
236 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-...
Sati's user avatar
  • 775
4 votes
1 answer
2k 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 ...
Nicolas Rougier's user avatar
1 vote
2 answers
370 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?
Gabriele Nicolardi's user avatar