dmitrym0 / org-hyperscheduler

org-hyperscheduler is an Emacs package that helps you organize your day.
GNU General Public License v3.0
188 stars 14 forks source link

Use `defalias` to define `org-hs-open` #6

Closed meliache closed 2 years ago

meliache commented 2 years ago

The advantage is just making it more obvious that it's just an alias and not doing anything else. E.g. when consulting M-x describe-variable org-hs-open, emacs will tell the user that it's an alias.

dmitrym0 commented 2 years ago

@meliache does defalias need autoload as well?

meliache commented 2 years ago

I merged the master branch again

@dmitrym0 At first I also wasn't sure if the defalias needs to be autoloaded, as I'm not an experienced elisp package developer but I just tested it and yes, the autoload comment is needed. This is how I tested it:

  1. add deferring to tell emacs not to load the package until it's needed
    (use-package org-hyperscheduler
    :defer t
    :straight
    (:host github :repo "dmitrym0/org-hyperscheduler" :files ("*")))

    (Or alternatively use (setq use-package-always-defer t) at the begin of your init file, but that will affect all packages.)

  2. Add/remove the ;;;###autoload magic comment from the source code
  3. Recompile the package, e.g. M-x straight-rebuild-package org-hyperscheduler
  4. Restart emacs and check if I can run M-x org-hs-open. I found that I can only do that when the magic comment is added

Out of curiosity, I also checked the autoload defintions that emacs generated. For me with straight they were in

~/.emacs.d/straight/build/org-hyperscheduler/org-hyperscheduler-autoloads.el

That file contained the lines:

;;; Generated autoloads from org-hyperscheduler.el

(autoload 'org-hyperscheduler-open "org-hyperscheduler" "\
Open org-hyperscheduler in the browser." t nil)

(defalias 'org-hs-open #'org-hyperscheduler-open)

So to be precise, emacs doesn't actually call autoload on the alias, but just forwards the alias definition to the autoload file that has the emacs code that is loaded before the actual package is loaded. That makes sense since an alias is just a lightweight shortform.

dmitrym0 commented 2 years ago

I didn't know how autoloads work! Thanks for doing this, I learned a bunch.