emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [FR] Don't hardcode checker functions prefix in org-lint
@ 2020-11-10 20:22 Gustavo Barros
  2020-11-13  1:08 ` Gustavo Barros
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo Barros @ 2020-11-10 20:22 UTC (permalink / raw)
  To: emacs-orgmode

Hi All,

This is a small feature request for `org-lint' not to hardcode the 
checker functions' prefix, as it currently does.

`org-lint' is a small gem in Org, specially to those fat-fingered folks 
such as myself, to the point that it's been some time since I've been 
fancying using it to check some of my own personal conventions and 
structures, beyond Org syntax.  It is not difficult to do so, and it is 
enough to define some appropriate checker functions and a personal 
`my-org-lints' let binding `org-lint--checkers' to my own set of 
checkers.  It's pretty neat.

However, `org-lint' hardcodes the prefix of the checker functions to its 
own prefix, so that to define my own personal checker functions I have 
to step on `org-lint's namespace, and use "org-lint-" as a prefix, to 
get things working.  The hardcoding occurs in 
`org-lint--generate-reports', when each checker is called with:

#+begin_src emacs-lisp
(funcall
 (intern (format "org-lint-%s"
		 (org-lint-checker-name c)))
 ast)
#+end_src

It would be really useful, and simple enough, if a variable was defined, 
such as:

#+begin_src emacs-lisp
(defvar org-lint-checker-prefix "org-lint")
#+end_src

and the call used this variable instead of hardcoding its value:
#+begin_src emacs-lisp
(funcall
 (intern (format "%s-%s"
                 org-lint-checker-prefix
		 (org-lint-checker-name c)))
 ast)
#+end_src

This would allow to define the mentioned `my-org-lints' function let 
binding `org-lint--checkers' and `org-lint-checker-prefix' to 
appropriate values.  So that an user's checker functions could have 
names with other prefixes.

As far as my grasp of `org-lint' goes (still learning), that would be 
enough for users to enjoy its infrastructure for personal lints without 
having to invade org-lint's namespace.  If you think it's a good idea, 
I'd certainly appreciate it to be included.  Thank you.

Best regards,
Gustavo.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FR] Don't hardcode checker functions prefix in org-lint
  2020-11-10 20:22 [FR] Don't hardcode checker functions prefix in org-lint Gustavo Barros
@ 2020-11-13  1:08 ` Gustavo Barros
  0 siblings, 0 replies; 2+ messages in thread
From: Gustavo Barros @ 2020-11-13  1:08 UTC (permalink / raw)
  To: emacs-orgmode

Hi All,

On Tue, 10 Nov 2020 at 17:22, Gustavo Barros <gusbrs.2016@gmail.com> 
wrote:

> This is a small feature request for `org-lint' not to hardcode the 
> checker
> functions' prefix, as it currently does.

I've been playing with and testing this further, and I found an 
uncovered corner in my initial suggestion: the revert-buffer behavior in 
the report buffer.  It is still simple to handle it, but requires a 
couple of extra steps: set the prefix variable as a buffer local 
variable in the report buffer in `org-lint--display-reports' and 
let-bind this value before moving to the linted buffer in 
`org-lint--generate-reports'.

As an extra sugar, but non essential, it would also be nice to be able 
to set the report buffer's name.

In sum, the suggestion/request then entails:

#+begin_src emacs-lisp
(defvar-local org-lint--checkers-prefix nil)
(defvar-local org-lint--report-buffer-name nil)

(defun org-lint--generate-reports (buffer checkers)
  (let ((checkers-prefix (or org-lint--checkers-prefix "org-lint")))
    (with-current-buffer buffer
      ;; [...]
      (funcall
       (intern (format "%s-%s"
                       checkers-prefix
		       (org-lint-checker-name c)))
       ast)
      ;; [...]
      )))

(defun org-lint--display-reports (source checkers)
  ;; changed let-binding <--
  (let ((buffer (get-buffer-create (or org-lint--report-buffer-name
                                       "*Org Lint*"))))
    (with-current-buffer buffer
      (org-lint--report-mode)
      (setf org-lint--source-buffer source)
      (setf org-lint--local-checkers checkers)
      ;; added variable setting <--
      (setf org-lint--checkers-prefix org-lint--checkers-prefix)
      (org-lint--refresh-reports)
      (tabulated-list-print)
      (add-hook 'tabulated-list-revert-hook #'org-lint--refresh-reports 
      nil t))
    (pop-to-buffer buffer)))
#+end_src

That's about it.  With it, I get a fully functional Lint report for 
personal lints with something like:

#+begin_src emacs-lisp
(defun my/org-lint (&optional arg)
  (interactive "P")
  (let ((org-lint--checkers my/org-lint-checkers)
        (org-lint--checkers-prefix "my/org-lint")
        (org-lint--report-buffer-name "*My Org Lint*"))
    (funcall-interactively 'org-lint arg)))
#+end_src

Best regards,
Gustavo.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-13  1:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-10 20:22 [FR] Don't hardcode checker functions prefix in org-lint Gustavo Barros
2020-11-13  1:08 ` Gustavo Barros

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).