all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How can i search for lines which wrap?
@ 2021-07-09  4:39 Dan Hitt
  2021-07-09  5:12 ` 2QdxY4RzWzUUiLuE
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Dan Hitt @ 2021-07-09  4:39 UTC (permalink / raw)
  To: Help Gnu Emacs

I was recently editing a document to try to make all the lines be no longer
than 79 characters.

There were a few ways that could occur: one would be a line of 80 dashes,
one would be a line of 80 underscores, and there were a few variants that i
could systematically locate (by searching for the offending pattern
followed by a control-J), and then fix.  Searching for control-J by itself
wouldn't do because i only wanted to get to the end of lines that are too
long.

So what i was missing was an easy way to search to the end of the next line
with 80 or more characters.

Basically, i would like to search for the continuation character which
signifies that the next visible line is not really a new line.  In the
emacs gui, this is depicted as a curved arrow in the margin.  In text emas,
this is signified by a backslash (that you cannot search for as a
backslash).

Since emacs can do everything else, i imagine there must be some way to
search for this, but i cannot recall ever having done so.

Thanks for any clues on how to do this.

dan


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How can i search for lines which wrap?
  2021-07-09  4:39 How can i search for lines which wrap? Dan Hitt
@ 2021-07-09  5:12 ` 2QdxY4RzWzUUiLuE
  2021-07-09  6:36   ` Eli Zaretskii
  2021-07-09  6:35 ` Eli Zaretskii
  2021-07-10  1:20 ` [External] : " Drew Adams
  2 siblings, 1 reply; 6+ messages in thread
From: 2QdxY4RzWzUUiLuE @ 2021-07-09  5:12 UTC (permalink / raw)
  To: help-gnu-emacs

On 2021-07-08 at 21:39:08 -0700,
Dan Hitt <dan.hitt@gmail.com> wrote:

> I was recently editing a document to try to make all the lines be no longer
> than 79 characters.
> 
> There were a few ways that could occur: one would be a line of 80 dashes,
> one would be a line of 80 underscores, and there were a few variants that i
> could systematically locate (by searching for the offending pattern
> followed by a control-J), and then fix.  Searching for control-J by itself
> wouldn't do because i only wanted to get to the end of lines that are too
> long.
> 
> So what i was missing was an easy way to search to the end of the next line
> with 80 or more characters.

The regular expression .\{80\}$ matches the end of lines consisting of
80 or more characters.

> Basically, i would like to search for the continuation character which
> signifies that the next visible line is not really a new line.  In the
> emacs gui, this is depicted as a curved arrow in the margin.  In text emas,
> this is signified by a backslash (that you cannot search for as a
> backslash).

Those continuation characters depend on the width of the frame.  As you
noted, they're not part of your document.

> Since emacs can do everything else, i imagine there must be some way to
> search for this, but i cannot recall ever having done so.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How can i search for lines which wrap?
  2021-07-09  4:39 How can i search for lines which wrap? Dan Hitt
  2021-07-09  5:12 ` 2QdxY4RzWzUUiLuE
@ 2021-07-09  6:35 ` Eli Zaretskii
  2021-07-10  1:20 ` [External] : " Drew Adams
  2 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2021-07-09  6:35 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Dan Hitt <dan.hitt@gmail.com>
> Date: Thu, 8 Jul 2021 21:39:08 -0700
> 
> I was recently editing a document to try to make all the lines be no longer
> than 79 characters.
> 
> There were a few ways that could occur: one would be a line of 80 dashes,
> one would be a line of 80 underscores, and there were a few variants that i
> could systematically locate (by searching for the offending pattern
> followed by a control-J), and then fix.  Searching for control-J by itself
> wouldn't do because i only wanted to get to the end of lines that are too
> long.
> 
> So what i was missing was an easy way to search to the end of the next line
> with 80 or more characters.

Use end-of-line to go to the end of a line, then use current-column to
find out the column number, and compare that to 79 (or any other
number you need).



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How can i search for lines which wrap?
  2021-07-09  5:12 ` 2QdxY4RzWzUUiLuE
@ 2021-07-09  6:36   ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2021-07-09  6:36 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Thu, 8 Jul 2021 22:12:48 -0700
> From: 2QdxY4RzWzUUiLuE@potatochowder.com
> 
> > So what i was missing was an easy way to search to the end of the next line
> > with 80 or more characters.
> 
> The regular expression .\{80\}$ matches the end of lines consisting of
> 80 or more characters.

Caveat: this assumes that each character takes up just one column on
display.  That assumption can be false, because there are zero-width
characters and wide characters.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [External] : How can i search for lines which wrap?
  2021-07-09  4:39 How can i search for lines which wrap? Dan Hitt
  2021-07-09  5:12 ` 2QdxY4RzWzUUiLuE
  2021-07-09  6:35 ` Eli Zaretskii
@ 2021-07-10  1:20 ` Drew Adams
  2021-07-12 17:16   ` Drew Adams
  2 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2021-07-10  1:20 UTC (permalink / raw)
  To: Dan Hitt, Help Gnu Emacs

> So what i was missing was an easy way to search to
> the end of the next line with 80 or more characters.

There are a few ways to do what you request.  Here are a couple.

1. You can make use of command `goto-long-line' from library
   `misc-cmds.el'.  That prompts you for a line length and
   then goes to the next line that's at least that long.

   To do that during Isearch for lines at least 80 chars,
   define a command such as this, which uses `goto-long-line':

   (defun goto-line>79-chars ()
     "Go to next line at least 80 chars long."
     (interactive)
     (goto-long-line 80 t))

   Then bind that command to a key in `isearch-mode-map'.
   Use it during Isearch anytime to go to the next line
   that's 80 chars or longer.

   (define-key isearch-mode-map (kbd "C-e") 'goto-line>79-chars)

   Library `misc-cmds.el' is here:

   https://www.emacswiki.org/emacs/download/misc-cmds.el


2. You can set `isearch-filter-predicate' to a function that
   returns non-nil only for a single-line search hit that ends
   past column 79.  Then regexp-search for a regexp such as `.$'.

   (defun line>79-p (beg end)
     "Return non-nil if END is past column 79."
     (save-excursion (goto-char end) (> (current-column) 79)))

   ;; (setq ORIG-isearch-filter-predicate  isearch-filter-predicate)
   (setq isearch-filter-predicate  'line>79-p)
   ;; (setq isearch-filter-predicate  ORIG-isearch-filter-predicate)

(You can use the commented out code to get back to the default filter.)

Note that you can't just regexp-search for `$', because
`isearch-filter-predicate' isn't used for empty matches.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [External] : How can i search for lines which wrap?
  2021-07-10  1:20 ` [External] : " Drew Adams
@ 2021-07-12 17:16   ` Drew Adams
  0 siblings, 0 replies; 6+ messages in thread
From: Drew Adams @ 2021-07-12 17:16 UTC (permalink / raw)
  To: Dan Hitt, Help Gnu Emacs

I said:

> 2. You can set `isearch-filter-predicate' to a function that
>    returns non-nil only for a single-line search hit that ends
>    past column 79.  Then regexp-search for a regexp such as `.$'.
> 
>    (defun line>79-p (beg end)
>      "Return non-nil if END is past column 79."
>      (save-excursion (goto-char end) (> (current-column) 79)))
>
> Note that you can't just regexp-search for `$', because
> `isearch-filter-predicate' isn't used for empty matches.

The unnecessary restriction of that last Note is no
longer true.  I've fixed Isearch+ so that filter
predicates can now be used also for empty matches
(such as regexp-searching for just `$').  And I filed
bug #49534, for vanilla Emacs to do likewise.

For example, with the above function `line>79-p', you
can use this command to search for lines of 80 chars
or longer using just `$' (no need to use `.$' etc.):

 (defun foo ()
   (interactive)
   (let ((isearch-filter-predicate  #'line>79-p))
     (isearch-forward 4)))

___

Of course, when a match is empty, as they all are in
this case, it can be difficult to see just where the
current search hit is, as you bounce around among hits.

For that, you can add a predefined filter predicate
named `crosshairs' (if you have library `crosshairs.el').
To do that, just use `C-z &' during Isearch, and enter
`crosshairs' (with completion) at the prompt.

That highlights the line and column of point at each
search hit.

`C-z &' is an example of a dynamic filtering key.
Dynamic filtering let you add, remove, and combine
Isearch filter predicates on the fly.  More info:

https://www.emacswiki.org/emacs/DynamicIsearchFiltering

___

More about library `crosshairs.el':

https://www.emacswiki.org/emacs/CrosshairHighlighting

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-07-12 17:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-09  4:39 How can i search for lines which wrap? Dan Hitt
2021-07-09  5:12 ` 2QdxY4RzWzUUiLuE
2021-07-09  6:36   ` Eli Zaretskii
2021-07-09  6:35 ` Eli Zaretskii
2021-07-10  1:20 ` [External] : " Drew Adams
2021-07-12 17:16   ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.