Skip to main content
11 votes
Accepted

Does "Occur-at-point" already exist?

There are a number of Emacs commands for which M-n at the input prompt (next-history-element) will insert a reasonable default if there is no next history element available. For occur that happens to ...
glucas's user avatar
  • 20.7k
7 votes

Occur with many conditions?

If you only care about a particular order (e.g. Buy comes first) then you can use a regexp: Buy.*0.00000057, as mentioned by @zck. But if you need to check for both orders then a single regexp won't ...
Drew's user avatar
  • 78k
6 votes

Does "Occur-at-point" already exist?

A common workflow is: start isearch with C-s, then search for the next word with C-w, then run occur with the current search string with M-s o.
sds's user avatar
  • 6,134
5 votes

Remove occurrences in occur mode?

If you delete the entire line from the occur buffer, it will not touch the original buffer. So press e to run #'occur-edit-mode, then delete the entire line (C-k).
zck's user avatar
  • 9,112
5 votes
Accepted

Yank / copy / get into a buffer matching regex search results

C-u M-x occur \"\(#[^\"]+\)\" <RETURN> \1 (this strips the quotes) or C-u M-x occur "#.+\" <RETURN> (this keeps the quotes) occur finds all lines that match the ...
Tyler's user avatar
  • 22.4k
5 votes
Accepted

Occur with many conditions?

If you know that BUY always comes before 0.00000057, you can give occur the regex BUY.*0.00000057. That will search for all lines that have BUY, any number of characters, then 0.00000057 in it. ...
zck's user avatar
  • 9,112
4 votes
Accepted

How can I make occur's regexp matching case-sensitive?

By default occur searches are case-insensitive. To force them to be case sensitive, you need to set the variable case-fold-search to nil. Note that this is a buffer-local variable. If you set it for ...
Tyler's user avatar
  • 22.4k
4 votes
Accepted

How save content of *occur* buffer?

You can use write-file (C-x C-w), then specify a filename. C-x C-w runs the command write-file (found in global-map), which is an interactive compiled Lisp function in ‘files.el’. Note however ...
YoungFrog's user avatar
  • 3,526
4 votes
Accepted

How search text which is on two lines?

You have to use a literal C-j to match the newline, which you can etnter by prefixing it with C-q, i.e. M-x occur RET text-to-find.*C-qC-j.*result (occur also takes a prefix argument that tells it ...
rpluim's user avatar
  • 5,365
3 votes
Accepted

How to tell Occur to show the line in the top of the buffer

You can scroll the window in occur-mode-find-occurrence-hook such that point is at the top of the window: (defun my-occur-recenter () "Scroll point to the top of the window." (recenter 0)) (add-...
Tobias's user avatar
  • 33.4k
3 votes
Accepted

Occur: optional arg REGION usage

You are quoting too much and e.g. not giving a chance to point-min and point-max to evaluate anything - ditto for b and e in your first attempt. Try (occur "foo" 1 (list (cons (point-min) (...
NickD's user avatar
  • 31.3k
3 votes
Accepted

why can't edit in buffer after save in file?

The *Occur* buffer will be in a major mode unsurprisingly called occur-mode. This mode, or perhaps the code that prepares it, or a combination of the two, do a number of things, including these: the ...
Harald Hanche-Olsen's user avatar
3 votes

Force new window to open to the left or right

You can invoke windmove-display-up/-down/-left/-right, windmove-display-same-window (C-M-S-0) or windmove-display-new-tab (C-M-S-t) right before making a new buffer to specify where to put it. The ...
Arch Stanton's user avatar
  • 1,707
3 votes
Accepted

browsing/navigating reStructuredText

rst-toc can be used to navigate sections.
Ista's user avatar
  • 1,198
3 votes
Accepted

Show text between two lines

Sure, use the function narrow-to-region. First select everything starting at the beginning of the line after the first match and ending at the end of the line before the second match, then type C-x n ...
db48x's user avatar
  • 18.4k
2 votes
Accepted

Previous/next occur result, independently from compilation errors

Looking at the source of occur-mode, I found this: (setq next-error-function 'occur-next-error)) This suggests occur-next-error is the function next-error calls in a "occured" buffer. And indeed, ...
JeanPierre's user avatar
  • 7,475
2 votes
Accepted

Using a backslash with occur

You need to escape the backslash with another backslash. So: M-s o \\def See the manual node on "Syntax for Strings" for more information.
Dan's user avatar
  • 33.2k
2 votes
Accepted

Predefined searches with helm-occur

Not sure how helm-swoop worked, but you can do this: (defun call-helm-occur (query) "Passes QUERY to helm-occur using `isearch-string'." (let ((isearch-string query)) (call-interactively '...
nanny's user avatar
  • 5,766
2 votes

Function that does `M-x replace-regexp` or `M-x occur` with a fixed pattern and replacement strings

For replace-regexp in many files, select the files in Dired and press Q to run dired-do-find-regexp-and-replace. See also the FAQ entry. For the equivalent of occur in many files, you can use A (...
Gilles 'SO- stop being evil''s user avatar
2 votes

Function that does `M-x replace-regexp` or `M-x occur` with a fixed pattern and replacement strings

One way this can be accomplished is by using dired. Here's an article from Xah Lee on how to use dired to find and replace across files: http://ergoemacs.org/emacs/find_replace_inter.html In short, ...
shoshin's user avatar
  • 914
2 votes
Accepted

How to go to matching pattern after org-occur?

Use the command next-error that is bound to the key sequence C-x ` (the second char is a backtick). As Omar pointed out in his comment, there is also a global keymap for motion commands bound to M-g. ...
Tobias's user avatar
  • 33.4k
2 votes

How to modify interactive function `occur` to a non-interactive function

I finally found a solution: (global-set-key (kbd "C-x j") (lambda () (interactive) (occur "regexp" nil))) I also found that \ needs to be escaped by another \ in the regexp, which ...
Youjun Hu's user avatar
  • 121
2 votes

How can I make occur's regexp matching case-sensitive?

You may (globally) toggle the behaviour with M-x toggle-case-fold-search. For more information see http://ergoemacs.org/emacs/elisp_list_matching_lines.html (dunno why the emacs wiki is less ...
StefanQ's user avatar
  • 161
2 votes
Accepted

How can I make occur display only first line of match?

(add-hook 'occur-mode-hook (lambda () (setq-local outline-regexp "^[[:blank:]]*[[:digit:]]+:" outline-level (lambda () ...
shynur's user avatar
  • 5,578
1 vote

How to use Helm to grep across a list of xz compressed files?

M-x zrgrep would be the normal way. I've just noticed there's no zlgrep though -- that would be a good feature request to M-x report-emacs-bug for. A manual workaround might be M-! zgrep -nH <...
phils's user avatar
  • 51.8k
1 vote

How to find all lines in a buffer that match string 1 but do not match string 2?

You can use M-x flush-lines in the occur buffer to perform the second half. You may have to toggle the read-only state first.
phils's user avatar
  • 51.8k
1 vote
Accepted

Aquamacs: Display *Occur* in current frame

Aquamacs is a version of GNU Emacs configured to behave in a more OSX way like TextEdit. This means that each thing is in a separate OS Window. Later versions of Aquamacs and macOS have added tabs so ...
mmmmmm's user avatar
  • 525
1 vote
Accepted

Remove occurrences in occur mode?

An occur buffer is just a buffer in read-only mode, that doesn't mean that it cannot be manipulated. Something as straightforward like this can help you: (defun occur-kill-line() "Quick and dirty ...
Muihlinn's user avatar
  • 2,664
1 vote

Using Occur to to recursively search in a directory

Elgrep allows you to grep files in a directory and recursively in its sub-directories. It lists the found matches in an *elgrep* buffer (much like occur). New users should input the search data in ...
Tobias's user avatar
  • 33.4k
1 vote
Accepted

Why after save *Occur* buffer I can't edit editable file?

The occur buffer is in occur mode. This mode doesn't allow you to edit text. After you save it, you need to change to a different mode. M-x text-mode should do what you need.
Tyler's user avatar
  • 22.4k

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