Hot answers tagged

6

(You say "a region", not "the region", so a guess is that you do not really mean the Emacs region.) If your question is really about the Emacs region then the answer is no. Point (the cursor position) is always at one end of the region, and mark is always at the other end. See the Emacs manual, node Mark for more information. [I found that node by going to ...


4

Here is one possible way to implement this using a temporary buffer: (defun sort-string (string &optional reverse) "sorts an input string, using a temporary buffer" ;;(interactive "sto be sorted multiline string: ") (with-temp-buffer (insert string) (let ((beg (point-min)) (end (point-max))) (sort-lines reverse beg end) (...


4

The command mc/edit-ends-of-lines adds a cursor to the end of the every line in the region. There are many ways to set the region. If you want to mark every line in a file, you can set the region to the whole file with C-x h. It's very helpful to spend a few minutes reading the documentation for multiple cursors, which includes a list of all the different ...


3

The Org documentation says Many commands in Org work on the region if the region is active. And indeed defining a region followed by C-c C-t acts on all headlines in that region. Note that customizable variable org-loop-over-headlines-in-active-region must be set. A further way is to use the respective bulk agenda action. Possible steps are as follows:...


3

The first backspace kills the whole region. You'll want to set delete-active-region to nil (it was introduced in 24.1). delete-backward-char is an interactive compiled Lisp function in ‘simple.el’. [...] If Transient Mark mode is enabled, the mark is active, and N is 1, delete the text in the region and deactivate the mark instead. To disable this, set ...


3

If I understand your question correctly, you're looking for C-c RET which invokes TeX-insert-macro.


3

I'm not aware of a common way of dealing with such tasks. with-temp-buffer and buffer-string are nice general helpers here. (setq SORTED (with-temp-buffer (insert UNSORTED) (sort-lines nil (point-min) (point-max)) (buffer-string)))


2

Do you see the same behavior of not copying the text to the kill-ring if you start Emacs using emacs -Q (no init file?) I don't see it. That is, C-h k makes the whole buffer the region and activates the region. Then M-w copies that text to the kill-ring. The message you show is not a warning. It is simply a confirmation that that text was saved to the kill-...


2

You should not try to fontify the buffer yourself. I describe here a method that works in buffers with font-lock activated. Add the keywords with font-lock-add-keywords as long as you need them and remove them afterwards with font-lock-remove-keywords. After such actions you should invalidate the buffer fontification with font-lock-flush. This method has ...


2

You can do this with library Isearch+. As far as I know, this is the only library that offers this possibility. Set or bind option isearchp-restrict-to-region-flag to non-nil. This means that when the region is active and you start isearching the search will be limited to the region. Select the text between the upper-left and lower-right corners of the ...


1

Yes. Here are some ways. With just vanilla Emacs you can narrow the buffer to the text between your two "markers", using C-x n n. You need only one marker - the mark, at one end of that bit of text, and point (the cursor position) at the other end of that bit of text. With library Isearch+ you can just search the active region - no need to narrow the ...


1

To invoke a function, don't quote it: (kill-whole-line), not ('kill-whole-line). You're looking for function use-region-p, so (use-region-p), not region-selected. (There is no predefined variable region-selected.) You need to pass functions the arguments they require. So (kill-region (region-beginning) (region-end). If you want it to be a function then ...


1

Yes. See library Zones, in particular, function zz-do-zones or zz-map-zones. From the Commentary in zones.el, section Define Your Own Commands: Pretty much anything you can do with the Emacs region you can do with a set of zones (i.e., with a non-contiguous "region"). But existing Emacs commands that act on the region do not know about non-...


1

The easiest way I can think of is to use query-replace-regexp. That works if my-function takes the region as string and transforms it into the new string such as demonstrated with upcase in the following example. BTW, I do not know how long the texts in the question environment may be. Go to the beginning of the buffer and type M-C-% for query-replace-...


1

This code should do what you want: (setq your-variable (buffer-substring (region-beginning) (region-end))) If you want a command, try this: (defun my-set-var-to-selection (variable beg end) "Set VARIABLE to a string with the selected text. You are prompted for VARIABLE." (interactive (if (use-region-p) (list (intern (completing-read "...


1

I'm not sure if you can do this with rectangular regions, but it's a perfect situation for multiple cursors: Fundamentals of multiple-cursors https://github.com/magnars/multiple-cursors.el In your case, starting with point before foobar1, call M-x set rectangular-region-anchor, navigate to the next line until you have a point before every foobar. Then ...


1

Your question is unclear (to me). You say you want to "mark regex isearch results" (plural). But the code you show just marks the final result - final match when you exit Isearch. Is that what you want: just set the region around the final match, so you can use C-w or M-w on it? If so, what was wrong with this answer on the page of your first link? ...


1

AUCTeX provides Font-Specifiers that one can use for such environments as described in the question and which are used often. For instance the following code (add-to-list 'LaTeX-font-list '(?\C-q "\\underline{" "}")) will add underline to the list of font specifiers. This code must be called after LaTeX-font-list is defined. Then when you press C-c C-f C-...


1

Replace SOMETHING by 'font-lock-face '(:foreground "red") or 'face '(:foreground "red"). You want font-lock-face when font-locking is active, otherwise property face is correct. Please look at EmacsWiki Text Properties for more explanation.


Only top voted, non community-wiki answers of a minimum length are eligible