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)
Att Righ
  • 725
  • 4
  • 14
  • You should activate [lexical binding](https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html) instead of using `lexical-let`. See https://nullprogram.com/blog/2016/12/22/ – dalanicolai Jan 14 '23 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 Jan 15 '23 at 11:29
  • 1
    Ah, you might be interested in [this answer](https://emacs.stackexchange.com/a/75400/26163). – dalanicolai Jan 15 '23 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. – Phil Hudson Jan 18 '23 at 08:16
  • @PhilHudson that's what the checkdoc wants.... I don't know why. Is there a better linter? https://github.com/emacs-mirror/emacs/blob/master/lisp/emacs-lisp/checkdoc.el#L1815 – Att Righ Jan 19 '23 at 09:50
  • @AttRigh Perhaps you are misinterpreting checkdoc's feedback. I'd be interested to see the checkdoc message that flags plain F (or similar) as needing quotes. – Phil Hudson Jan 20 '23 at 11:29
  • I've included a repro in my questions. Here's the message: `Argument ‘f’ should appear (as F) in the doc string (C-h,f,e,n,p,q)` – Att Righ Jan 20 '23 at 11:35
  • That message confirm Phil's point. and tells you to include the argument as an uppercase f (F) in the docstring (and Phil adds the info that you should also remove the quoted 'f' as a reference to the argument f). – dalanicolai Jan 20 '23 at 11:47
  • 1
    Ah okay `' means links. Fine, I might as well use that standard. – Att Righ Jan 20 '23 at 11:57

1 Answers1

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.

mmarshall540
  • 131
  • 4