Skip to content

Instantly share code, notes, and snippets.

@suhailshergill
Created July 17, 2012 04:25
Show Gist options
  • Save suhailshergill/3127107 to your computer and use it in GitHub Desktop.
Save suhailshergill/3127107 to your computer and use it in GitHub Desktop.
the heimlich: dirty hack to unchoke gist-region on `%'
(defadvice gist-region (around su/advice/gist/gist-region/around/dirty-hack
a c pre)
"Dirty hack to prevent gist-region from choking on buffers which contain
`%' character"
(save-window-excursion
(let* ((delete-old-versions t)
(dummy "foo")
(beg (ad-get-arg 0))
(end (ad-get-arg 1))
(min-beg-end (min beg end))
(original-text (buffer-substring beg end))
gistid buf proc)
(kill-region beg end)
(insert-for-yank-1 dummy)
(ad-set-arg 0 min-beg-end)
(ad-set-arg 1 (point))
ad-do-it
(sleep-for 0.5) ;; deep magic
(dolist (buf (buffer-list))
(when (string-match "^\\s-\\*http api\\.github\\.com:443\\*$" (buffer-name
buf))
(setq proc (get-buffer-process buf))
(when proc (kill-process proc))
))
(delete-region min-beg-end (point))
(insert-for-yank-1 original-text)
(setq gistid (car (last (split-string (car kill-ring)
"/"))))
(setq buf (gist-fetch gistid))
(with-current-buffer buf
(delete-region (point-min)
(point-max))
(insert-for-yank-1 original-text)
(gist-mode-save-buffer)
(kill-buffer))
)))
@fakedrake
Copy link

That fixed it for me thank you

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