Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

counsel.el (counsel-library-candidates): check dirs in load-path exists #1720

Conversation

edkolev
Copy link
Contributor

@edkolev edkolev commented Aug 17, 2018

This PR fixes the following issue for me:

M-x counsel-find-library causes the following error on macOS:

Debugger entered--Lisp error: (file-missing "Opening directory" "No such file or directory" "/Library/Application Support/Emacs/26.1/site-lisp")
  file-name-all-completions("" "/Library/Application Support/Emacs/26.1/site-lisp")
  (let ((--dolist-tail-- (file-name-all-completions "" (or dir default-directory)))) (while --dolist-tail-- (let ((file (car --dolist-tail--))) (if (string-match suffix file) (progn (if (string-match "pkg.elc?$" file) nil (setq short-name (substring file 0 (match-beginning 0))) (if (setq old-val (gethash short-name cands)) (progn (setq dir-parent (counsel-directory-name (cdr old-val))) (puthash short-name (cons (counsel-string-compose dir-parent (car old-val)) (cdr old-val)) cands) (setq dir-parent (counsel-directory-name dir)) (puthash (concat dir-parent short-name) (cons (propertize (counsel-string-compose dir-parent short-name) 'full-name (expand-file-name file dir)) dir) cands)) (puthash short-name (cons (propertize short-name 'full-name (expand-file-name file dir)) dir) cands))))) (setq --dolist-tail-- (cdr --dolist-tail--)))))
  (let ((dir (car --dolist-tail--))) (let ((--dolist-tail-- (file-name-all-completions "" (or dir default-directory)))) (while --dolist-tail-- (let ((file (car --dolist-tail--))) (if (string-match suffix file) (progn (if (string-match "pkg.elc?$" file) nil (setq short-name (substring file 0 (match-beginning 0))) (if (setq old-val (gethash short-name cands)) (progn (setq dir-parent (counsel-directory-name (cdr old-val))) (puthash short-name (cons (counsel-string-compose dir-parent (car old-val)) (cdr old-val)) cands) (setq dir-parent (counsel-directory-name dir)) (puthash (concat dir-parent short-name) (cons (propertize (counsel-string-compose dir-parent short-name) 'full-name (expand-file-name file dir)) dir) cands)) (puthash short-name (cons (propertize short-name 'full-name (expand-file-name file dir)) dir) cands))))) (setq --dolist-tail-- (cdr --dolist-tail--))))) (setq --dolist-tail-- (cdr --dolist-tail--)))
  (while --dolist-tail-- (let ((dir (car --dolist-tail--))) (let ((--dolist-tail-- (file-name-all-completions "" (or dir default-directory)))) (while --dolist-tail-- (let ((file (car --dolist-tail--))) (if (string-match suffix file) (progn (if (string-match "pkg.elc?$" file) nil (setq short-name (substring file 0 (match-beginning 0))) (if (setq old-val (gethash short-name cands)) (progn (setq dir-parent (counsel-directory-name (cdr old-val))) (puthash short-name (cons (counsel-string-compose dir-parent (car old-val)) (cdr old-val)) cands) (setq dir-parent (counsel-directory-name dir)) (puthash (concat dir-parent short-name) (cons (propertize (counsel-string-compose dir-parent short-name) 'full-name (expand-file-name file dir)) dir) cands)) (puthash short-name (cons (propertize short-name 'full-name (expand-file-name file dir)) dir) cands))))) (setq --dolist-tail-- (cdr --dolist-tail--))))) (setq --dolist-tail-- (cdr --dolist-tail--))))
  (let ((--dolist-tail-- load-path)) (while --dolist-tail-- (let ((dir (car --dolist-tail--))) (let ((--dolist-tail-- (file-name-all-completions "" (or dir default-directory)))) (while --dolist-tail-- (let ((file (car --dolist-tail--))) (if (string-match suffix file) (progn (if (string-match "pkg.elc?$" file) nil (setq short-name (substring file 0 (match-beginning 0))) (if (setq old-val (gethash short-name cands)) (progn (setq dir-parent (counsel-directory-name (cdr old-val))) (puthash short-name (cons (counsel-string-compose dir-parent (car old-val)) (cdr old-val)) cands) (setq dir-parent (counsel-directory-name dir)) (puthash (concat dir-parent short-name) (cons (propertize (counsel-string-compose dir-parent short-name) 'full-name (expand-file-name file dir)) dir) cands)) (puthash short-name (cons (propertize short-name 'full-name (expand-file-name file dir)) dir) cands))))) (setq --dolist-tail-- (cdr --dolist-tail--))))) (setq --dolist-tail-- (cdr --dolist-tail--)))))
  (let ((suffix (concat (regexp-opt '(".el" ".el.gz") t) "\\'")) (cands (make-hash-table :test (function equal))) short-name old-val dir-parent res) (let ((--dolist-tail-- load-path)) (while --dolist-tail-- (let ((dir (car --dolist-tail--))) (let ((--dolist-tail-- (file-name-all-completions "" (or dir default-directory)))) (while --dolist-tail-- (let ((file (car --dolist-tail--))) (if (string-match suffix file) (progn (if (string-match "pkg.elc?$" file) nil (setq short-name (substring file 0 (match-beginning 0))) (if (setq old-val (gethash short-name cands)) (progn (setq dir-parent (counsel-directory-name (cdr old-val))) (puthash short-name (cons (counsel-string-compose dir-parent (car old-val)) (cdr old-val)) cands) (setq dir-parent (counsel-directory-name dir)) (puthash (concat dir-parent short-name) (cons (propertize (counsel-string-compose dir-parent short-name) 'full-name (expand-file-name file dir)) dir) cands)) (puthash short-name (cons (propertize short-name 'full-name (expand-file-name file dir)) dir) cands))))) (setq --dolist-tail-- (cdr --dolist-tail--))))) (setq --dolist-tail-- (cdr --dolist-tail--))))) (maphash (function (lambda (_k v) (setq res (cons (car v) res)))) cands) (nreverse res))
  counsel-library-candidates()
  counsel-find-library()
  funcall-interactively(counsel-find-library)
  call-interactively(counsel-find-library)

For some reason, /Library/Application Support/Emacs/26.1/site-lisp is in my load-path, but the dir doesn't exist.

Looking at find-library's code, I see that it also runs file-directory-p (in locate-file-completion-table). Note: find-library works fine, it doesn't cause the same error as counsel-find-library

@edkolev
Copy link
Contributor Author

@edkolev edkolev commented Aug 17, 2018

Here's the diff w/o whitespace changes: https://github.com/abo-abo/swiper/pull/1720/files?w=1

@basil-conto
Copy link
Collaborator

@basil-conto basil-conto commented Aug 17, 2018

Re-adding the file-directory-p check (removing it was clearly a mistake on my part; sorry) means that nil entries in load-path are no longer interpreted as default-directory. Perhaps something like the following would be better:

(when (file-directory-p (or dir (setq dir default-directory)))
  (dolist (file (file-name-all-completions "" dir))
    ...))

(I'm currently AFK, so guaranteed 100% untested.)

@edkolev edkolev force-pushed the counsel-library-candidates-check-dirs-exists branch from 5d57222 to f81cbdc Compare Aug 17, 2018
@edkolev
Copy link
Contributor Author

@edkolev edkolev commented Aug 17, 2018

I've pushed a commit which interprets nil as default-directory. Let me know if I should modify it further.

@andschwa
Copy link
Contributor

@andschwa andschwa commented Aug 18, 2018

Weird, this is happening to me too @edkolev... wonder why it is.

Edit: If you mkdir that directory, the next that comes up is ../site-lisp from there. mkdir that and all is well. Still funny.

@edkolev
Copy link
Contributor Author

@edkolev edkolev commented Aug 18, 2018

As mentioned above, a recent commit has caused this regression, probably this one 16a5352

I would suggest you don't bother mkdir-ing paths, just use find-library until this issue is resolved.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Aug 20, 2018

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants