Skip to content

Instantly share code, notes, and snippets.

@gongo
Created March 3, 2012 06:59
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 gongo/1964779 to your computer and use it in GitHub Desktop.
Save gongo/1964779 to your computer and use it in GitHub Desktop.
見たい文字だけを表示する elisp (dnso.el)
;;; dnso.el -- Do not show off!
;; MAHALO License (based on MIT License)
;;
;; Copyright (c) 2012 Wataru MIYAGUNI (gonngo _at_ gmail.com)
;;
;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;;
;; 1. The above copyright notice and this permission notice shall be included in
;; all copies or substantial portions of the Software.
;; 2. Shall be grateful for something (including, but not limited this software).
;;
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;; THE SOFTWARE.
;;; Code:
;; (setq dnso:match-keywords "a-zA-Z") ;; defualt
;;; Demo:
;; http://youtu.be/MZaWMpJPN7s
(defconst dnso:match-keywords "a-zA-Z")
(defface dnso:face
'((t (:foreground "Black" :background "Black")))
"Only Only Only face")
(defvar dnso:overlays nil)
(defconst dnso:buffer "*Only Only Buffer*")
(defun dnso:keywords-point (sp regexp)
(save-excursion
(goto-char sp)
(let (p)
(setq p (re-search-forward regexp nil t))
(if (integerp p) (1- p) p))))
(defun dnso:match-keywords-point (sp)
(dnso:keywords-point sp (concat "[" dnso:match-keywords "]")))
(defun dnso:no-match-keywords-point (sp)
(dnso:keywords-point sp (concat "[^" dnso:match-keywords "]")))
(defun dnso:show ()
(interactive)
(save-excursion
(copy-to-buffer (get-buffer-create dnso:buffer) (point-min) (point-max))
(let ((buffer (current-buffer))
face)
(with-current-buffer dnso:buffer
(switch-to-buffer (current-buffer))
(goto-char (point-min))
(insert " ")
(goto-char (point-min))
(setq dnso:overlays nil)
(set-face-background 'dnso:face (background-color-at-point))
(set-face-foreground 'dnso:face (background-color-at-point))
(catch 'loop
(let (overlay p1 p2)
(while t
(setq p1 (dnso:no-match-keywords-point (point)))
(when (null p1) (throw 'loop nil))
(setq p2 (dnso:match-keywords-point p1))
(when (null p2) (setq p2 (point-max)))
(setq overlay (make-overlay p1 p2))
(overlay-put overlay 'face 'dnso:face)
(setq dnso:overlays (cons overlay dnso:overlays))
(goto-char p2)
)))
(goto-char (point-min))
(delete-char 1)
(view-mode)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment