7

Here's one approach: (defun isearch-exit-mark-match () "Exit isearch and mark the current match." (interactive) (isearch-exit) (push-mark isearch-other-end) (activate-mark)) (define-key isearch-mode-map (kbd "<C-return>") #'isearch-exit-mark-match) This binds a different key (C-return) to exit the current isearch and also leave the last ...


6

avy already supports what you want. See avy-dispatch-alist. However, the default actions are not enough. I have the following function in my config (here it copies a sexp, but you can change it to copy a line): (defun my-avy-action-copy-and-yank (pt) "Copy and yank sexp starting on PT." (avy-action-copy pt) (yank)) Then assign a key to the function ...


5

Actually for org-table-copy-region it isn't necessary to mark the exact column width! Just mark the beginning of the column somewhere in a cell, then the end by going down the required number of rows and do C-c C-x M-w (for M-x o-t-c-r). Then go to another cell, where you want to add the column and do C-c C-x C-y (for M-x org-table-paste-rectangle).


5

Hopefully StarBug gave you an answer to your literal question about stuff between newlines. Your clarification suggests that you are actually looking for org-element-context. That function gives you the org element at point which can be a source block. The returned element has properties like its bounds (:begin and :end) and its contents (:value). The ...


4

Two rules to take into account when solving your problem: Do not persistently mess up the syntax table if you do not see through all the consequences. It is used for many tasks. Do not advice forward-word to solve your problem. It is also used for many tasks you do not aprehend at the first look. But, what you can do is rebinding the keys for forward-char ...


4

At first, note that pdf-sync binds mouse-double-1 in the minor mode pdf-sync-minor-mode to pdf-sync-backward-search-mouse. So one should probably only bind it in a minor mode that can be deactivated again. The following code defines a minor mode pdf-sel-mode that binds mouse-double-1 to a new command pdf-sel-mouse. pdf-sel-mouse selects the word below the ...


4

Library Isearch+ lets you do that easily, and even toggle it on/off on the fly. Non-nil option isearchp-set-region-flag automatically sets the region (selection) around the last search target when you quit isearch. Command isearchp-toggle-set-region, bound to M-s M-SPC during isearch toggles option isearchp-set-region-flag. Command set-region-around-search-...


3

When emacs pastes ("yanks") text, it puts a mark at the start of the text, so selecting it can be done using exchange-point-and-mark, bound to C-xC-x by default.


2

The two commands org-table-select-col and org-table-copy-col in the following lisp code allow the selection and the copying of the current table column. You can bind it to the key of your liking and/or insert it via easy-menu-define-key into org-tbl-menu. (defun org-table-goto-col-beginning () "Go to beginning of current column and return `point'." (...


2

The transient-mark-mode-hook is called when you enter/leave the Transient Mark Mode, which is enabled by default starting from Emacs 23. Only when it's enabled, setting the mark will activate it and highlight the region. You could try the following code. (defconst my-alist `((mark-active ,@(let ((m (make-sparse-keymap))) (define-key m (kbd ...


2

The following is based on Tobias's answer but use Advising instead: (define-advice kill-ring-save (:around (old-fun &rest args) highlight) "Save the text selection and keep the selection highlight." (let (deactivate-mark) (apply old-fun args))) If you need to undo it, use (advice-remove 'kill-ring-save 'kill-ring-save@highlight)


2

The function kill-ring-save-keep-selection defined in the following emacs-lisp snippet works like kill-ring-save but keeps the selection. I've bound it to M-W in contrast to M-w for kill-ring-save. (byte-compile `(defun kill-ring-save-keep-selection (&rest args) "Just like `kill-ring-save' with arguments ARGS but keep selection." ,(interactive-...


2

Use M-| (shell-command-on-region) then sh to pipe the current region to Bash. It works because bash supports running program from STDIN, e.g., ~ $ echo 'date' | sh Mon Feb 25 21:54:51 CST 2019 M-| runs via a fresh shell every time, so I'm not sure if it can work in your case.


2

You could try sh-execute-region which is bound to C-M-x in sh-mode.


2

For the specific example you cite, I would execute M-z ,, where M-z is bound to zap-to-char. I don't know how well this would generalize to your daily usage though.


1

You need to say that this command is a navigation command, by replacing your (interactive) with (interactive "^") C-h o interactive RET explains that: [...] If the string begins with ^ and shift-select-mode is non-nil, Emacs first calls the function handle-shift-selection. [...]


1

Here is a function that returns the text between two surrounding blank lines: (defun region-between-surrounding-blank-lines () (interactive) (let ((beg nil) (end nil)) (save-excursion (re-search-backward (rx bol (* blank) eol)) (setq beg (point)) (forward-char) (re-search-forward (rx bol (* blank) eol)) (setq end (- (...


1

One can easily define a new command that displays a buffer with a given substring in its name. There are some conceptional things to consider: It may be that none of the living buffers has the substring in its name. The example code bails out in that case. There may be multiple buffers with that substring in their name. The example code selects one of ...


1

Not built in but another package for this is called objed (I'm the author). You can mark any text object with m the point is moved to the next object of current type automatically. Unmark any object by navigating to it and press m again. Here is an example screencast:


1

Org mode adds the org-date face to the timestamps, so you should be able to use the following to select the timestamp at point. (defun your-mark-org-timestamp () (interactive) (when (eq (get-text-property (point) 'face) 'org-date) (let ((beg (previous-property-change (point) nil (line-beginning-position))) (end (next-property-change (point)...


1

The original poster has indicated (in a comment) a desire "to create a highlighted region, so that [he/she] can copy or cut the region (i.e., the timestamp)". The following function returns the timestamp at point without permanently moving point to that location. The user can modify this function to do things like (kill-new ts) to put the timestamp into ...


1

Please consult the documentation for replace-string (you get the doc with C-h f replace-string RET). The Section on the arguments START and END clearly says how to reproduce the interactive behavior in elisp functions: Operates on the region between START and END (if both are nil, from point to the end of the buffer). Interactively, if Transient Mark ...


1

Posting own answer which mostly works as I'd like (needed some special consideration for evil mode and fci). While it works well for basic usage, errors will also replace the selection, ideally a nonzero exit code would display as a message instead of putting the error into the editor. ;; See: https://emacs.stackexchange.com/a/34900/2418 ;; Wrapper for '...


1

You can test whether there is an active selection of text using function region-active-p. C-h f region-active-p tells you: region-active-p is a compiled Lisp function in simple.el. (region-active-p) Return non-nil if Transient Mark mode is enabled and the mark is active. Some commands act specially on the region when Transient Mark mode ...


1

cute-jumpers answer is perfectly functional. If you want to bind the action to another key rather than use avy's internal dispatch process then the following adapted code works quite well: (defun my-avy-paste-word (char) "Paste a word selected with avy" (interactive (list (read-char "char:" t))) (let ((avy-action 'my-copy-word)) (avy--...


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