help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Size of startup files


From: Marcin Borkowski
Subject: Re: Size of startup files
Date: Tue, 22 Nov 2022 11:44:10 +0100
User-agent: mu4e 1.1.0; emacs 29.0.50

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]