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

Unregistered definition type ‘defalias’ #30

Closed
CeleritasCelery opened this issue Aug 21, 2018 · 6 comments
Closed

Unregistered definition type ‘defalias’ #30

CeleritasCelery opened this issue Aug 21, 2018 · 6 comments
Labels

Comments

@CeleritasCelery
Copy link

I am trying to advise the ielm function and I am getting the following fatal error.
Unregistered definition type ‘defalias’. Here is my code

(el-patch-defun ielm ()
      "Interactively evaluate Emacs Lisp expressions.
  Switches to the buffer `*ielm*', or creates it if it does not exist.
  See `inferior-emacs-lisp-mode' for details."
      (interactive)
      (let (old-point)
        (unless (comint-check-proc "*ielm*")
          (with-current-buffer (get-buffer-create "*ielm*")
            (unless (zerop (buffer-size)) (setq old-point (point)))
            (inferior-emacs-lisp-mode)))
        (el-patch-swap (pop-to-buffer-same-window "*ielm*")
                       (progn (split-window)
                              (pop-to-buffer "*ielm*")))
        (when old-point (push-mark old-point))))

Here is the stack trace

Debugger entered--Lisp error: (error "Unregistered definition type ‘defalias’")
  signal(error ("Unregistered definition type ‘defalias’"))
  error("Unregistered definition type `%S'" defalias)
  #f(compiled-function (definition &optional docstring-note) "Evaluate DEFINITION without updating `load-history'.\nDEFINITION should be an unquoted list beginning with `defun',\n`defmacro', `define-minor-mode', etc. DOCSTRING-NOTE, if given,\nis a sentence to put in brackets at the end of the docstring." #<bytecode 0xbe7bd1>)((defalias 'ielm (function (lambda nil "Interactively evaluate Emacs Lisp expressions.\nSwitches to the buffer `*ielm*', or creates it if it does not exist.\nSee `inferior-emacs-lisp-mode' for details." (interactive) (let (old-point) (if (comint-check-proc "*ielm*") nil (save-current-buffer (set-buffer (get-buffer-create "*ielm*")) (if (= 0 (buffer-size)) nil (setq old-point (point))) (inferior-emacs-lisp-mode))) (error "Can't use `el-patch-swap' outside of an `el-patch'") (if old-point (progn (push-mark old-point))))))) "This function was patched by `el-patch'.")
  (el-patch--stealthy-eval (defalias 'ielm (function (lambda nil "Interactively evaluate Emacs Lisp expressions.\nSwitches to the buffer `*ielm*', or creates it if it does not exist.\nSee `inferior-emacs-lisp-mode' for details." (interactive) (let (old-point) (if (comint-check-proc "*ielm*") nil (save-current-buffer (set-buffer (get-buffer-create "*ielm*")) (if (= 0 (buffer-size)) nil (setq old-point (point))) (inferior-emacs-lisp-mode))) (error "Can't use `el-patch-swap' outside of an `el-patch'") (if old-point (progn (push-mark old-point))))))) "This function was patched by `el-patch'.")
  (progn (puthash 'defalias '(defalias 'ielm (function (lambda nil "Interactively evaluate Emacs Lisp expressions.\nSwitches to the buffer `*ielm*', or creates it if it does not exist.\nSee `inferior-emacs-lisp-mode' for details." (interactive) (let (old-point) (if (comint-check-proc "*ielm*") nil (save-current-buffer (set-buffer (get-buffer-create "*ielm*")) (if (= 0 (buffer-size)) nil (setq old-point (point))) (inferior-emacs-lisp-mode))) (error "Can't use `el-patch-swap' outside of an `el-patch'") (if old-point (progn (push-mark old-point))))))) (or (gethash ''ielm el-patch--patches) (puthash ''ielm (make-hash-table :test (function equal)) el-patch--patches))) (el-patch--stealthy-eval (defalias 'ielm (function (lambda nil "Interactively evaluate Emacs Lisp expressions.\nSwitches to the buffer `*ielm*', or creates it if it does not exist.\nSee `inferior-emacs-lisp-mode' for details." (interactive) (let (old-point) (if (comint-check-proc "*ielm*") nil (save-current-buffer (set-buffer (get-buffer-create "*ielm*")) (if (= 0 (buffer-size)) nil (setq old-point (point))) (inferior-emacs-lisp-mode))) (error "Can't use `el-patch-swap' outside of an `el-patch'") (if old-point (progn (push-mark old-point))))))) "This function was patched by `el-patch'."))
  (el-patch--definition (defalias 'ielm (function (lambda nil "Interactively evaluate Emacs Lisp expressions.\nSwitches to the buffer `*ielm*', or creates it if it does not exist.\nSee `inferior-emacs-lisp-mode' for details." (interactive) (let (old-point) (if (comint-check-proc "*ielm*") nil (save-current-buffer (set-buffer (get-buffer-create "*ielm*")) (if (= 0 (buffer-size)) nil (setq old-point (point))) (inferior-emacs-lisp-mode))) (error "Can't use `el-patch-swap' outside of an `el-patch'") (if old-point (progn (push-mark old-point))))))))
  (closure (bootstrap-version t) nil (el-patch--definition (defalias 'ielm (function (lambda nil "Interactively evaluate Emacs Lisp expressions.\nSwitches to the buffer `*ielm*', or creates it if it does not exist.\nSee `inferior-emacs-lisp-mode' for details." (interactive) (let (old-point) (if (comint-check-proc "*ielm*") nil (save-current-buffer (set-buffer (get-buffer-create "*ielm*")) (if (= 0 (buffer-size)) nil (setq old-point (point))) (inferior-emacs-lisp-mode))) (error "Can't use `el-patch-swap' outside of an `el-patch'") (if old-point (progn (push-mark old-point)))))))))()
  eval-after-load-helper("/usr/intel/pkgs/emacs/26.1/share/emacs/26.1/lisp/ielm.elc")
  run-hook-with-args(eval-after-load-helper "/usr/intel/pkgs/emacs/26.1/share/emacs/26.1/lisp/ielm.elc")
  do-after-load-evaluation("/usr/intel/pkgs/emacs/26.1/share/emacs/26.1/lisp/ielm.elc")
  autoload-do-load((autoload "ielm" 1234208 t nil) ielm)
  command-execute(ielm)
@raxod502
Copy link
Member

This works if I evaluate it in *scratch*, and also appears to expand to different code than appears in your stack trace if I byte-compile it.

Are you perhaps byte-compiling your code without having el-patch loaded at byte-compilation time?

@CeleritasCelery
Copy link
Author

looks like you are correct. I can eval in the scratch buffer and it works. I missed your clear instructions about this in the README 😟

@Fuco1
Copy link
Contributor

Fuco1 commented Jan 27, 2019

I have this same problem. I'm patching org-attach-annex-get-maybe and when org-attach autoloads el-patch gives me

Debugger entered--Lisp error: (error "Unregistered definition type ‘defalias’")
  signal(error ("Unregistered definition type ‘defalias’"))
  error("Unregistered definition type `%S'" defalias)
  #f(compiled-function (definition &optional docstring-note) "Evaluate DEFINITION without updating `load-history'.\nDEFINITION should be an unquoted list beginning with `defun',\n`defmacro', `define-minor-mode', etc. DOCSTRING-NOTE, if given,\nis a sentence to put in brackets at the end of the docstring." #<bytecode 0xa5e5b9>)((defalias 'org-attach-annex-get-maybe (function (lambda (path) "Call git annex get PATH (via shell) if using git annex.\nSignals an error if the file content is not available and it was not retrieved." (let* ((default-directory (expand-file-name org-attach-directory)) (path-relative (file-relative-name path))) (if (and (org-attach-use-annex) (not (string-equal (error "Can't use `el-patch-swap' outside of an `el-patch'") (shell-command-to-string (format "git annex find --format=found --in=here %s" (shell-quote-argument path-relative)))))) (progn (let ((should-get (if (eq org-attach-annex-auto-get 'ask) (y-or-n-p (format "Run git annex get %s? " path-relative)) org-attach-annex-auto-get))) (if should-get (progn (message "Running git annex get \"%s\"." path-relative) (call-process "git" nil nil nil "annex" "get" path-relative)) (error "File %s stored in git annex but it is not available, and was not retrieved" path))))))))) "This function was patched by `el-patch'.")
  (el-patch--stealthy-eval (defalias 'org-attach-annex-get-maybe (function (lambda (path) "Call git annex get PATH (via shell) if using git annex.\nSignals an error if the file content is not available and it was not retrieved." (let* ((default-directory (expand-file-name org-attach-directory)) (path-relative (file-relative-name path))) (if (and (org-attach-use-annex) (not (string-equal (error "Can't use `el-patch-swap' outside of an `el-patch'") (shell-command-to-string (format "git annex find --format=found --in=here %s" (shell-quote-argument path-relative)))))) (progn (let ((should-get (if (eq org-attach-annex-auto-get 'ask) (y-or-n-p (format "Run git annex get %s? " path-relative)) org-attach-annex-auto-get))) (if should-get (progn (message "Running git annex get \"%s\"." path-relative) (call-process "git" nil nil nil "annex" "get" path-relative)) (error "File %s stored in git annex but it is not available, and was not retrieved" path))))))))) "This function was patched by `el-patch'.")
  (progn (puthash 'defalias '(defalias 'org-attach-annex-get-maybe (function (lambda (path) "Call git annex get PATH (via shell) if using git annex.\nSignals an error if the file content is not available and it was not retrieved." (let* ((default-directory (expand-file-name org-attach-directory)) (path-relative (file-relative-name path))) (if (and (org-attach-use-annex) (not (string-equal (error "Can't use `el-patch-swap' outside of an `el-patch'") (shell-command-to-string (format "git annex find --format=found --in=here %s" (shell-quote-argument path-relative)))))) (progn (let ((should-get (if (eq org-attach-annex-auto-get 'ask) (y-or-n-p (format "Run git annex get %s? " path-relative)) org-attach-annex-auto-get))) (if should-get (progn (message "Running git annex get \"%s\"." path-relative) (call-process "git" nil nil nil "annex" "get" path-relative)) (error "File %s stored in git annex but it is not available, and was not retrieved" path))))))))) (or (gethash ''org-attach-annex-get-maybe el-patch--patches) (puthash ''org-attach-annex-get-maybe (make-hash-table :test (function equal)) el-patch--patches))) (el-patch--stealthy-eval (defalias 'org-attach-annex-get-maybe (function (lambda (path) "Call git annex get PATH (via shell) if using git annex.\nSignals an error if the file content is not available and it was not retrieved." (let* ((default-directory (expand-file-name org-attach-directory)) (path-relative (file-relative-name path))) (if (and (org-attach-use-annex) (not (string-equal (error "Can't use `el-patch-swap' outside of an `el-patch'") (shell-command-to-string (format "git annex find --format=found --in=here %s" (shell-quote-argument path-relative)))))) (progn (let ((should-get (if (eq org-attach-annex-auto-get 'ask) (y-or-n-p (format "Run git annex get %s? " path-relative)) org-attach-annex-auto-get))) (if should-get (progn (message "Running git annex get \"%s\"." path-relative) (call-process "git" nil nil nil "annex" "get" path-relative)) (error "File %s stored in git annex but it is not available, and was not retrieved" path))))))))) "This function was patched by `el-patch'."))
  (el-patch--definition (defalias 'org-attach-annex-get-maybe (function (lambda (path) "Call git annex get PATH (via shell) if using git annex.\nSignals an error if the file content is not available and it was not retrieved." (let* ((default-directory (expand-file-name org-attach-directory)) (path-relative (file-relative-name path))) (if (and (org-attach-use-annex) (not (string-equal (error "Can't use `el-patch-swap' outside of an `el-patch'") (shell-command-to-string (format "git annex find --format=found --in=here %s" (shell-quote-argument path-relative)))))) (progn (let ((should-get (if (eq org-attach-annex-auto-get 'ask) (y-or-n-p (format "Run git annex get %s? " path-relative)) org-attach-annex-auto-get))) (if should-get (progn (message "Running git annex get \"%s\"." path-relative) (call-process "git" nil nil nil "annex" "get" path-relative)) (error "File %s stored in git annex but it is not available, and was not retrieved" path))))))))))
  (progn (el-patch--definition (defalias 'org-attach-annex-get-maybe (function (lambda (path) "Call git annex get PATH (via shell) if using git annex.\nSignals an error if the file content is not available and it was not retrieved." (let* ((default-directory (expand-file-name org-attach-directory)) (path-relative (file-relative-name path))) (if (and (org-attach-use-annex) (not (string-equal (error "Can't use `el-patch-swap' outside of an `el-patch'") (shell-command-to-string (format "git annex find --format=found --in=here %s" (shell-quote-argument path-relative)))))) (progn (let ((should-get (if (eq org-attach-annex-auto-get 'ask) (y-or-n-p (format "Run git annex get %s? " path-relative)) org-attach-annex-auto-get))) (if should-get (progn (message "Running git annex get \"%s\"." path-relative) (call-process "git" nil nil nil "annex" "get" path-relative)) (error "File %s stored in git annex but it is not available, and was not retrieved" path)))))))))))
  (lambda nil (progn (el-patch--definition (defalias 'org-attach-annex-get-maybe (function (lambda (path) "Call git annex get PATH (via shell) if using git annex.\nSignals an error if the file content is not available and it was not retrieved." (let* ((default-directory (expand-file-name org-attach-directory)) (path-relative (file-relative-name path))) (if (and (org-attach-use-annex) (not (string-equal (error "Can't use `el-patch-swap' outside of an `el-patch'") (shell-command-to-string (format "git annex find --format=found --in=here %s" (shell-quote-argument path-relative)))))) (progn (let ((should-get (if (eq org-attach-annex-auto-get 'ask) (y-or-n-p (format "Run git annex get %s? " path-relative)) org-attach-annex-auto-get))) (if should-get (progn (message "Running git annex get \"%s\"." path-relative) (call-process "git" nil nil nil "annex" "get" path-relative)) (error "File %s stored in git annex but it is not available, and was not retrieved" path))))))))))))()
  funcall((lambda nil (progn (el-patch--definition (defalias 'org-attach-annex-get-maybe (function (lambda (path) "Call git annex get PATH (via shell) if using git annex.\nSignals an error if the file content is not available and it was not retrieved." (let* ((default-directory (expand-file-name org-attach-directory)) (path-relative (file-relative-name path))) (if (and (org-attach-use-annex) (not (string-equal (error "Can't use `el-patch-swap' outside of an `el-patch'") (shell-command-to-string (format "git annex find --format=found --in=here %s" (shell-quote-argument path-relative)))))) (progn (let ((should-get (if (eq org-attach-annex-auto-get 'ask) (y-or-n-p (format "Run git annex get %s? " path-relative)) org-attach-annex-auto-get))) (if should-get (progn (message "Running git annex get \"%s\"." path-relative) (call-process "git" nil nil nil "annex" "get" path-relative)) (error "File %s stored in git annex but it is not available, and was not retrieved" path)))))))))))))
  mapc(funcall ((lambda nil (progn (el-patch--definition (defalias 'org-attach-annex-get-maybe (function (lambda (path) "Call git annex get PATH (via shell) if using git annex.\nSignals an error if the file content is not available and it was not retrieved." (let* ((default-directory (expand-file-name org-attach-directory)) (path-relative (file-relative-name path))) (if (and (org-attach-use-annex) (not (string-equal (error "Can't use `el-patch-swap' outside of an `el-patch'") (shell-command-to-string (format "git annex find --format=found --in=here %s" (shell-quote-argument path-relative)))))) (progn (let ((should-get (if (eq org-attach-annex-auto-get 'ask) (y-or-n-p (format "Run git annex get %s? " path-relative)) org-attach-annex-auto-get))) (if should-get (progn (message "Running git annex get \"%s\"." path-relative) (call-process "git" nil nil nil "annex" "get" path-relative)) (error "File %s stored in git annex but it is not available, and was not retrieved" path)))))))))))) (lambda nil (progn (progn (puthash 'defun '(defun org-attach-annex-get-maybe (path) "Call git annex get PATH (via shell) if using git annex.\nSignals an error if the file content is not available and it was not retrieved." (let* ((default-directory (expand-file-name org-attach-directory)) (path-relative (file-relative-name path))) (when (and (org-attach-use-annex) (not (string-equal (el-patch-swap "found" "\nfound") (shell-command-to-string (format "git annex find --format=found --in=here %s" (shell-quote-argument path-relative)))))) (let ((should-get (if (eq org-attach-annex-auto-get 'ask) (y-or-n-p (format "Run git annex get %s? " path-relative)) org-attach-annex-auto-get))) (if should-get (progn (message "Running git annex get \"%s\"." path-relative) (call-process "git" nil nil nil "annex" "get" path-relative)) (error "File %s stored in git annex but it is not available, and was not retrieved" path)))))) (or (gethash 'org-attach-annex-get-maybe el-patch--patches) (puthash 'org-attach-annex-get-maybe (make-hash-table :test (function equal)) el-patch--patches))) (prog2 (progn) (defalias 'org-attach-annex-get-maybe (function (lambda (path) "Call git annex get PATH (via shell) if using git annex.\nSignals an error if the file content is not available and it was not retrieved.\n\n[This function was patched by `el-patch'.]" (let* ((default-directory (expand-file-name org-attach-directory)) (path-relative (file-relative-name path))) (if (and (org-attach-use-annex) (not (string-equal "\nfound" (shell-command-to-string (format "git annex find --format=found --in=here %s" (shell-quote-argument path-relative)))))) (progn (let ((should-get (if (eq org-attach-annex-auto-get 'ask) (y-or-n-p (format "Run git annex get %s? " path-relative)) org-attach-annex-auto-get))) (if should-get (progn (message "Running git annex get \"%s\"." path-relative) (call-process "git" nil nil nil "annex" "get" path-relative)) (error "File %s stored in git annex but it is not available, and was not retrieved" path))))))))) (setq current-load-list (remove '(defun . org-attach-annex-get-maybe) current-load-list))))))))
  do-after-load-evaluation("/home/matus/.emacs.d/.cask/26.1/elpa/org-plus-contrib-20181126/org-attach.elc")
  autoload-do-load((autoload "org-attach" "The dispatcher for attachment commands.\nShows a list of commands and prompts for another key to execute a command.\n\n(fn)" t nil) org-attach)
  command-execute(org-attach)

I can evaluate the el-patch-defun form but when I try to load org-attach it fails.

This is the patch:

(eval-after-load "org-attach"
  '(progn
     (el-patch-defun org-attach-annex-get-maybe (path)
       "Call git annex get PATH (via shell) if using git annex.
Signals an error if the file content is not available and it was not retrieved."
       (let* ((default-directory (expand-file-name org-attach-directory))
              (path-relative (file-relative-name path)))
         (when (and (org-attach-use-annex)
                    (not
                     (string-equal
                      (el-patch-swap "found" "\nfound")
                      (shell-command-to-string
                       (format "git annex find --format=found --in=here %s"
                               (shell-quote-argument path-relative))))))
           (let ((should-get
                  (if (eq org-attach-annex-auto-get 'ask)
                      (y-or-n-p (format "Run git annex get %s? " path-relative))
                    org-attach-annex-auto-get)))
             (if should-get
                 (progn (message "Running git annex get \"%s\"." path-relative)
                        (call-process "git" nil nil nil "annex" "get" path-relative))
               (error "File %s stored in git annex but it is not available, and was not retrieved"
                      path))))))))

raxod502 added a commit that referenced this issue Jan 27, 2019
Previously, you could get an error:

    Unregistered definition type ‘defalias’

if you tried to evaluate an `el-patch-defun' form or similar inside of
an `eval-after-load' or similar, without having previously loaded
`el-patch'. This was due to an autoloading bug, which this commit
fixes.

In retrospect, the documentation I added when originally addressing
this problem was wrong -- it should not be necessary to explicitly
load a package in order to use its macros, at least in this
context (it is sometimes necessary in other cases, most notably when a
macro from package X is used inside an `eval-after-load' form for
package Y which is evaluated before package X is loaded, and the macro
from package X is autoloaded, and it does not evaluate all of its
arguments, and one of its arguments can be mistaken for an invocation
of some other macro from package Z).
@raxod502
Copy link
Member

You can work around the problem by adding (require 'el-patch) before your eval-after-load form. However, after some further investigation, I determined that this is a bug in el-patch, which should be fixed in the above commit—let me know if you still get the error.

@Fuco1
Copy link
Contributor

Fuco1 commented Jan 29, 2019

I should really switch to straight.el... trying upstream branches out with the combination of package.el, cask and git submodules is so painful (yes my config is a mess).

Anyhow, your fix works! Thanks!

@Fuco1
Copy link
Contributor

Fuco1 commented Jan 29, 2019

Really enjoying el-patch by the way. It's such an obvious idea once you think about it... but that someone actually implemented it just blows my mind :) Keep it up!

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

No branches or pull requests

3 participants