3

I have the following function:

(defun filter-repl-show-after (line-num)
  "Show lines after LINE-NUM."
  (filter-repl--foreach-line
   (lexical-let ((line-num line-num))
     (lambda ()
       (when (> (line-number-at-pos) line-num)
         (filter-repl--show-line))))))

(defun filter-repl--foreach-line (f)
  "Apply F to each line in the buffer."
  (save-excursion
    (goto-char (point-min))
    (while (not (eobp))
        (funcall f)
        (forward-line))))

The elisp linter is warning me that ‘(line-num line-num)’ is a malformed function. The problem seems to be due to the lexical letter, because I don't get the warning with

(defun filter-repl-show-after-tweaked (line-num)
  "Show lines after LINE-NUM."
  (filter-repl--foreach-line
     (lambda ()
       (when (> (line-number-at-pos) line-num)
         (filter-repl--show-line)))))

Is this warning a false positive and I avoid it if so?

Regarding checkdoc demanding uppercase names in docstring

Repro M-x checkdoc on

(defun hello (f)
  "Say hello to 'f'."
)

Results in the followign message:

Argument ‘f’ should appear (as F) in the doc string (C-h,f,e,n,p,q)
9
  • You should activate lexical binding instead of using lexical-let. See nullprogram.com/blog/2016/12/22 Commented Jan 14, 2023 at 10:10
  • Yeah I guess that's one approach. I'm a bit hesitant about lexical-let because I have a habit of editting functions one at a tine and evaluating them and could get bugs because the file's lexical-let property gets forgotten.
    – Att Righ
    Commented Jan 15, 2023 at 11:29
  • 1
    Ah, you might be interested in this answer. Commented Jan 15, 2023 at 14:13
  • 1
    Trivial doco tip: you are unnecessarily (and incorrectly) quoting argument names in your docstrings. Taking your second function above for example, you are telling Emacs to link to the documentation for a variable, function, macro, user option, face or other object called "F" (literally, in upper case), which presumably does not exist. Just leave your argument names uppercase but unquoted. Commented Jan 18, 2023 at 8:16
  • 1
    Ah okay `' means links. Fine, I might as well use that standard.
    – Att Righ
    Commented Jan 20, 2023 at 11:57

1 Answer 1

1

The elisp linter is warning me that ‘(line-num line-num)’ is a malformed function.

The elisp linter is saying that the list (line-num line-num) doesn't make sense as a function object. The reason it thinks it should be a function object is probably that it doesn't know that lexical-let is a macro, and also because it's the first item in the unquoted ((line-num line-num)) list.

After initially copying your first code block into my *scratch* buffer, I got the same "malformed function" warning (plus a warning stating that "the function" lexical-let doesn't appear to be defined).

If you add (require 'cl) above the code, both warnings disappear. However, an additional warning appears, about the "cl" library being deprecated.

From at least Emacs 28 forward, lexical-let is only found in the (deprecated) "cl" library. Based on the commentary to "cl-lib", it may have at one point been included in that (non-deprecated) library, but it isn't anymore. So you might want to look for an alternative to using the lexical-let macro.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.