Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
22 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 ...
1
vote
3answers
47 views

Function that does `M-x replace-regexp` or `M-x occur` with a fixed pattern and replacement strings

I often use M-x replace-regexp and M-x occur with some fixed regexp pattern and replacement string on many files. Doing it manually by opening each file in an Emacs buffer and hitting the keys is ...
0
votes
1answer
27 views

How the get the text value of a complete value of a variable?

here a little example to explain my problem : How to get "marge" or ("marge") from oef-highlighted-variable ? oef-highlighted-variable #("marge" 0 5 (fontified nil face oef-font-variable-name-face)) ...
0
votes
3answers
66 views

How to concatenate a string and a list?

I would like to concatenate a string (e.g. "abc") and a list (e.g. '(aa bb)) so as to obtain "abc aa bb".
2
votes
1answer
17 views

repeat string-inflection command

I would like to repeat M-x string-inflection-camelcase on several words. For example in: foo_bar baz qux-quux quuz CORGE_GRAULT GARPLY I place my cursor on foo_bar and then enter M-x string-...
2
votes
1answer
70 views

Normalize string to make it file/path safe

Often I find my self doing this C-x C-f to create a file, while in the mini buffer prompt, paste a url like "https://github.com/seamusabshere/cache_method/issues/15" from the clipboard. Since "https:...
2
votes
0answers
40 views

Calculate current-column including display properties

I am trying to calculate the width of text within either a buffer or a string after it has been displayed, i.e. after taking into account the width of any display properties, such as embedded images, ...
4
votes
1answer
69 views

Width of string as if it were displayed

From the documentation of string-width string: This function returns the width in columns of the string string, if it were displayed in the current buffer and the selected window. For me this ...
2
votes
2answers
34 views

Arbitrary length lists as argument for interactive function

Say I have a defun with a dolist inside that I want to be able to pass a string that is then converted to a list with a length equal to the number of words in said string via the minibuffer, so ...
2
votes
1answer
65 views

Concat in Org Easy Templates [duplicate]

I have a variety of org easy templates. I have a new file template which includes a #+DATE header that I'd like to populate with the current date [at the time the template is called]. The ...
1
vote
3answers
79 views

Simple way to test if string contains float eg. “8.3”

I thought (defun string-integer-p (string) was cool, I found it in the emacswiki. Is there a variant of it I can use to test if string contains float eg. "8.3"
2
votes
0answers
22 views

Collapse xml-node-children from `xml.el` into a string

An API I have used for years (via an elisp package) recently started inserting formatting tags (particularly for <i></i> italics) into the 'ArticleTitle' field of entries. The assumption ...
1
vote
2answers
53 views

How can I use a char as a counter?

I have this LaTeX code: \begin{enumerate}[a] \affiliation{...} \affiliation{...} \affiliation{...} ... \affiliation{...} \end{enumerate} and, using a script written in Emacs Lisp, I want to ...
1
vote
1answer
76 views

Why do regexp that matches text in buffer does not (necessarily) match same text in string?

I have a regexp, org-parse-regexp which matches org items which I define to be a heading and a source block (actually, I include more stuff but I want to keep it simple). I've tested it using re-...
1
vote
2answers
50 views

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

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-...
0
votes
0answers
36 views

How can I get my target string point/marker without moving the pointer?

Lets say I have the following LaTeX code: \ref{AAA}, \ref{BBB} ... \ref{BBB,CCC,DDD} \begin{the bibliography}{99} \bibitem{AAA} \bibitem{BBB} and I want to write a function that does: (perform-...
2
votes
1answer
89 views

Interpolate environment variables in string

I am trying to write a function that will interpolate the enviroment variables stored in process-environment in a string. For example, if I have the string "This is $Foo and ${Bar}_none and '$skip'" ...
3
votes
3answers
116 views

Is there a way to autoindent single quoted lines automatically for python code?

The python.el mode has several ways to fill docstrings, but I would like to fill single quoted lines. Is there a function that would change this: variable = { 'key': ' this is a very long ...
1
vote
1answer
198 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 ...
7
votes
3answers
77 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 ...
2
votes
2answers
388 views

Split line every n characters

I have a long binary string that I would like to split every 32 characters. Is there a command that can do this for me? I have tried word wrapping, but it splits per word. It has no effect since a ...
0
votes
1answer
90 views

Expand variables before concat'ing them

I have (setq TeX-auto-local "subdir") (setq TeX-macro-private '("dir/")) I want to set TeX-auto-private to dir/subdir by joining TeX-auto-local and TeX-macro-private together. I thought it was easy ...
2
votes
2answers
73 views

What is the best way to search forward/backward for a token?

Sometimes I want to search for a specific word but I don't want to find words which have my search string as a substring. For example, if I search for "pan" (bread, in Spanish), I don't want to find ...
2
votes
2answers
62 views

Evaluate parts inside text-property string using read syntax?

I just discovered that it is possible to define strings with text properties using the special read syntax. Now I'm trying to evaluate a value of a property within the string definition so something ...
3
votes
2answers
1k views

How to wrap a single string literal across multiple lines?

Is it possible to write a single line for an Elisp string: "hello world" As: "hello world" Without inserting a newline character? (wrapping a string literal). I read that adding a tilde at the ...
1
vote
1answer
31 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?
1
vote
1answer
36 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 ...
0
votes
1answer
51 views

Passing a string with substitutions to the “perform-replace” command

I want to generalize this query-replace regexp: (perform-replace "Geophysical[\s\t\n]*Research[\s\t\n]*Letters" "Geophys.\\\\ Res.\\\\ Lett." t t nil 1 nil (point-...
1
vote
1answer
107 views

Get multibyte string byte

Given a multibyte string "x=π", how to get 4-th byte of the string, without creating string copy with something like string-as-unibyte? Pseudo code: (string-nth-byte 4 "x=π"). Expected result: 128. ...
1
vote
1answer
69 views

major-mode as argument to string-match vs string-equal

Why is (string-match "lisp" major-mode) not working, while (string-equal "lisp-interaction-mode" major-mode) is working? string-match results in debugger message: (wrong-type-argument stringp lisp-...
0
votes
1answer
39 views

buffer-file-name can return propertized text?

Once upon a time I was surprised to see buffer-file-name sometimes return propertized text like #("/tmp/foo" 1 4 (face flx-highlight-face)) instead of "/tmp/foo". I got in the habit of defensively "...
0
votes
1answer
435 views

How to programmatically surround a string with escaped double-quote

It seems that my question should be common knowledge, and I thought I knew it (at some point in the distant past), but the answer escapes me tonight. I'd like to take a string like "foo" and ...
0
votes
1answer
180 views

Using quail input-method to insert a string

The standard way to define an abbreviation using quail is as follows: (quail-define-rules ("a" ?s )) Inserting "a" gives "s". I am wondering if one can insert an arbitrary string using quail, I ...
1
vote
1answer
107 views

Single function to return file contents as a string

I'm wondering if there's a terse (i.e. single function) approach for reading a file's content given its path and returning it as a string. My go-to has been: (with-temp-buffer (insert-file-...
1
vote
3answers
32 views

How to know if user input a string or a number using interactive

I want to check if a user input a word or a number. And I write the function look like this: (defun check-input (arg) "description" (interactive "senter arg: ") (setq isnum (string-match "\\'[0-...
13
votes
1answer
1k views

How to strip decorations (text properties) from a string?

By a "decorated string" I mean something like #("foo" 0 4 (fontified t face font-lock-function-name-face)) ...as opposed to the "plain string" "foo" (If Elisp code reads a string directly from a ...
1
vote
0answers
20 views

Cperl font lock regions in here docs

I am having a problem in cperl-mode described in this question. Basically inserting a newline at the start of a line in here doc in cperl-mode is breaking the syntax highlighting. One of the answers ...
1
vote
1answer
112 views

Building a list of strings with a regexp while loop

I'd like to perform a regexp search, capture part of a matched string, and save that part to a list. (Eventually the plan is to save this list to a file in a particular format, but for now a simple ...
1
vote
1answer
56 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 ...
0
votes
0answers
62 views

Get emacs to read unquoted strings in json

I am trying to use emacs-lisp to interact with a MongoDB. Here is an example of a string that mongo returns, that emacs cannot read. The problem is the unquoted ObjectId and ISODate items (if I put ...
0
votes
1answer
47 views

Why is “*\\Completions\\*” formatting used when specifying buffer names for display-buffer-alist?

From GNU Emacs Manual: 20.6.2: If you prefer Emacs to display a temporary buffer in a different fashion, we recommend to customize the variable display-buffer-alist (see Choosing a Window for ...
1
vote
1answer
74 views

Check if buffername is equal to file name

I'm trying to autoexport a file from orgmode to html, so I decided to make a function to check the major mode of the buffer and check if the buffer has open the file that I want to export but when I ...
0
votes
1answer
55 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="...
4
votes
1answer
137 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 ...
6
votes
3answers
778 views

How to check if a given string is a substring of an element of a list

According to documentation, member checks if a a given element is an element of a list. For example if the list, say my_list consists of apple and orange, (member "apple" my_list) returns true. Is ...
0
votes
1answer
26 views

string-match matches buffer contents, instead of argument string

I am trying to parse file permissions using string-match. My code is, (setq fmode (nth 8 (file-attributes "/Users/sk/a.js"))) (message "file mode is as, - %s" fmode) (string-match "^.\\(...\\)\\(...\\...
4
votes
0answers
57 views

truncate-string-to-width doesn't pad/print the string, as documented

I am referring the documentation for truncate-string-to-width from here. It says, (truncate-string-to-width "\tab\t" 12 4) will output, ab But what i get in my machine (emacs versioned 25.1.50.1)...
0
votes
1answer
67 views

Return nth line from (current) buffer

I want to get the first line of the buffer I'm actually in. More generally, I'm looking for a utility that returns Nth line from a supplied buffer. Is there some built-in for that?
1
vote
0answers
255 views

In Emacs Lisp, how to convert roman numerals to an integer?

In Emacs Lisp, how to write an Emacs Lisp function to convert a natural number from roman numerals representation to the equivalent Emacs Lisp integer value? The Emacs Lisp function should be callable ...
0
votes
2answers
451 views

elisp trying to double backslashes in windows pathname - concat strips a slash escape

I'm trying to insert a string pathname into a buffer on a Windows machine. The variable holding the string has the right number of backslashes (two) in the directory pathname. I know this because when ...