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.

Revisions

  1. grafov revised this gist Jun 22, 2024. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions haredoc.el
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,17 @@
    (require 'ansi-color)

    ;; Shows haredoc for the current word.
    ;; 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 (thing-at-point 'word t)) ;; Get the current word
    (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) ;; Insert as binary due escape seqs
    (ansi-color-apply-on-region (point-min) (point-max)))))) ;; Finally add coloring
    (with-current-buffer buffer-name (insert output)
    (ansi-color-apply-on-region (point-min) (point-max))))))
  2. grafov created this gist Jun 22, 2024.
    14 changes: 14 additions & 0 deletions haredoc.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    (require 'ansi-color)

    ;; Shows haredoc for the current 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 (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) ;; Insert as binary due escape seqs
    (ansi-color-apply-on-region (point-min) (point-max)))))) ;; Finally add coloring