FindLongLines

Last edit

Summary: Rückgängig gemacht auf den Stand vom 2013-08-24 11:21 UTC

Changed:

< I bind `goto-longest-line' to `C-x L'. If you use IWikiModesPlus (library <tt>[[iWikiModes+.el]]</tt>, then `goto-longest-line' is also bound to `C-end' during IWikiModes (`C-s C-end'). This has the added advantage that `C-g' puts you back where you started. -- DrewAdams

to

> I bind `goto-longest-line' to `C-x L'. If you use IsearchPlus (library <tt>[[isearch+.el]]</tt>, then `goto-longest-line' is also bound to `C-end' during Isearch (`C-s C-end'). This has the added advantage that `C-g' puts you back where you started. -- DrewAdams


This page is about moving the cursor to long lines and visualizing long lines.

Go To Lines Longer than Some Limit

There are various ways to go to lines that are longer than some limit. Some of them just count characters to determine line length; others take character width into account as well, so they are useful even with characters of variable width.

Fixed Character Width

The following techniques do not take character width into account; they are based only on the number of characters. This means that these techniques might not be appropriate for characters of variable width (e.g. ‘TAB’ characters) or for double-width characters such as are typically used for Chinese and Japanese.

Variable Character Width

The following technique takes character width into account.

  (defun my-next-long-line (arg)
    "Move to the ARGth next long line greater than `fill-column'."
    (interactive "p")
    (or arg (setq arg 1))
    (let ((opoint (point))
          (line-length 0))
      ;; global-variable: fill-column
      (while (and (<= line-length fill-column)
                  (zerop (forward-line (if (< arg 0) -1 1))))
        (setq line-length (save-excursion
                            (end-of-line)
                            (current-column))))
      ;; Stop, end of buffer reached.
      (if (> line-length fill-column)
          (if (> arg 1)
              (my-next-long-line (1- arg))
            (if (< arg -1)
                (my-next-long-line (1+ arg))
              (message (format "Long line of %d columns found"
                               line-length))))
        (goto-char opoint)
        (message "Long line not found"))))

Go To the Longest Line(s)

Command ‘goto-longest-line’, from library misc-cmds.el, goes to the first of the longest lines in the region or the buffer. It does not matter where the line is with respect to the cursor position. If the region is active, then the region is checked; otherwise, the buffer is checked. Interactively, ‘goto-longest-line’ displays a message with the information that it returns, which is a list of four elements: (LINE LINE-LENGTH OTHER-LINES LINES-CHECKED).

Example messages:

      Line 234: 76 chars, (459 lines measured)
      Line 234: 76 chars, Others: {239, 313} (459 lines measured)

If you repeat ‘goto-longest-line’, it goes to the longest line following the current line. This destination is not necessarily the longest line, besides the current line, in the region or buffer; it is the longest line that occurs after the current line.

I bind ‘goto-longest-line’ to ‘C-x L’. If you use IsearchPlus (library isearch+.el, then ‘goto-longest-line’ is also bound to ‘C-end’ during Isearch (‘C-s C-end’). This has the added advantage that ‘C-g’ puts you back where you started. – DrewAdams

Visualizing Long Lines

There are several libraries that provide visual aids to let you know when the cursor passes a certain column limit. Usually, the aim is to avoid creating long lines or to point out lines that are longer than the limit.


CategoryEditing CategoryFilling EightyColumnRule