Hot answers tagged

11

M-= (command count-words-region). (The region does not even need to be activated, but activating it lets you see it.)


2

You can also use the function bolp: bolp is a built-in function in `../editfns.c'. (bolp) Return t if point is at the beginning of a line. This function does not change global state, including the match data. Usually you get a buffer position via (point), thus simply issuing (bolp) will be enough. If the point has been moved, use goto-...


2

Count lines does the trick, it is defined in simple.el (count-lines (point-min) (point-max))


1

For a faster method to get line number at position -- (with-current-buffer BUFFER (goto-char POSITION) (string-to-number (format-mode-line "%l"))) -- see the following thread, which cites some limitations / disadvantages in the comments: A faster method to obtain `line-number-at-pos` in large buffers The traditional method is to use line-number-at-pos, ...


1

Try delete-duplicate-lines, which is part of distributed Emacs. Emacs Wiki page Duplicate Lines might help. It points to a blog post about it. It explains why interactive search-and-replace might not help. It explains how to do it with Lisp, in various ways. It explains how to do it with the UNIX / GNU/Linux command sort or unique.


1

If you don't need to do this all the time, the quickest solution might be using interactive replacement: query-replace-regexp, bound to C-M-%. Start with point at the top of the buffer. Note, if you want to delete entire lines, you'll need to include a newline in your regexp. You enter this at the prompt with C-q C-j. So, for over_second, call C-M-%, then ...


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