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
387 views

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 10.10.10.10 bla bla bla") (string-match "[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+" test-string) (message (match-string 0 ...
Russ Kiselev's user avatar
1 vote
1 answer
512 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-...
Sati's user avatar
  • 775
2 votes
1 answer
286 views

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 configuration.org 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
590 views

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
356 views

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
13k views

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
557 views

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
3k views

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
330 views

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
997 views

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
258 views

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
92 views

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

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
131 views

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
468 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
2 votes
1 answer
279 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
1 vote
2 answers
369 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
1 vote
2 answers
135 views

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
97 views

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