oantolin / orderless

Emacs completion style that matches multiple regexps in any order

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

org-refile induces a lisp level error from orderless

matta opened this issue · comments

The particular way I have org-refile configured seems to cause orderless to throw a lisp level error. Perhaps there is something unusual in the completion tables that org is generating?

Repro:

In a scratch or temp directory somewhere create these files:

repro-orderless.el:

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(unless (package-installed-p 'orderless)
  (package-refresh-contents)
  (package-install 'orderless))
(require 'orderless)

(setq original-completion-styles completion-styles)

(defun toggle-orderless ()
  (interactive)
  (setq completion-styles
	(if (equal completion-styles original-completion-styles)
	    '(orderless)
	  original-completion-styles))
  (message "completion-styles is now %s" completion-styles))

(toggle-orderless)

(setq org-refile-use-outline-path 'file)

sample.org

* Heading One
** Subheading A
** Subheading B
* Heading Two
** Subheading C
** Subheading D

run-emacs.sh:

#!/bin/sh
user_emacs_directory=$(pwd)/emacs.d/
mkdir -p "${user_emacs_directory}"
emacs -Q --execute "(setq user-emacs-directory \"${user_emacs_directory}\")" --load repro-orderless.el

Then:

  1. sh run-emacs.sh
  2. Edit sample.org
  3. Place the cursor on "Subheading D"
  4. Execute C-x C-w or M-x org-refile.
  5. Type "two" into the minibuffer.
  6. Press TAB

Expected:

Since I set (setq org-refile-use-outline-path 'file) I expect some sort of completion over the file+heading strings.

Actual:

orderless displays a lisp level error: completion--some: Wrong type argument: characterp, "sample.org/Heading Two/"

When I enable debugging on error I get this:

Debugger entered--Lisp error: (wrong-type-argument characterp "sample.org/Heading Two/")
  orderless-try-completion("two" #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil 3)
  #f(compiled-function (style) #<bytecode 0x11b90bdb948d907b>)(orderless)
  completion--some(#f(compiled-function (style) #<bytecode 0x11b90bdb948d907b>) (orderless))
  completion--nth-completion(1 "two" #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil 3 (metadata))
  completion-try-completion("two" #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil 3 (metadata))
  completion--do-completion(57 60)
  completion--in-region-1(57 60)
  #f(compiled-function (start end collection predicate) #<bytecode 0x111a22a86a24cd5d>)(57 60 #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil)
  apply(#f(compiled-function (start end collection predicate) #<bytecode 0x111a22a86a24cd5d>) (57 60 #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil))
  #f(compiled-function (funs global args) #<bytecode -0xf66db1d121e122>)(nil nil (57 60 #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil))
  completion--in-region(57 60 #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil)
  completion-in-region(57 60 #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil)
  minibuffer-complete()
  funcall-interactively(minibuffer-complete)
  call-interactively(minibuffer-complete nil nil)
  command-execute(minibuffer-complete)
  read-from-minibuffer("Refile subtree \"Subheading D\" to (default sample.o..." nil (keymap (10 . minibuffer-complete-and-exit) (13 . minibuffer-complete-and-exit) keymap (menu-bar keymap (minibuf "Minibuf" keymap (tab menu-item "Complete" minibuffer-complete :help "Complete as far as possible") (space menu-item "Complete Word" minibuffer-complete-word :help "Complete at most one word") (63 menu-item "List Completions" minibuffer-completion-help :help "Display all possible completions") "Minibuf")) (27 keymap (103 keymap (27 keymap (99 . switch-to-completions))) (118 . switch-to-completions)) (prior . switch-to-completions) (63 . minibuffer-completion-help) (32 . minibuffer-complete-word) (9 . minibuffer-complete) keymap (menu-bar keymap (minibuf "Minibuf" keymap (previous menu-item "Previous History Item" previous-history-element :help "Put previous minibuffer history element in the min...") (next menu-item "Next History Item" next-history-element :help "Put next minibuffer history element in the minibuf...") (isearch-backward menu-item "Isearch History Backward" isearch-backward :help "Incrementally search minibuffer history backward") (isearch-forward menu-item "Isearch History Forward" isearch-forward :help "Incrementally search minibuffer history forward") (return menu-item "Enter" exit-minibuffer :key-sequence "\15" :help "Terminate input and exit minibuffer") (quit menu-item "Quit" abort-recursive-edit :help "Abort input and exit minibuffer") "Minibuf")) (13 . exit-minibuffer) (10 . exit-minibuffer) (7 . abort-minibuffers) (C-tab . file-cache-minibuffer-complete) (9 . self-insert-command) (XF86Back . previous-history-element) (up . previous-line-or-history-element) (prior . previous-history-element) (XF86Forward . next-history-element) (down . next-line-or-history-element) (next . next-history-element) (27 keymap (60 . minibuffer-beginning-of-buffer) (114 . previous-matching-history-element) (115 . next-matching-history-element) (112 . previous-history-element) (110 . next-history-element))) nil org-refile-history "sample.org/" nil)
  completing-read-default("Refile subtree \"Subheading D\" to (default sample.o..." #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil t nil org-refile-history "sample.org/" nil)
  completing-read("Refile subtree \"Subheading D\" to (default sample.o..." #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil t nil org-refile-history "sample.org/" nil)
  apply(completing-read "Refile subtree \"Subheading D\" to (default sample.o..." #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) (nil t nil org-refile-history "sample.org/"))
  org-olpath-completing-read("Refile subtree \"Subheading D\" to (default sample.o..." (("sample.org/" "/home/matt/scratch/orderless/sample.org" nil nil) ("sample.org/Heading One/" "/home/matt/scratch/orderless/sample.org" "^\\(\\*+\\)\\(?: +\\(DONE\\|TODO\\)\\)?\\(?: +\\(\\[#.\\]\\)\\)?..." 1) ("sample.org/Heading Two/" "/home/matt/scratch/orderless/sample.org" "^\\(\\*+\\)\\(?: +\\(DONE\\|TODO\\)\\)?\\(?: +\\(\\[#.\\]\\)\\)?..." 47)) nil t nil org-refile-history "sample.org/")
  org-refile-get-location("Refile subtree \"Subheading D\" to" nil nil)
  org-refile(nil)
  funcall-interactively(org-refile nil)
  call-interactively(org-refile nil nil)
  command-execute(org-refile)

Again with a non-byte-compiled orderless-try-completion function:

Debugger entered--Lisp error: (wrong-type-argument characterp "sample.org/Heading Two/")
  concat("" ("sample.org/Heading Two/" "/home/matt/scratch/orderless/sample.org" "^\\(\\*+\\)\\(?: +\\(DONE\\|TODO\\)\\)?\\(?: +\\(\\[#.\\]\\)\\)?..." 47))
  (setq one (concat (car (orderless--prefix+pattern string table pred)) one))
  (if (equal string one) t (setq one (concat (car (orderless--prefix+pattern string table pred)) one)) (cons one (length one)))
  (progn (if (equal string one) t (setq one (concat (car (orderless--prefix+pattern string table pred)) one)) (cons one (length one))))
  (if one (progn (if (equal string one) t (setq one (concat (car (orderless--prefix+pattern string table pred)) one)) (cons one (length one)))))
  (let (one) (orderless-filter string table #'(lambda (&rest args) (if (or (not pred) (apply pred args)) (progn (if one (progn ...)) (setq one (car args) one (if ... ... args) one (if ... ... one)))) nil)) (if one (progn (if (equal string one) t (setq one (concat (car (orderless--prefix+pattern string table pred)) one)) (cons one (length one))))))
  (catch 'orderless--many (let (one) (orderless-filter string table #'(lambda (&rest args) (if (or (not pred) (apply pred args)) (progn (if one ...) (setq one ... one ... one ...))) nil)) (if one (progn (if (equal string one) t (setq one (concat (car ...) one)) (cons one (length one)))))))
  orderless-try-completion("two" #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil 3)
  #f(compiled-function (style) #<bytecode 0x11b90bdb948d907b>)(orderless)
  completion--some(#f(compiled-function (style) #<bytecode 0x11b90bdb948d907b>) (orderless))
  completion--nth-completion(1 "two" #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil 3 (metadata))
  completion-try-completion("two" #f(compiled-function (string predicate &optional flag) #<bytecode -0x7d184d17f8ee644>) nil 3 (metadata))
  completion--do-completion(57 60)
  completion--in-region-1(57 60)

I think I just came across the same error in a different context and fixed it. Please test this commit: 1ccf74f

@oantolin that commit fixed it, thanks!