3

I'm trying to debug a piece of elisp that is in an orgmode template I'd like to use. (link here) The problem is occurring in the source block that is supposed define the cite links.

(org-add-link-type 
 "cite" 'ebib
 (lambda (path desc format)
   (cond
    ((eq format 'html)
     (format "(<cite>%s</cite>)" path))
    ((eq format 'latex)
     (if (or (not desc) (equal 0 (search "cite:" desc)))
         (format "\\cite{%s}" path)
       (format "\\cite[%s][%s]{%s}"
               (cadr (split-string desc ";"))
               (car (split-string desc ";"))  path))))))

now when this block is run, it completes no problem and gives back a "Created cite link." message which is expected. However when you go to run the latex exporter, it gives me the following error.

Symbol's function definition is void: search

I have narrowed this down to the search command in the add link block, however I cannot figure out what it is supposed to be calling. From my research Common Lisp has a search function, but elisp does not. I've tried modifying the code to use every search like function build into emacs, and a few that are not such as the ebib-search with no success. Do any of you have an idea as to what this is referencing?

2
  • 2
    It probably is the Common Lisp search. Add (require 'cl), or else rename it to cl-search (which is autoloaded).
    – phils
    Nov 27, 2017 at 6:22
  • @phils you are absolutely right, do you want to make this an answer so I can accept it?
    – Nalisarc
    Nov 27, 2017 at 18:29

2 Answers 2

4

From my research Common Lisp has a search function, but elisp does not.

elisp does in fact provide the Common Lisp search function in the cl library.

So adding (require 'cl) will fix the problem for the code as written.

Alternatively you could change search to cl-search which is an autoloaded alias.

4

I think just using the built-in string-match instead of search is the most simple thing in this special case.

The modified code would look like:

(org-add-link-type 
 "cite" 'ebib
 (lambda (path desc format)
   (cond
    ((eq format 'html)
     (format "(<cite>%s</cite>)" path))
    ((eq format 'latex)
     (if (or (not desc) (equal 0 (string-match "cite:" desc)))
         (format "\\cite{%s}" path)
       (format "\\cite[%s][%s]{%s}"
               (cadr (split-string desc ";"))
               (car (split-string desc ";"))  path))))))

Two remarks are in place:

  1. The common lisp function search searches for literal strings while string-match searches for regular expressions. That does not matter here since there are no special characters in the search string cite:.
  2. string-match modifies the match data. That does not matter here since the match data is modified anyway by split-string.
3
  • Interesting take, and I'll need to experiment with it a bit. But it looks like the problem was that I was missing the cl package, and I just needed to require it. Thanks for looking into it though.
    – Nalisarc
    Nov 27, 2017 at 18:41
  • @Nalisarc I know that (require 'cl) works. But, why pulling a heavy-weight package in when there is a light-weight built-in solution.
    – Tobias
    Nov 27, 2017 at 19:28
  • Oh I see, the two aren't quite identical, but upon closer inspection string-match should do the same thing as cl-search.
    – Nalisarc
    Nov 27, 2017 at 21:09

Your Answer

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

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