Questions tagged [replace]

Replacing is the action of searching a string for a sub-string and replacing it with a different string.

Filter by
Sorted by
Tagged with
1
vote
2answers
179 views

Package cl is deprecated, is there any easy fix for it?

For the warning of Package cl is deprecated is there any easy fix for it? Here is a piece of code I copied from somewhere (that I don't know how to fix): (eval-when-compile (require 'cl)) (defun ...
1
vote
1answer
47 views

How to dynamically replace certain text, by evaluating a function on change in current buffer

I am trying to figure out how to use window-change-functions refer here for official documentation to be able to run a function to replace certain text within the current buffer at every change of the ...
0
votes
1answer
71 views

frame-background-mode leads `Args out of range: #<buffer doo.py>, 0, 1` error

I am using following answer to search and replace a word in the entire buffer: (defun query-replace-region-or-from-top () "If marked, query-replace for the region, else for the whole buffer (...
0
votes
1answer
26 views

Replacing with context information

When writing latex sometimes I reuse old documents that use the siunitx package and use the \SI command. Then I often want to include the calculations via pythontex and replace (in a region) \SI with ...
0
votes
1answer
24 views

How can I fix my re-replace-region function in which match data gets clobbered?

I have an ancient function I've been using for decades which performs a regexp replacement in a region: (defun re-replace-region (begin end old new) "Replace occurrences of REGEXP with TO-STRING ...
0
votes
2answers
42 views

Pass selected text as argument to a script and replace selected text with output from the script

I'd like to pass some selected text in a buffer to a python script. The python script will process the string and print the result to stdout. This output should replace the original string that was ...
3
votes
1answer
43 views

Equivalent of query-replace-regexp for multiple regexps

How can I do the equivalent of query-replace-regexp for multiple regexps? For instance, if regexp1 is matched, it should be replaced by text1, and if regexp2 is matched, it should be replaced by text2 ...
2
votes
1answer
39 views

Modify the first element of the kill-ring

I have stored in my clipboard a path to an image, which I want to paste inside emacs. I would like to modify the path to change/postpone/prepone some stuff before yanking. Following my previous ...
3
votes
1answer
87 views

Beginner - Correct usage of elisp conditionals and when: Improving code readability for org export

I am exporting from org mode format to LaTeX and HTML formats. To tweak a little plain text in those formats, I am using filter functions. If I try to use such a form of a filter function: (defun ...
1
vote
1answer
24 views

Why does the prompt remain even if I quit my command?

I'm trying to write a function that should allow me to conditionally choose how to replace a regexp. E.g. if I have the string "A. Z" I'd like to choose if replace it with "A@. Z" ...
0
votes
0answers
19 views

Preserving evil mode search/replace command history

In evil mode, I use a lot of search/replace with %s/pattern/replacement. I have (evil-select-search-module 'evil-search-module 'evil-search) in my ~/.emacs file. However, some of the past search/...
1
vote
1answer
47 views

How to select and replace the content of all specific org-headings?

I am trying to select each content-heading extracted with org-noter and then remove all erroneous newlines. This is my function. (defun sanitize-noter-import () "Sanitizes org-noter imports. ...
0
votes
1answer
32 views

How to modify text that's yanked?

I copy text from websites and paste/yank into emacs buffers. But this text sometimes has silent hyphens in them. The behaviour when copying and pasting text with soft hyphens in it varies across ...
2
votes
1answer
51 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 ...
1
vote
1answer
71 views

function to search and replace multiple words - necessary to goto-line 1 every time?

This is a very rudimentary question, but I have a document in which I need to replace many different words fairly frequently, so I created a function that goes like this: (defun chikan () (...
0
votes
1answer
58 views

Replace expressions including variable text

I wish to create a function to put in my .emacs (but I am no Elisp expert) in order to perform a certain number of replacements within an Emacs buffer. In particular, I want to: replace any ...
1
vote
1answer
97 views

remove “-” (soft hyphen) between words

When I try to paste a text from a web page inside Emacs I get this "-" between words. Here is one example: Is there a way to get rid of this (don't know the term..) ? Aus Sicht vie­ler ...
2
votes
3answers
227 views

Find/replace all files in a directory? (recursively)

One task I still end up using an IDE for is project wide find-replace. The steps are as follows. Select a directory to replace in(this could default to the projects root). Select the file extensions ...
0
votes
1answer
139 views

replace-regexp-in-string: How to prepend a string to the entire string matched?

I am adding divider lines to certain sections of the reports generated by the binary ledger [ https://www.ledger-cli.org/ ] through the function ledger-do-report in the ledger-mode Lisp library [ ...
1
vote
0answers
54 views

How to replace a block of text with a “query-like” approach all at once?

I want to search and replace a block of text with a "query-like" approach all at once. For example, if I have \emph{``Foo $\bar$ baz''} to be replaced by \emph{Foo $\bar$ baz} using a &...
1
vote
1answer
46 views

How can I get the search string from incremental regexp search to use with replace regexp

If I want to do a replace-regexp I usually start with a isearch-forward-regexp so I can get immediate visual feedback on the search string. From there I'd like to grab the search string for using in ...
0
votes
2answers
129 views

How do I search/replace with case sensitive search?

In emacs I'm using M-% to replace occurrences of b_abcd (of which there are only a few) with B_abcd (of which there are very many). Currently Emacs asks if it's OK to replace at each B_abcd, which ...
0
votes
1answer
94 views

Regex to replace subset of repeated pattern

ABC、DEF, GHI, JKL、MNO PQR、STU, VWX、YZ How do I replace all , s with 、 in the repeated pattern above? The repeated pattern can be mapped with the regex below: "^\\([A-Z]+、\\)\\(\\([A-Z]+\\), \\)+&...
1
vote
1answer
32 views

Decode double-back-slashes-prefixed octal codes in 'utf-8

I have a string "\\303\\273" that I want to decode into û. It's known that (decode-coding-string "\303\273" 'utf-8) evals to û. However, I'm not able to translate "\\303\\273&...
1
vote
1answer
89 views

Remove multiple blank lines in a buffer, leave one

I'd like to take a buffer which looks like this: one two three four five And turn it into this one two three four five I've tried using delete-blank-line, however, it will only effect the area ...
0
votes
0answers
15 views

How to use projectile-replace only for specific wildcard such as Python?

From this answer, I am using projectile-replace to replace words within a folder. It works fine but it covers all the buffers. I was able to accomplish it it using find-dired: (defun my-find-files () ...
1
vote
1answer
27 views

icicles search and replace; need help to do a successfull replace

I try to use Icicles to search and replace. I understand to search with it (some details, that I need), but I'm unable to do a replace. The link below shows a recipe, that I try to follow, but it ...
0
votes
1answer
42 views

How to replace a letter with its numerical alphabetic position?

I have this code: \author[p]{...} \author[bc]{...} \author[p]{...} \author[l,o]{...} \author[t,q]{...} \author[at]{...} \author[z]{...} \author[ak]{...} \author[az]{...} \author[ah,bq]{...} ... I ...
0
votes
1answer
54 views

Programmatically find-and-replace custom sequence

I need to write a command which will apply to my buffer custom, predefined copy-and-replace sequence. What I have is: (defun custom-processor () "Formats logs to human-readable format" ((replace-...
0
votes
1answer
64 views

How to set a variable that matches different type of strings?

I have these strings: First Type: arXiv:1234.56789 arXiv:1234.56789v1 Second type: hep-th/123456789 hep-th.AB/12345689 hep-th/123456789v1 hep-th.AB/12345689 Belong to the second type even strings ...
0
votes
0answers
43 views

error in process sentinel: Invalid file-name during replacing words

I am getting following error error in process sentinel: Invalid file-name due to generated _flymake.py files, when I am following approach for the recursively find and replace in text files not ...
0
votes
2answers
247 views

Replace string in rectangular region?

When you select a region normally, you can do a replace-string on only that region. It would be very useful to select a rectangular region (via C-x SPC), and be able to replace-string on only that ...
2
votes
1answer
63 views

Query replace regexp with a distant match?

I have a single transcript file for a set of course lectures I am watching. After doing some formatting on the file. I have it broken up into sets of lessons where the main heading is the lesson title ...
2
votes
1answer
74 views

How to add a suffix to the end of a string in a line?

Here's an example of content in a file This_is_line_1 : 1 This_is_another_line :2 This_is_3rd_line :3 Here_is_line_4 :4 So, how can using emacs to add char @ immediately to the end 1 string ...
0
votes
2answers
66 views

How to replace first 100 digits with letters?

I want to replace the first 104 digits as it follows: 1 --> a ... 26 --> z 27 --> aa ... 52 --> az 53 --> ba ... 104 --> bz I have tried as it follows: (...
0
votes
0answers
52 views

How to replace a LaTex macro with its argument?

I want to replace a macro with its argument, that's to say, if I have \newcommand{\foo}{FOO} I want to replace every occurence of \foo with its argument FOO in a specified region. I am trying to ...
0
votes
1answer
86 views

need help with very complex find and replace

I have a very complex (at least to my mind) text replacement task. ideally this would be a function or macro I could run over every org header in a buffer. I want to 1. move over any TODO state to a ...
1
vote
1answer
730 views

Search/replace and replace within a block of selected text of buffer in spacemacs

As stated in the title, I want to search and edit (including replace) certain strings in a selected part of a buffer, not the entire buffer!!!, how can I do it? Are there any built-in keystrokes?
0
votes
1answer
509 views

Replace full-width numerals with half-width numerals

I'd like to convert numerals from half-width to full-width characters with a simple regex search and replace as follows: replace-regexp-in-string regexp rep string &optional fixedcase literal ...
0
votes
2answers
76 views

Replace a block of code with another

How can I replace a block of code with another, akin to query-replace/query-replace-regexp? For example: Replacing the following block: for(A) { if(B) { s1; } else { C; } } with ...
0
votes
3answers
133 views

Complex searching and replacing [duplicate]

Suppose I have following pattern: throw "some message"; which I'd like to replace with: throw new Error("some message"); So, "some message" part should not be changed (or copied as is), and ...
2
votes
2answers
475 views

Selecting next occurrence of word incrementally

I want to make changes inside a paragraph of a large text file. If I have the cursor at the word "foo", what key combination would get the cursor at the next occurrences of this word? The cursor ...
0
votes
1answer
44 views

How to call `replace-string` with specific strings from code?

Sometimes I want to replace [$] with \( and [/$] with \) either in the region or in the whole buffer. replace-string works well for that, except for requiring me to type the strings I want to replace. ...
1
vote
1answer
155 views

Regex: Don't Match Text Between Curly Braces (LaTeX Commands)

I've been using pandoc and emacs to convert beamer presentations to markdown format. In the beamer presentations we highlighted certain code in example code blocks red. Pandoc has left me to get rid ...
1
vote
1answer
178 views

How to paste a multiline regex from re-builder into `replace-regexp`

I built with M-x re-builder a regex to match empty quoted lines in emails. In read syntax it is: "^>\\s-*\n>" How can I copy this regex in re-builder, so that I can paste it in the first ...
1
vote
1answer
140 views

csv-mode: do not split line on newline inside quoted field

I'm using the latest csv-mode in Emacs 25.3.1 in centos 6.10. The problem is that I have many fields that are long documentation strings and many of them have embedded newlines. This messed up csv-...
3
votes
1answer
217 views

Search and replace two consecutive newlines

Running spacemacs 0.200. I am sorry if it is too basic. But I am just not able to get this. How do I convert two consecutive newlines with some text, say, 'there were two newlines here'? I could ...
0
votes
0answers
37 views

replace char at position using Emacs script

Below script will insert a char at position: #!/usr/bin/env emacs --script (defun modify(filename) (find-file-literally filename) (goto-char 3) (insert "\x39") (save-buffer 0) (kill-buffer)...
0
votes
2answers
299 views

Using Occur to to recursively search in a directory [duplicate]

I use 'occur' to search for regexp in current buffer and edit the results in occur buffer . Now my requirement is to search all the files in a directory(including sub-directories ) and edit the ...
3
votes
2answers
1k views

Emacs replace-regexp reference the match in the replace argument

Is there an easy way to use replace-regexp to do something like: XYZ001 XYZ002 XYZ003 to 'XYZ001' 'XYZ002' 'XYZ003' i.e. replace-regexp XYZ* 'XYZ*' Is replace-regexp the the wrong tool for the ...