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
1answer
47 views

Difference between (quote string) and “string”

Experiment on interative ielm ELISP> (print 'list) list list ELISP> (print "list") "list" "list" Any differences with the two results? by the way, one extra times printed.
1
vote
3answers
109 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"
1
vote
3answers
76 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 ...
1
vote
1answer
62 views

How to know output type

I've got this code: (defun insert-random-uuid () (interactive) (shell-command "uuidgen" t)) which produces a uuid that looks like this ffc715d2-1e10-4faf-b1f6-f85cae88a7d7. However, I believe it'...
1
vote
1answer
137 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"...
1
vote
1answer
45 views

how to convert “foobar?” into 'foobar?

I'm trying to turn a string containing a question mark into the corresponding symbol but: (intern "foobar?") returns 'foobar\? How can i do the same thing without the backslash? Also i'm interested ...
1
vote
2answers
85 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-...
1
vote
1answer
96 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
201 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
101 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 ...
1
vote
1answer
39 views

Break a long string in a concatenation of shorter ones

Is there a predefined way to split "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud ...
1
vote
1answer
55 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
107 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-...
1
vote
1answer
133 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
74 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 ...
1
vote
1answer
172 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
63 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 ...
1
vote
1answer
75 views

Elisp: How to accumulate function return into a list

I have this small snippet of Elisp code that decodes kernel traces: (defvar projbase "/my/proj/base") (setq my_shell_output (substring (shell-command-to-string (concat "/home/demetra/scripts/...
1
vote
1answer
149 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
1answer
144 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
127 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 ...
1
vote
1answer
38 views

Non-hex digit used for Unicode escape error when setting org-latex-classes

When I try to set org-latex-classes with the following code: (setq org-latex-classes '(("article" " \\documentclass[12pt,a4paper]{article} \usepackage{xeCJK} %\usepackage[heading]{...
1
vote
3answers
36 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-...
1
vote
0answers
22 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
456 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: ...
0
votes
3answers
174 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".
0
votes
2answers
49 views

Sort lines in a string

Given I have a string that maybe came from a buffer, or a clipboard, or wherever; how do I sort-lines in it? Given that sort-lines only works with a region, I assume I have to put it to a temporary ...
0
votes
1answer
81 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?
0
votes
1answer
821 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
57 views

Search for occurrence of character within a string without using the common lisp library?

I need to extract certain information from buffer names, and I'm doing so by extracting substrings based on the position of unique characters within a buffer name string. So, I currently am doing ...
0
votes
1answer
77 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="...
0
votes
2answers
646 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 ...
0
votes
1answer
32 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 ...
0
votes
1answer
30 views

Check if a character is in a string

It is easy to present list of allowed characters as string, like " \n\t". (char-before) return integer. How can I check that a character is in a string? There is What is the easiest way to check if ...
0
votes
1answer
35 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 ...
0
votes
1answer
36 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
1answer
139 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 ...
0
votes
1answer
47 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
69 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 ...
0
votes
1answer
32 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 "^.\\(...\\)\\(...\\...
0
votes
1answer
29 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 ...
0
votes
0answers
318 views

Format strings for org-agenda-prefix-format

I want to customize org-agenda-prefix-format but am unable to find something in the reference explaining the syntax and the format strings I can use. The manual simply states: You can also ...
0
votes
0answers
45 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-...
0
votes
0answers
68 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 ...