Skip to content

Instantly share code, notes, and snippets.

@kurohuku
Created December 5, 2013 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurohuku/7805989 to your computer and use it in GitHub Desktop.
Save kurohuku/7805989 to your computer and use it in GitHub Desktop.
(require 'cl)
(defvar popup-matching-paren-open-parens "([{\"")
(defvar popup-matching-paren-close-parens ")]}\"")
(defun popup-matching-paren (&optional lines)
"popup 1+`lines'*2 lines"
(interactive)
(unless lines
(setq lines 0))
(cond
((find (char-before) popup-matching-paren-close-parens)
(popup-matching-paren-backward lines))
((find (char-after) popup-matching-paren-open-parens)
(popup-matching-paren-forward lines))))
(defun popup-matching-paren-forward (lines)
(let ((text (save-excursion
(forward-sexp)
(unless (and (<= (window-start) (point))
(< (point) (window-end)))
(popup-matching-paren-get-lines lines)))))
(when text
(popup-tip text))))
(defun popup-matching-paren-backward (lines)
(let ((text (save-excursion
(backward-sexp)
(unless (and (<= (window-start) (point))
(< (point) (window-end)))
(popup-matching-paren-get-lines lines)))))
(when text
(popup-tip text))))
(defun popup-matching-paren-get-lines (lines)
(let ((beg (save-excursion (previous-line lines) (line-beginning-position)))
(end (save-excursion (next-line lines) (line-end-position))))
(buffer-substring beg end)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment