Skip to content

Commit

Permalink
*liny expand-template primary
Browse files Browse the repository at this point in the history
  • Loading branch information
ran9er committed Mar 26, 2013
1 parent 8ed3140 commit 20ed968
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 54 deletions.
7 changes: 2 additions & 5 deletions _eval-after-load/org.el
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
;; -*- encoding: utf-8-unix; -*-
;; File-name: <org-mode.el>
;; Create: <2012-01-03 14:21:30 ran9er>
;; Time-stamp: <2013-03-13 20:44:17 ran9er>
;; Mail: <[email protected]>
;; *========== org-mode
(setq org-hide-leading-stars t)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done 'time)
(add-hook 'org-mode-hook
(lambda () (setq truncate-lines nil)))
22 changes: 9 additions & 13 deletions liny/extensions/expand-template.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,37 @@
'relay nil nil nil ori)))
(void (liny-overlay-link ovl rly))
(void (overlay-put rly 'template str))
(templ (liny-expand-templ rly))
(first (car templ))
(last (cdr templ)))
(templ (liny-expand-templ rly)))
(liny-overlay-push-to
ori 'snippet-ready
`(lambda(o) ;o => ori
(liny-overlay-link-remove ,ovl)
(liny-overlay-link ,rly ,first ,last)
(let ((ori1 (overlay-get ,first 'origin)))
(mapc (lambda(x)(overlay-put x 'origin ,ori)
(liny-overlay-push-to ,ori 'member x))
(overlay-get ori1 'member))
(liny-overlay-release ori1))))
))
(liny-overlay-link-remove ,ovl)
))))

(defun liny-expand-templ-ovl (ovl)
"liny-expand-templ-ovl is writen by ran9er"
(if (y-or-n-p "Continues?")
(progn
(goto-char (overlay-end (liny-find-role ovl)))
(goto-char (overlay-end (car (liny-expand-templ ovl)))))
(liny-goto-field 'nn t)))
(liny-goto-field 'next t)
(liny-goto-field 'next t)))

(defun liny-expand-templ (ov &optional origin)
"liny-expand-template is writen by ran9er"
(let* ((str (overlay-get ov 'template)) ;ov => relay
(templ (liny-insert (liny-gen-token str) t t origin ov)) ;templ => expand
(ori (overlay-get ov 'origin))
(last (cdr templ))) ;last => expand relay
(last (cdr templ)) ;last => expand relay
(ori1 (liny-ovl-get last 'origin)))
(overlay-put last 'template str)
(liny-overlay-link ov (car templ) last)
(mapc
(lambda(x)(overlay-put x 'origin ori)
(liny-overlay-push-to ori 'member x))
(liny-ovl-get last 'origin 'member))
(liny-ovl-get ori1 'origin 'member))
(liny-overlay-release ori1)
(liny-overlay-append-hooks
last 'jump-relay-hooks 'liny-expand-templ-ovl)
templ))
17 changes: 1 addition & 16 deletions liny/extensions/goto-field-by-order.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,4 @@
(length (member (rassq o lst)
lst)))))
(oo (if (< idx 0) nil (cdr (nth idx lst)))))
(if oo
(cond
((eq (overlay-get oo 'role) 'end)
(if (y-or-n-p "finish this snippet?")
(progn
(goto-char (overlay-end oo))
(liny-run-hook (overlay-get ori 'snippet-exit) oo)
(liny-clear-instance o))))
((eq (overlay-get oo 'role) 'relay)
(liny-run-hook (overlay-get oo 'jump-relay-hooks) oo))
(t
(overlay-put o 'offset (- (overlay-end o)(point)))
(overlay-put o 'face 'liny-editable-face)
(goto-char (- (overlay-end oo)(overlay-get oo 'offset)))
(overlay-put oo 'face 'liny-active-face)))
(message "End of world."))))
(liny-goto-field-really oo)))
44 changes: 25 additions & 19 deletions liny/liny.el
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
relay
((role . relay)
(id . nil)
(offset . 0)
(previous . nil)
(next . nil)
(insert-in-front-hooks liny-this-overlay)
Expand Down Expand Up @@ -565,28 +566,33 @@

(defvar liny-goto-field-func 'liny-goto-field)


(defun liny-goto-field-really (ov &optional na)
"liny-goto-field-1 is writen by ran9er"
(if ov
(cond
((eq (overlay-get ov 'role) 'end)
(if (or na (y-or-n-p "finish this snippet?"))
(progn
(goto-char (overlay-end ov))
(liny-run-hook (overlay-get
(overlay-get ov 'origin)
'snippet-exit) ov)
(liny-clear-instance o))))
(t
(overlay-put o 'offset (- (overlay-end o)(point)))
(overlay-put o 'face 'liny-editable-face)
(if (or na (null (eq (overlay-get ov 'role) 'relay)))
(goto-char (- (overlay-end ov)(overlay-get ov 'offset)))
(liny-run-hook (overlay-get ov 'jump-relay-hooks) ov))
(overlay-put ov 'face 'liny-active-face)))
(message "End of world.")))

(defun liny-goto-field (p-or-n &optional na)
(interactive)
(let* ((o (liny-get-primary (liny-get-overlay)))
(oo (cond
((eq p-or-n 'nn)
(overlay-get (overlay-get o 'next) 'next))
(t (overlay-get o p-or-n)))))
(if oo
(cond
((eq (overlay-get oo 'role) 'end)
(if (or na (y-or-n-p "finish this snippet?"))
(progn
(goto-char (overlay-end oo))
(liny-clear-instance o))))
((eq (overlay-get oo 'role) 'relay)
(liny-run-hook (overlay-get oo 'jump-relay-hooks) oo))
(t
(overlay-put o 'offset (- (overlay-end o)(point)))
(overlay-put o 'face 'liny-editable-face)
(goto-char (- (overlay-end oo)(overlay-get oo 'offset)))
(overlay-put oo 'face 'liny-active-face)))
(message "End of world."))))
(oo (overlay-get o p-or-n)))
(liny-goto-field-really oo na)))

(defun liny-previous-field ()
(interactive)
Expand Down
2 changes: 1 addition & 1 deletion liny/snippets/emacs-lisp-mode#cond
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cond cd co cn
emacs-lisp-mode lisp-mode lisp-interaction-mode
<------environment
<------snippet
(${1:cond}
(${1:cond}
${2%{(${1:TEST}
${2:form})
$0}}$0)

0 comments on commit 20ed968

Please sign in to comment.