unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Marcin Borkowski <mbork@mbork.pl>
To: Bob Newell <bobnewell@bobnewell.net>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Size of startup files
Date: Tue, 22 Nov 2022 11:44:10 +0100	[thread overview]
Message-ID: <87pmdfclqd.fsf@mbork.pl> (raw)
In-Reply-To: <875yf9xvja.phibqa@vnoxvs.kbxpyjyhg.info>


On 2022-11-20, at 20:42, Bob Newell <bobnewell@bobnewell.net> wrote:

> Aloha,
>
> This is just a 'curiosity' question as I wonder if I am off
> the deep end even for an Emacs user, which would be really
> saying something.
>
> I just took a quick look and found that my startup files
> (called from .emacs and so on) amount to about 5,000 lines of
> elisp.  Of course I comment extensively but at least half of
> this or more is actual code.

(shameless-plug

In the Elisp book I wrote last year I included a fairly simple code to
count SLOC, excluding blank lines and comment-only lines.  Why not try
this on your init file?

--8<---------------cut here---------------start------------->8---
; -*- lexical-binding: t; -*-

(defun count-sloc--count-lines-if (predicate begin end)
  "Count lines satisfying PREDICATE from BEGIN to END.
PREDICATE should accept no arguments."
  (save-excursion
    (save-restriction
      (narrow-to-region begin end)
      (goto-char begin)
      (let ((count 0))
	(while (not (eobp))
	  (when (funcall predicate)
	    (setq count (1+ count)))
	  (forward-line))
	count))))

(defun count-sloc--act-on-region-or-buffer (func message)
  "Perform FUNC on region or buffer and print MESSAGE.
FUNC should accept two arguments, the beginning and end of the
range it operates on.  If MESSAGE contains
a placeholder (e.g. \"%s\"), the return value of FUNC is
substituted for it."
  (let (begin end)
    (if (use-region-p)
	(setq begin (region-beginning) end (region-end))
      (setq begin (point-min) end (point-max)))
    (message message (funcall func begin end))))

(defun count-sloc--comment-or-blank-line-p ()
  "Return t if the point is at a comment line.
Assume that the point is at the beginning of line."
  (unless (nth 3 (syntax-ppss))
    (save-excursion
      (let ((orig-line-number (line-number-at-pos)))
	(forward-comment 1000)
	(or (not (eq orig-line-number (line-number-at-pos)))
	    (eobp))))))

(defun count-sloc--negate (fun)
  "Return a function returning the logical opposite of FUN."
  (lambda (&rest args)
    (not (apply fun args))))

(defun count-sloc ()
  "Count non-blank lines in the region or buffer."
  (interactive)
  (count-sloc--act-on-region-or-buffer
   (apply-partially #'count-sloc--count-lines-if
		    (count-sloc--negate
		     #'count-sloc--comment-or-blank-line-p))
   "Non-blank lines: %s"))
--8<---------------cut here---------------end--------------->8---

My init.el is 1591 lines long (excluding comment/blank lines) and 2317
lines including them.  (But it includes a few other files.)  Also, my
init.el is /very/ messy (I will make it better Some Day™.)

)

Best,

-- 
Marcin Borkowski
http://mbork.pl



  parent reply	other threads:[~2022-11-22 10:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-20 19:42 Size of startup files Bob Newell
2022-11-20 20:24 ` Colin Baxter
2022-11-21 21:52   ` Bob Newell
2022-11-22 10:00     ` Eric S Fraga
2022-11-20 22:07 ` Rudolf Adamkovič
2022-11-21  0:46   ` Samuel Wales
2022-11-21  9:37 ` Eric S Fraga
2022-11-21 22:00 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-11-21 23:10   ` Emanuel Berg
2022-11-22  7:02     ` Pankaj Jangid
2022-11-22 11:45       ` Jean Louis
2022-11-22 14:34       ` M-x toggle-theme Jean Louis
2022-11-22 16:59         ` Philip Kaludercic
2022-11-22 17:48           ` Akib Azmain Turja
2022-11-22 18:08             ` Philip Kaludercic
2022-11-23 10:54     ` libraries (was: Re: Size of startup files) Emanuel Berg
2022-11-21 23:20   ` Size of startup files Emanuel Berg
2022-11-22 10:44 ` Marcin Borkowski [this message]
2022-11-22 14:45   ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pmdfclqd.fsf@mbork.pl \
    --to=mbork@mbork.pl \
    --cc=bobnewell@bobnewell.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).