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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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.

2
votes
1answer
37 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
63 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
15 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
50 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
70 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
40 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
35 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
49 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
83 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
153 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
74 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
269 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
65 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
66 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
59 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 ...
2
votes
2answers
595 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
25 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
28 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
42 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
94 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
55 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
38 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
299 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
153 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
93 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
31 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-...
12
votes
1answer
877 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
99 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
52 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
55 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
37 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
62 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
48 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
120 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
671 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
24 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 "^.\\(...\\)\\(...\\...
3
votes
0answers
48 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
64 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
225 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
370 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 ...
3
votes
1answer
345 views

Regular expression matching group replacement not working

I want to convert .waitForVisible('.someselector') .click(); Into: .waitAndClick('.someselector'); Automatically in a lot of files. So I wrote: (defun hhaamm-replace-regexp-in-buffer (from to) (...
2
votes
1answer
65 views

Match regexp groups or entire text

According to match-string help: Value is nil if NUMth pair didn't match In fact: (string-match "\\(hullo\\)" "hello") (match-string 1 "hello") gives nil Also, a NUM Zero means the entire ...
1
vote
1answer
203 views

Regex Quantifier not working in string-match

All the documentation I can find says this should be returning the index of the first of the three x's but instead it returns nil: (string-match "x\{3\}" "string with 3 x's repeating: xxx") update: ...
1
vote
1answer
124 views

syntax-highlighting strings incorrectly for strings in opascal-mode

I write my projects in FreePascal and use opascal-mode to write it. I'm having a problem that this mode thinks that '\' is not a complete string, and hence all code after it is highlighted as a string....
1
vote
1answer
118 views

Is there a string manipulation difference between Emacs 24 and 25.1?

I'm test-driving Emacs 25.1 and have noticed that a simple concat command, which used to work in v.24 (and v.23), doesn't work in v.25.1: (setq yas-snippet-dirs (concat user-emacs-directory "snippets"...
3
votes
2answers
151 views

How to split the output of a `printenv` shell command?

Basically, I want to split a multiline string at the regular expression that, in Perl, would be specified with \n(?=[^\W\d]\w*=). Note that the Perl regexp features a "zero-width lookahead match" ((?=...
0
votes
1answer
28 views

How to get the first N words of an org file's main body

Given an org-mode file like this #+TITLE: My title #+AUTHOR: Me Myself First and so on words sixth this we don't want How can I get the first N words of the main body? So for N=5, I would like to ...
2
votes
1answer
120 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) ) ...
0
votes
1answer
26 views

Strip arbitrary characters from a string?

Q: How can I strip non-word characters from a string? For an arbitrary string, how do I strip all characters with non-word syntax? Alternately, using a regexp, how do I strip out the non-alphabetic ...