3

I am configuring a CI/CD pipeline to process org-mode files into documentation, source code, and other file formats.

I would like to add a call to org-lint to do basic syntax checking against org files as part pipeline.

Unfortunately I haven't be able get the command line to work.

I've tried the following commands:

emacs --batch -l org -f org-lint org-lint-notes.org

emacs --batch -l org --eval '(org-lint)' org-lint-notes.org

But both return the error below:

Symbol’s function definition is void: org-lint

I'm not sure what I'm doing wrong.

Thanks for your help!


This code was tested using:
emacs version: GNU Emacs 25.2.1 (x86_64-unknown-cygwin, GTK+ Version 3.22.10)
org-mode version: 9.1.2

  • 1
    I am not sure but I doubt that org 9.1.2 was shipped with emacs 25.2.1. I think it was some 8.X version. Could it be that you installed org 9.1.2 with package-install? In that case you need to add -f package-initialize to use orgmode 9.1.2 with --batch. Further note that you should load the buffer you want to lint before you call -f org-lint. You can test which org version you are using with --batch and without package-initialize by emacs --batch -f org-version on the command line. – Tobias Jun 23 '18 at 14:24
  • Note further that you should not need -l org since org-lint as well as org-versionare autoloaded. – Tobias Jun 23 '18 at 14:28
  • @Tobias - Thank you! I completely forgot about loading package-initialize like publish.el does. I’ll do some research about loading buffer first and/or passing buffer name to org-lint. Thanks again! – Melioratus Jun 23 '18 at 16:30
0

Calling org-lint against org-mode file from command-line

  1. Create an org-mode file

    • For example, create a new file named org-lint-ex1.org

      * Using =org-lint= to Check org-mode Syntax
      ** Inside emacs
      
      1. Open org-mode file in emacs.
      
      2. Invoke =org-lint= command
      
         #+BEGIN_SRC 
           M-x org-lint
         #+END_SRC
      
          #+BEGIN_SR shell
           M-x org-lint
         #+END_SRC
      
  2. Call org-lint from the command-line

    For example, to execute org-lint against the org-lint-ex1.org file use the following command:

    emacs --batch -f package-initialize --eval "(add-hook 'org-mode-hook 
          (lambda ()  
              (let* ((file-name (current-buffer))
                (Col1 'Line)
                (Col2 'Trust)
                (Col3 'Warning)
                (lint-report (org-lint))
                )
              (princ (format \"file: %s\n%6s%6s%8s\n\" file-name Col1 Col2 Col3))
              (dolist (element lint-report)
               (setq report (car (cdr element)))
               (princ (format \"%6s%6s %7s\n\" (seq-elt report 0) (seq-elt report 1) (seq-elt report 2)))
              )
          )))" org-lint-ex1.org 
    

    The output of the command should be similar to the following:

    file: org-lint-ex1.org
      Line Trust Warning
         8  high Missing language in source block
        12   low Possible incomplete block "#+BEGIN_SR shell"
        14   low Possible incomplete block "#+END_SRC"
    

Note: If using emacs version less than 25.x.x, update script code to call elt instead of seq-elt.


This code was tested using:
emacs version: GNU Emacs 25.2.1 (x86_64-unknown-cygwin, GTK+ Version 3.22.10)
org-mode version: 9.1.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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