Skip to content

Commit

Permalink
Merge pull request #50 from djgoku/feature/the-real-add-count-duplica…
Browse files Browse the repository at this point in the history
…te-lines

Adding `count-duplicate-lines`
  • Loading branch information
djgoku authored Apr 5, 2024
2 parents 808b4de + d530928 commit b274a98
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions emacs/config.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
(global-unset-key (kbd "C-x C-z"))
#+end_src

* ~count-duplicate-lines~

This function is similar to ~delete-duplicate-lines~, but this
actually counts the lines and puts the value beside the counted line.

#+begin_src emacs-lisp
(defun count-duplicate-lines ()
"count duplicate lines"
(interactive)
(save-excursion
(goto-char (point-min))
(while (not (eq (point) (point-max)))
(let* ((current-line-as-string (string-trim-right (thing-at-point 'line t)))
(current-line-as-string-count (+ 1 (string-width current-line-as-string))) ; adding one since we trim the newline
(counted (count-matches current-line-as-string))
(current-point (point)))
(flush-lines current-line-as-string)
(insert current-line-as-string (format ",%s" counted) ?\n)))))
#+end_src
#+begin_src emacs-lisp :results none
(when (and (string-equal system-type "gnu/linux") (fboundp 'guix-emacs-autoload-packages))
(add-to-list 'load-path "~/.guix-profile/share/emacs/site-lisp")
Expand Down

0 comments on commit b274a98

Please sign in to comment.