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
3 answers

Elisp regex matching - evaluate as region vs as individual sexp gives different answers

Here's a chunk of code: (defvar test-string "bla bla bla bla bla bla") (string-match "[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+" test-string) (message (match-string 0 ...
Russ Kiselev's user avatar
1 vote
1 answer

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-...
Sati's user avatar
  • 775
2 votes
1 answer

How to use ,var-name (defvar) syntax in org-publish-project-alist? Init file is in form of org-mode

I have following function as part of my emacs settings for publishing org to html. (defvar website-html-preamble "<nav> <ul class="nav nav-tabs"> <li role="...
Rahuketu86's user avatar
9 votes
4 answers

Which keyboard shortcut to use for navigating out of a string

When I'm in the middle of a looooong string, like the following (setq Emacs-beta "Which keyboard shortcut to use for navigating out of a string") Can I skip out of it, just before the first " (after ...
Dieter.Wilhelm's user avatar
1 vote
2 answers

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

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-...
Aquaactress's user avatar
  • 1,443
38 votes
3 answers

How to check in elisp if a string is a substring of another string?

How to check if a string s1 is a substring of another string s2? For example (test-substring "f t" "df tj") --> t, (test-substring "ft" "df tj") --> nil.
Name's user avatar
  • 7,809
12 votes
2 answers

How do i get rid of "default" (last used) string in some emacs functions?

I have the following problem : when i use 'C-x r t' (string-rectangle), i am prompted to enter some string, to replace the selected rectangle. Lets say i type ";;" (to comment out the rectangle). This ...
mation's user avatar
  • 121
9 votes
2 answers

How can I turn a string into its literal representation?

(mystery-function "a neat\nstring\"") => "\"a neat \\nstring\\\"" This question was asked on freenode#emacs by user dropdrive. How could I write (or use) a function that takes a string literal ...
Sean Allred's user avatar
  • 6,901
8 votes
3 answers

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 ...
Dan's user avatar
  • 32.9k
4 votes
1 answer

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 allows ...
kdb's user avatar
  • 1,561
3 votes
1 answer

modify syntax table for strings in perl modes

My company uses a version of Perl where you can define by binary number using something like my $var = 'b010110110; etc. Problem is both perl-mode and cperl-mode interpret ' as the start of the string ...
Prgrm.celeritas's user avatar
3 votes
1 answer

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 ...
Gabriele Nicolardi's user avatar
2 votes
1 answer

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
2 votes
1 answer

how to parameterize prompt for interactive/command?

background I had elisp code (in this very small git repo) like (defun bulk-replace-file (filepath) (interactive "FPath to file to bulk-replace: ") (bulk-replace-file-non-interactive filepath) ) ...
TomRoche's user avatar
  • 622
2 votes
1 answer

How to get the string representation of a keymap event?

I'd like to get the string representation of a keymap event. For instance 19 should be printed as C-s, 1 as C-a etc... I could make my own function to do that but since describe-keyis capable of ...
syl20bnr's user avatar
  • 2,095
2 votes
3 answers

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
2 votes
1 answer

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
1 vote
2 answers

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
1 vote
2 answers

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 ...
Prgrm.celeritas's user avatar
1 vote
1 answer

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?
Evan Aad's user avatar
  • 1,521