Skip to content

Instantly share code, notes, and snippets.

@grafov
Last active June 22, 2024 18:03
Show Gist options
  • Save grafov/30a4dd6c81ea2526710e16ce1f79e2b9 to your computer and use it in GitHub Desktop.
Save grafov/30a4dd6c81ea2526710e16ce1f79e2b9 to your computer and use it in GitHub Desktop.
Shows haredoc for the current word under cursor in the GNU/Emacs bufer.
(require 'ansi-color)
;; Shows haredoc for the selected or word.
(defun haredoc ()
"Run the haredoc with the current word under the cursor and display
the results in a new buffer."
(interactive)
(let* ((current-word
(if (use-region-p) ;; Use region or the current word
(setq current-word (buffer-substring-no-properties (region-beginning) (region-end)))
(setq current-word (thing-at-point 'word t)))) ;; Get the current word
(command (concat "haredoc -a -F tty " current-word)) ;; Create the command string
(output (shell-command-to-string command)) ;; Run the command and capture the output
(buffer-name (concat "*haredoc: " current-word "*"))) ;; Name for the output buffer
(with-output-to-temp-buffer buffer-name ;; Create and display the buffer
(with-current-buffer buffer-name (insert output)
(ansi-color-apply-on-region (point-min) (point-max))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment