jkitchin / org-ref

org-mode modules for citations, cross-references, bibliographies in org-mode and useful bibtex tools to go with it.
GNU General Public License v3.0
1.36k stars 243 forks source link

insert link after link got eval: No catch for tag: --cl-block-nil--, 1 cl-return #788

Closed tshu-w closed 4 years ago

tshu-w commented 4 years ago

I got eval: No catch for tag: --cl-block-nil--, 1 cl-return if I insert link after an existing link.

Backtrace:

Debugger entered--Lisp error: (no-catch --cl-block-nil-- 0)
  throw(--cl-block-nil-- 0)
  org-ref-list-index("2017annual" ("2017annual"))
  org-ref-insert-key-at-point(("1705"))
  or-ivy-bibtex-insert-cite(("1705: ((collection . NLI) (timestamp . 2020-07-22T..." ("collection" . "NLI") ("timestamp" . "2020-07-22T06:54:19Z") ("file" . "/Users/wangtianshu/Zotero/storage/H9TPCX4W/1705.ht...") ("annotation" . "00000") ("urldate" . "2020-07-22") ("url" . "https://arxiv.org/abs/1705.02364") ("title" . "[1705.02364] {{Supervised Learning}} of {{Universa...") ("=type=" . "online") ("=key=" . "1705") ("bibfile" . "/Users/wangtianshu/Documents/Zotero/references.bib") ("position" . 368)))
  ivy-call()
  #f(compiled-function (arg1 arg2 &rest rest) "Read a string in the minibuffer, with completion.\n\nPROMPT is a string, normally ending in a colon and a space.\n`ivy-count-format' is prepended to PROMPT during completion.\n\nCOLLECTION is either a list of strings, a function, an alist, or\na hash table, supplied for `minibuffer-completion-table'.\n\nPREDICATE is applied to filter out the COLLECTION immediately.\nThis argument is for compatibility with `completing-read'.\n\nWhen REQUIRE-MATCH is non-nil, only members of COLLECTION can be\nselected.\n\nIf INITIAL-INPUT is non-nil, then insert that input in the\nminibuffer initially.\n\nHISTORY is a name of a variable to hold the completion session\nhistory.\n\nKEYMAP is composed with `ivy-minibuffer-map'.\n\nPRESELECT, when non-nil, determines which one of the candidates\nmatching INITIAL-INPUT to select initially.  An integer stands\nfor the position of the desired candidate in the collection,\ncounting from zero.  Otherwise, use the first occurrence of\nPRESELECT in the collection.  Comparison is first done with\n`equal'.  If that fails, and when applicable, match PRESELECT as\na regular expression.\n\nDEF is for compatibility with `completing-read'.\n\nUPDATE-FN is called each time the candidate list is re-displayed.\n\nWhen SORT is non-nil, `ivy-sort-functions-alist' determines how\nto sort candidates before displaying them.\n\nACTION is a function to call after selecting a candidate.\nIt takes one argument, the selected candidate. If COLLECTION is\nan alist, the argument is a cons cell, otherwise it's a string.\n\nMULTI-ACTION, when non-nil, is called instead of ACTION when\nthere are marked candidates. It takes the list of candidates as\nits only argument. When it's nil, ACTION is called on each marked\ncandidate.\n\nUNWIND is a function of no arguments to call before exiting.\n\nRE-BUILDER is a function transforming input text into a regex\npattern.\n\nMATCHER is a function which can override how candidates are\nfiltered based on user input.  It takes a regex pattern and a\nlist of candidates, and returns the list of matching candidates.\n\nDYNAMIC-COLLECTION is a boolean specifying whether the list of\ncandidates is updated after each input by calling COLLECTION.\n\nEXTRA-PROPS is a plist that can be used to store\ncollection-specific session-specific data.\n\nCALLER is a symbol to uniquely identify the caller to `ivy-read'.\nIt is used, along with COLLECTION, to determine which\ncustomizations apply to the current completion session." #<bytecode 0x1fee720d7c25>)("Open: " (... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) :require-match t :keymap (keymap ... ... ... ... ... ... ... ... ...) :re-builder ivy--regex-ignore-order :action or-ivy-bibtex-insert-cite :caller org-ref-ivy-insert-cite-link)
  apply(#f(compiled-function (arg1 arg2 &rest rest) "Read a string in the minibuffer, with completion.\n\nPROMPT is a string, normally ending in a colon and a space.\n`ivy-count-format' is prepended to PROMPT during completion.\n\nCOLLECTION is either a list of strings, a function, an alist, or\na hash table, supplied for `minibuffer-completion-table'.\n\nPREDICATE is applied to filter out the COLLECTION immediately.\nThis argument is for compatibility with `completing-read'.\n\nWhen REQUIRE-MATCH is non-nil, only members of COLLECTION can be\nselected.\n\nIf INITIAL-INPUT is non-nil, then insert that input in the\nminibuffer initially.\n\nHISTORY is a name of a variable to hold the completion session\nhistory.\n\nKEYMAP is composed with `ivy-minibuffer-map'.\n\nPRESELECT, when non-nil, determines which one of the candidates\nmatching INITIAL-INPUT to select initially.  An integer stands\nfor the position of the desired candidate in the collection,\ncounting from zero.  Otherwise, use the first occurrence of\nPRESELECT in the collection.  Comparison is first done with\n`equal'.  If that fails, and when applicable, match PRESELECT as\na regular expression.\n\nDEF is for compatibility with `completing-read'.\n\nUPDATE-FN is called each time the candidate list is re-displayed.\n\nWhen SORT is non-nil, `ivy-sort-functions-alist' determines how\nto sort candidates before displaying them.\n\nACTION is a function to call after selecting a candidate.\nIt takes one argument, the selected candidate. If COLLECTION is\nan alist, the argument is a cons cell, otherwise it's a string.\n\nMULTI-ACTION, when non-nil, is called instead of ACTION when\nthere are marked candidates. It takes the list of candidates as\nits only argument. When it's nil, ACTION is called on each marked\ncandidate.\n\nUNWIND is a function of no arguments to call before exiting.\n\nRE-BUILDER is a function transforming input text into a regex\npattern.\n\nMATCHER is a function which can override how candidates are\nfiltered based on user input.  It takes a regex pattern and a\nlist of candidates, and returns the list of matching candidates.\n\nDYNAMIC-COLLECTION is a boolean specifying whether the list of\ncandidates is updated after each input by calling COLLECTION.\n\nEXTRA-PROPS is a plist that can be used to store\ncollection-specific session-specific data.\n\nCALLER is a symbol to uniquely identify the caller to `ivy-read'.\nIt is used, along with COLLECTION, to determine which\ncustomizations apply to the current completion session." #<bytecode 0x1fee720d7c25>) ("Open: " ... :require-match t :keymap ... :re-builder ivy--regex-ignore-order :action or-ivy-bibtex-insert-cite :caller org-ref-ivy-insert-cite-link))
  ivy-posframe--read(#f(compiled-function (arg1 arg2 &rest rest) "Read a string in the minibuffer, with completion.\n\nPROMPT is a string, normally ending in a colon and a space.\n`ivy-count-format' is prepended to PROMPT during completion.\n\nCOLLECTION is either a list of strings, a function, an alist, or\na hash table, supplied for `minibuffer-completion-table'.\n\nPREDICATE is applied to filter out the COLLECTION immediately.\nThis argument is for compatibility with `completing-read'.\n\nWhen REQUIRE-MATCH is non-nil, only members of COLLECTION can be\nselected.\n\nIf INITIAL-INPUT is non-nil, then insert that input in the\nminibuffer initially.\n\nHISTORY is a name of a variable to hold the completion session\nhistory.\n\nKEYMAP is composed with `ivy-minibuffer-map'.\n\nPRESELECT, when non-nil, determines which one of the candidates\nmatching INITIAL-INPUT to select initially.  An integer stands\nfor the position of the desired candidate in the collection,\ncounting from zero.  Otherwise, use the first occurrence of\nPRESELECT in the collection.  Comparison is first done with\n`equal'.  If that fails, and when applicable, match PRESELECT as\na regular expression.\n\nDEF is for compatibility with `completing-read'.\n\nUPDATE-FN is called each time the candidate list is re-displayed.\n\nWhen SORT is non-nil, `ivy-sort-functions-alist' determines how\nto sort candidates before displaying them.\n\nACTION is a function to call after selecting a candidate.\nIt takes one argument, the selected candidate. If COLLECTION is\nan alist, the argument is a cons cell, otherwise it's a string.\n\nMULTI-ACTION, when non-nil, is called instead of ACTION when\nthere are marked candidates. It takes the list of candidates as\nits only argument. When it's nil, ACTION is called on each marked\ncandidate.\n\nUNWIND is a function of no arguments to call before exiting.\n\nRE-BUILDER is a function transforming input text into a regex\npattern.\n\nMATCHER is a function which can override how candidates are\nfiltered based on user input.  It takes a regex pattern and a\nlist of candidates, and returns the list of matching candidates.\n\nDYNAMIC-COLLECTION is a boolean specifying whether the list of\ncandidates is updated after each input by calling COLLECTION.\n\nEXTRA-PROPS is a plist that can be used to store\ncollection-specific session-specific data.\n\nCALLER is a symbol to uniquely identify the caller to `ivy-read'.\nIt is used, along with COLLECTION, to determine which\ncustomizations apply to the current completion session." #<bytecode 0x1fee720d7c25>) "Open: " (... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) :require-match t :keymap (keymap ... ... ... ... ... ... ... ... ...) :re-builder ivy--regex-ignore-order :action or-ivy-bibtex-insert-cite :caller org-ref-ivy-insert-cite-link)
  apply(ivy-posframe--read #f(compiled-function (arg1 arg2 &rest rest) "Read a string in the minibuffer, with completion.\n\nPROMPT is a string, normally ending in a colon and a space.\n`ivy-count-format' is prepended to PROMPT during completion.\n\nCOLLECTION is either a list of strings, a function, an alist, or\na hash table, supplied for `minibuffer-completion-table'.\n\nPREDICATE is applied to filter out the COLLECTION immediately.\nThis argument is for compatibility with `completing-read'.\n\nWhen REQUIRE-MATCH is non-nil, only members of COLLECTION can be\nselected.\n\nIf INITIAL-INPUT is non-nil, then insert that input in the\nminibuffer initially.\n\nHISTORY is a name of a variable to hold the completion session\nhistory.\n\nKEYMAP is composed with `ivy-minibuffer-map'.\n\nPRESELECT, when non-nil, determines which one of the candidates\nmatching INITIAL-INPUT to select initially.  An integer stands\nfor the position of the desired candidate in the collection,\ncounting from zero.  Otherwise, use the first occurrence of\nPRESELECT in the collection.  Comparison is first done with\n`equal'.  If that fails, and when applicable, match PRESELECT as\na regular expression.\n\nDEF is for compatibility with `completing-read'.\n\nUPDATE-FN is called each time the candidate list is re-displayed.\n\nWhen SORT is non-nil, `ivy-sort-functions-alist' determines how\nto sort candidates before displaying them.\n\nACTION is a function to call after selecting a candidate.\nIt takes one argument, the selected candidate. If COLLECTION is\nan alist, the argument is a cons cell, otherwise it's a string.\n\nMULTI-ACTION, when non-nil, is called instead of ACTION when\nthere are marked candidates. It takes the list of candidates as\nits only argument. When it's nil, ACTION is called on each marked\ncandidate.\n\nUNWIND is a function of no arguments to call before exiting.\n\nRE-BUILDER is a function transforming input text into a regex\npattern.\n\nMATCHER is a function which can override how candidates are\nfiltered based on user input.  It takes a regex pattern and a\nlist of candidates, and returns the list of matching candidates.\n\nDYNAMIC-COLLECTION is a boolean specifying whether the list of\ncandidates is updated after each input by calling COLLECTION.\n\nEXTRA-PROPS is a plist that can be used to store\ncollection-specific session-specific data.\n\nCALLER is a symbol to uniquely identify the caller to `ivy-read'.\nIt is used, along with COLLECTION, to determine which\ncustomizations apply to the current completion session." #<bytecode 0x1fee720d7c25>) ("Open: " ... :require-match t :keymap ... :re-builder ivy--regex-ignore-order :action or-ivy-bibtex-insert-cite :caller org-ref-ivy-insert-cite-link))
  ivy-read("Open: " (... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) :require-match t :keymap (keymap ... ... ... ... ... ... ... ... ...) :re-builder ivy--regex-ignore-order :action or-ivy-bibtex-insert-cite :caller org-ref-ivy-insert-cite-link)
  org-ref-ivy-insert-cite-link()
  org-ref-insert-link(nil)
  funcall-interactively(org-ref-insert-link nil)
  call-interactively(org-ref-insert-link nil nil)
  command-execute(org-ref-insert-link)

GNU Emacs 27.1 (build 1, x86_64-apple-darwin19.6.0, NS appkit-1894.60 Version 10.15.6 (Build 19G2021)) of 2020-08-25

jkitchin commented 4 years ago

Can you provide a way to reproduce this? I don't see this.

tshu-w commented 4 years ago

sorry, here is my minimal config to reproduce this, you can change bibliography list to yours:

;;; emacs -nw -Q -l ~/.emacs.d/test.el

(setq package-archives '(("melpa" . "https://melpa.org/packages/")
                         ("org"   . "https://orgmode.org/elpa/")
                         ("gnu"   . "https://elpa.gnu.org/packages/")))

;; initialize packages
(unless (bound-and-true-p package--initialized) ; To avoid warnings in 27
  (setq package-enable-at-startup nil)          ; To prevent initializing twice
  (package-initialize))

;; setup `use-package'
(unless (package-installed-p 'use-package)
  (when (not package-archive-contents)
    (package-refresh-contents))
  (package-install 'use-package))

(require 'use-package)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(use-package org-ref
  :ensure t
  :after (:any org autex bibtex)
  :init
  (setq org-ref-completion-library 'org-ref-ivy-cite)
  :config
  (setq reftex-default-bibliography '("~/Documents/Zotero/references.bib")

        org-ref-default-bibliography '("~/Documents/Zotero/references.bib")
        org-ref-bibliography-notes "~/Documents/Org/notes/papers/")

  ;; (use-package bibtex-completion
  ;;   :commands (bibtex-completion-edit-notes bibtex-completion-find-pdf)
  ;;   :init
  ;;   (setq bibtex-autokey-year-length 4
  ;;         bibtex-completion-additional-search-fields '(keywords)
  ;;         bibtex-completion-bibliography '("~/Documents/Zotero/references.bib")
  ;;         bibtex-completion-library-path '("~/Documents/Zotero/storage/")
  ;;         bibtex-completion-notes-path "~/Documents/Org/notes/papers/"
  ;;         bibtex-completion-notes-template-multiple-files
  ;;         "#+title: ${author-or-editor} (${year}): ${title}\n#+roam_key: cite:${=key=}\n\n"
  ;;         bibtex-completion-pdf-field "file"
  ;;         bibtex-dialect 'biblatex))

  ;; ;; Tell org-ref to let bibtex-completion find notes for it
  ;; (setq org-ref-notes-function
  ;;       (lambda (citekey)
    ;;         (let ((bibtex-completion-bibliography (org-ref-find-bibliography)))
    ;;           (bibtex-completion-edit-notes
    ;;            (list (car (org-ref-get-bibtex-key-and-file citekey)))))))

  ;; ;; Override `org-ref-open-pdf-at-point' directly since `H-p' is bound to it.
  ;; (defun org-ref-open-pdf-at-point ()
  ;;   "Open the pdf for bibtex key under point if it exists."
  ;;   (interactive)
  ;;   (let* ((results (org-ref-get-bibtex-key-and-file))
  ;;          (key (car results))
  ;;          (pdf-file (car (bibtex-completion-find-pdf key))))
  ;;     (if (file-exists-p pdf-file)
  ;;         (org-open-file pdf-file)
  ;;       (message "No PDF found for %s" key))))

  ;; (defun org-ref-list-index (substring list)
  ;;   "Return the index of SUBSTRING in a LIST of strings."
  ;;   (let ((i 0)
  ;;         (found nil))
  ;;     (cl-dolist (arg list i)
  ;;       (if (string-match (concat "^" substring "$") arg)
  ;;           (progn
  ;;             (setq found t)
  ;;             (cl-return i)))
  ;;       (setq i (+ i 1)))
  ;;     ;; return counter if found, otherwise return nil
  ;;     (if found i nil)))
  )

reproduce steps

  1. emacs -nw -Q -l ~/.emacs.d/test.el
  2. call M-x org-ref-insert-link twice.
  3. error will throw on the second inserting.

I change dolist to cl-dolist in org-ref-list-index and works fine on my side.

jkitchin commented 4 years ago

I think the simplest solution might be just change dolist to cl-dolist. I have pushed that. Does that fix this issue?

tshu-w commented 4 years ago

yes, it fixed. thx you.