Skip to content

Instantly share code, notes, and snippets.

@Fuco1
Created August 21, 2013 17:37
Show Gist options
  • Save Fuco1/6297493 to your computer and use it in GitHub Desktop.
Save Fuco1/6297493 to your computer and use it in GitHub Desktop.
Work in progress on prefix-hiding, if someone wants to mess with it.
cl--foo
cl-loop
(setq hide-prefix-last-point (cl-remove-if foo bar))
("\\_<\\(cl--\\)\\(\\(\\sw\\|\\s_\\)+\\)"
(1 (progn (my-hide-prefix (match-beginning 1) (match-end 1)) nil))
(2 font-lock-constant-face))
(font-lock-add-keywords nil '(("\\_<\\(cl-\\)\\([^-]\\)\\(?:\\sw\\|\\s_\\)*"
(1 (progn (my-hide-prefix (match-beginning 1) (match-end 1)) nil))
(2 hide-prefix-cl-face))
("\\_<\\(hide-prefix-\\)\\([^-]\\(?:\\sw\\|\\s_\\)*\\)"
(1 (progn (my-hide-prefix (match-beginning 1) (match-end 1)) nil))
(2 font-lock-type-face))))
cl-foo
(defun my-hide-prefix (start end)
(unless (--keep (overlay-get it 'hide-prefix) (overlays-at start))
(let ((ov (make-overlay start end nil t)))
(overlay-put ov 'display "") ;; any prefix possible here
(overlay-put ov 'hide-prefix t)
(overlay-put ov 'evaporate t)
(overlay-put ov 'modification-hooks '(my-hide-prefix-ov-mod)))))
(defun my-hide-prefix-ov-mod (overlay after? beg end &optional length)
(delete-overlay overlay))
(defvar hide-prefix-last-point 0
"Point before last command.")
(defvar hide-prefix-last-overlay nil
"Last expanded overlay.")
(defun hide-prefix-post-command-handler ()
(when (/= (point) hide-prefix-last-point)
;; if there is an overlay before point, show it
(when hide-prefix-last-overlay
(overlay-put hide-prefix-last-overlay 'display "")
(setq hide-prefix-last-overlay nil))
(let ((ov (car (--filter (overlay-get it 'hide-prefix) (overlays-at (1- (point)))))))
(when ov
(overlay-put ov 'display nil)
(setq hide-prefix-last-overlay ov))))
(setq hide-prefix-last-point (point)))
(add-hook 'post-command-hook 'hide-prefix-post-command-handler nil t)
(remove-hook 'post-command-hook 'hide-prefix-post-command-handler t)
asd cl-asd
(let ((oo (cl-loop foo))))
cl-df
sdasd
cl-asd
(defun foo )
(lambda asd)
asd
(defface my-hide-prefix
'((t (:box (:line-width 1 :color "LightGoldenrod3" :style nil))))
"foo")
(defvar my-hide-prefix 'my-hide-prefix)
(defface hide-prefix-cl-face
'((t (:underline (:color "red" :style line))))
"CL namespace face.")
(defvar hide-prefix-cl-face 'hide-prefix-cl-face)
(defun cl--position (cl-seq cl-start &optional cl-end cl-from-end)
(if (listp cl-seq)
(let ((cl-p (nthcdr cl-start cl-seq)))
(or cl-end (setq cl-end 8000000))
(let ((cl-res nil))
(while (and cl-p (< cl-start cl-end) (or (not cl-res) cl-from-end))
(if (cl--check-test cl-item (car cl-p))
(setq cl-res cl-start))
(setq cl-p (cdr cl-p) cl-start (1+ cl-start)))
cl-res))
(or cl-end (setq cl-end (length cl-seq)))
(if cl-from-end
(progn
(while (and (>= (setq cl-end (1- cl-end)) cl-start)
(not (cl--check-test cl-item (aref cl-seq cl-end)))))
(and (>= cl-end cl-start) cl-end))
(while (and (< cl-start cl-end)
(not (cl--check-test cl-item (aref cl-seq cl-start))))
(setq cl-start (1+ cl-start)))
(and (< cl-start cl-end) cl-start))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment