Skip to content

Instantly share code, notes, and snippets.

@ericbmerritt
Created June 10, 2011 16:08
Show Gist options
  • Save ericbmerritt/1019166 to your computer and use it in GitHub Desktop.
Save ericbmerritt/1019166 to your computer and use it in GitHub Desktop.
highlight extent
;;;###autoload
(defun ispell-hl-minor-mode (&optional arg)
"Toggle Ispell Highlight mode.
With prefix ARG, turn Ispell Highlight mode on if arg is positive.
In Ispell Highlight mode, changing the buffer contens will spell
the words around the cursor and highlight miss-spelled ones!"
(interactive "P")
(setq ispell-hl-minor-mode
(not (or (and (null arg) ispell-hl-minor-mode)
(<= (prefix-numeric-value arg) 0))))
(make-local-hook 'before-change-functions)
(make-local-hook 'after-change-functions)
(if ispell-hl-minor-mode
(progn
(add-hook 'before-change-functions 'ispell-hl-before-check-word nil t)
(add-hook 'after-change-functions 'ispell-hl-check-word nil t)
)
(progn
(remove-hook 'before-change-functions 'ispell-hl-before-check-word t)
(remove-hook 'after-change-functions 'ispell-hl-check-word t)
(ispell-hl-buffer t) ; remove highlighted errors
))
(redraw-modeline))
(make-face 'ispell-hl-error-face
"Face to use for highlighting spelling errors.")
(set-face-foreground 'ispell-hl-error-face "red3")
(set-face-underline-p 'ispell-hl-error-face t)
(defun ispell-hl-error (from to)
"Highlight the region delimited by FROM and TO as a spelling-error."
(interactive "r")
(let ((x (make-extent from to (current-buffer))))
(set-extent-keymap x ispell-hl-keymap)
(set-extent-property x 'pointer selection-pointer-glyph)
(set-extent-property x 'duplicable t)
(set-extent-property x 'unique t)
(set-extent-property x 'start-open t)
(set-extent-property x 'end-closed t)
(set-extent-priority x 1000)
(set-extent-property x 'ispell-hl-error t)
(set-extent-face x 'ispell-hl-error-face)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment