reddit / emacs

GNU Hypobole 1.0

Thin-Ice-7955 路 2022-06-22 20:16
## GNU Hypobole 1.0 There have been a few recent discussions about the [GNU Hyperbole](https://www.gnu.org/software/hyperbole/) package, which provides worldwide interlinking capabilities across different buffers and modes via implicit and explicit links, which are activated with a single command or key. This feature is interesting, but Hyperbole comes with a additional baggage, the Koutliner, HyRolo, HyControl and technical debt, which makes the package hard to get into. For this reason I tried to cook down the package to a minimal subset - GNU Hypobole. Since Emacs is Elisp and Elisp is Emacs it also makes sense to hack it yourself. Still, the following package is only meant as a demonstrator. If you truly want to use the hotkey functionality, you may rather use the original Hyperbole package, [Embark](https://github.com/oantolin/embark) (`embark-dwim` as hotkey and `embark-act` for additional actions) or simply [Org-mode](https://orgmode.org/) (`org-open-at-point-global` for Org links in arbitrary modes). Also consider contributing to Emacs or the package ecosystem! Thank you for reading! ## The Code ;;; hypobole.el --- Worldwide interlinking capabilities -*- lexical-binding: t -*- ;; The assist key command `hypobole-key' (C-c h) recognizes: ;; ;; + {C-h h} macros ;; + Org links (org-open-at-point-global) ;; + Toggeable Org elements in Org (C-c C-c) ;; + URLs ;; + Files ;; + Symbols ;; + S-expressions (require 'ffap) (require 'pp) (require 'org) (defvar hypobole-links '(hypobole-kmacro hypobole-org-link hypobole-org-toggle hypobole-url hypobole-file hypobole-symbol hypobole-sexp hypobole-nop)) (defun hypobole-nop () (user-error "No link at point")) (defun hypobole-kmacro () (interactive) (save-excursion (let ((beg (progn (skip-chars-backward "^{}\n") (point))) (end (progn (skip-chars-forward "^{}\n") (point)))) (when (and (eq (char-before beg) ?{) (eq (char-after end) ?})) (setq unread-command-events (listify-key-sequence (kbd (buffer-substring beg end)))) t)))) (defun hypobole-org-link () (interactive) (ignore-errors (progn (if (derived-mode-p 'org-mode) (org-open-at-point) (org-open-at-point-global)) t))) (defun hypobole-org-toggle () (interactive) (when (derived-mode-p 'org-mode) (ignore-errors (or (org-ctrl-c-ctrl-c) t)))) (defun hypobole-url () (interactive) (when-let (url (ffap-url-at-point)) (browse-url url) t)) (defun hypobole-file () (interactive) (when-let (file (ffap-file-at-point)) (find-file file) t)) (defun hypobole-symbol () (interactive) (when-let* ((symbol (thing-at-point 'symbol)) (symbol (intern-soft symbol)) ((or (boundp symbol) (fboundp symbol)))) (describe-symbol symbol) t)) (defun hypobole-sexp () (interactive) (when-let* ((sexp (sexp-at-point)) ((consp sexp))) (pp-display-expression (eval sexp t) "*Pp Eval Output*") t)) (defun hypobole-key () (interactive) (run-hook-with-args-until-success 'hypobole-links)) (global-set-key (kbd "C-c h") 'hypobole-key) (provide 'hypobole) ;;; hypobole.el ends here
AblatedSprocket 路 2022-06-22 21:41
I don't know anything about Hyperbole, but I enjoy these hack-it-together-yourself of posts. Thanks for sharing!
rswgnu 路 2022-06-23 00:48
I get the hypo joke and I hope this stays as a joke and is not posted anywhere where people might confuse it for the real thing. To be clear, even for the small set of contexts this handles it does far fewer things with each type than the original, globally replicated, massively metastasized, inherently magnetic V8 Hyperbole 馃槈
Thin-Ice-7955 路 2022-06-23 06:41
Yeah, it is obviously meant as a joke and there is no plan to create a package given that there are hyperbole and embark. But there is a lot of value in trying to rebuild features yourself, just to get a grip and to improve your elisp skills. The extensibility with elisp what makes emacs unique, so users should try to take advantage of that. Otherwise you will probably have an easier ride with other editors, in particular if you are looking for out of the boxiness. To come back to hyperbole: You write that hyperbole does much more for the small sets of contexts - can you please be more precise about that? This would be really helpful for understanding. I know that you can press C-u to inspect the action before executing it, but is there more to it? Does hyperbole do something different with files/urls/symbols? Note that the hypobole from above takes advantages of org links so it should in principle be equally powerful to hyperbole with respect to explicit links, e.g., you could define a link in org syntax: gh:rswgnu/hyperbole/5ae3550
Thin-Ice-7955 路 2022-06-23 06:44
Thanks! Yes, hacking emacs yourself is what makes emacs unique. We should all be taking advantage of that!
[deleted] 路 2022-06-23 07:02
[deleted]