Skip to content

Don't count form feed character (\f or ^L) as newline, optionally #2609

@skangas

Description

@skangas

In Emacs, the form feed \f or ^L (Ctrl+L) character, 0xC in ASCII, is not considered to start a new line. Wikipedia explains:

The form feed character is sometimes used in plain text files of source code as a delimiter for a page break, or as marker for sections of code. Some editors, in particular emacs and vi, have built-in commands to page up/down on the form feed character. This convention is predominantly used in Lisp code, and is also seen in C and Python source code. GNU Coding Standards require such form feeds in C.[2] Editors like Vim and Emacs understand such sections and have shortcuts for moving among them.

In Emacs, a file containing just the three characters \n\f\d will be considered to have two (2) lines, the first of them being \n and the second line \f\n. But codespell counts this file as a file with three (3) lines.

Recipe to reproduce:

$ echo -ne "foo\n\f\nte\n" > /tmp/foo.txt
$ codespell /tmp/foo.txt
/tmp/foo.txt:4: te ==> the, be, we, to

If I open /tmp/foo.txt in Emacs, and try to jump to line 4, I end up on the empty line at the end of the file. I do not go to the line containing the typo, which in Emacs is line 3. This obviously gets worse the more \n\f\n there are in a file: every one means we land further and further from the actual typo.

Would it be possible to add an option to treat \f in the way that is expected by Emacs? I'm not sure what it should be called, but something like --form-feed-no-newline or --emacs-form-feed perhaps.

This would help tremendously when using codespell on Emacs Lisp source code. There are many, many Lisp files which contain the character sequence \n\f\n.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions