Skip to content

Commit

Permalink
* my-auto-pair ==> skeleton-pair-alist-update
Browse files Browse the repository at this point in the history
  • Loading branch information
ran9er committed May 29, 2013
1 parent 3713a40 commit 42d4554
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 46 deletions.
2 changes: 1 addition & 1 deletion 16_hl-p.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
;; '((lambda (action pair pos-before)
;; (hl-paren-color-update)))))))

(add-hook 'emacs-lisp-mode-hook 'my-auto-pair)
(add-hook 'emacs-lisp-mode-hook 'skeleton-pair-alist-update)

;; * Enables highlight-parentheses-mode on all buffers:

Expand Down
9 changes: 0 additions & 9 deletions _autoload-conf/skeleton-pair.el
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
(setq skeleton-pair-cond-alist
'(
((char-bf '(?$ ?=)) . (?\{ _ "}"))
((or (char-bf ?/)(char-bf ?=)) . (?\[ n _ n "]"))
((bolp) . (?/ "*" n _ n "*/"))
(t . (?/ _))
((bolp) . (?. -1 "->"))
(t . (?. _))
))
(skeleton-pair-alist-update)

;;;###autoload
Expand Down
70 changes: 68 additions & 2 deletions _eval-after-load/eshell.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
(outline-minor-mode 1)
(eldoc-mode)
; (lisp-symbol)
(my-auto-pair)
(skeleton-pair-alist-update)
;; (enable-theme 'eshell)
(eshell-scroll-conservatively)
(setq
Expand Down Expand Up @@ -102,14 +102,49 @@
'require
'(eshell-ls
eshell-user-key
eshell-user-func
eshell-cmpl
eshell-bmk))

;; * face
;(make-face 'eshell-custom-face)
;(set-face-attribute 'eshell-custom-face nil :font "宋体-10")

;; * func & alias
(defun eshell/ff(file)
(find-file file))

(defun eshell/img(img)
(propertize "Image" (quote display) (create-image (expand-file-name img))))

(defun eshell/ee ()
(find-file (expand-file-name "_extensions/+eshell.el" *init-dir*)))

(defun eshell/aa ()
(find-file eshell-aliases-file))

(defun eshell/rr ()
(find-file (expand-file-name "_qref.org" work-dir)))

(defun eshell/ed (file1 file2)
(ediff-files file1 file2))

(defun eshell/ro ()
"Delete files matching pattern \".*~\" and \"*~\""
(eshell/rm (directory-files "." nil "^\\.?.*~$" nil)))

;; ** alternate func
(defun eshell/less (&rest args)
"Invoke `view-file' on a file. "less +42 foo" will go to line 42 in
the buffer for foo."
(while args
(if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
(let* ((line (string-to-number (match-string 1 (pop args))))
(file (pop args)))
(tyler-eshell-view-file file)
(goto-line line))
(tyler-eshell-view-file (pop args)))))
(defalias 'eshell/more 'eshell/less)

;; * last command timer
(add-hook 'eshell-load-hook
(lambda()(setq last-command-start-time (float-time))))
Expand Down Expand Up @@ -156,3 +191,34 @@
;+++++++++++++++++++++++++++++++++++++++


;; * other func
(defun eshell-maybe-bol ()
(interactive)
(let ((p (point)))
(eshell-bol)
(if (= p (point))
(beginning-of-line))))

(defun eshell/vi (&rest args)
"Invoke `find-file' on the file.
\"vi +42 foo\" also goes to line 42 in the buffer."
(while args
(if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
(let* ((line (string-to-number (match-string 1 (pop args))))
(file (pop args)))
(find-file file)
(goto-line line))
(find-file (pop args)))))

(defun eshell/emacs (&rest args)
"Open a file in emacs. Some habits die hard."
(if (null args)
;; If I just ran "emacs", I probably expect to be launching
;; Emacs, which is rather silly since I'm already in Emacs.
;; So just pretend to do what I ask.
(bury-buffer)
;; We have to expand the file names or else naming a directory in an
;; argument causes later arguments to be looked for in that directory,
;; not the starting directory
(mapc #'find-file (mapcar #'expand-file-name (eshell-flatten-list (reverse args))))))

2 changes: 1 addition & 1 deletion _eval-after-load/js-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
;; " *, *" t))
;; )))

(add-hook 'javascript-mode-hook 'my-auto-pair)
(add-hook 'javascript-mode-hook 'skeleton-pair-alist-update)
7 changes: 3 additions & 4 deletions _eval-after-load/lua-mode.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
(load-once
;; (add-to-list 'auto-mode-alist '("\\.lua\\'" . lua-mode))
;; (autoload 'lua-mode "lua-mode" "" t nil)
)
(add-to-list 'auto-mode-alist '("\\.wlua\\'" . lua-mode))

(add-hook 'lua-mode-hook 'skeleton-pair-alist-update)
15 changes: 12 additions & 3 deletions _extensions_/liny/snippets/_keywords_index
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@
(nil nil)
"t"
(nil
("top" "tail" "notop" "head"))))
("top" "tail" "notop" "head"))
"wx.lua.newfile"
(("head")
nil)))
#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data
("env"
("#env")
Expand Down Expand Up @@ -148,7 +151,11 @@
"snip"
("snippets=file")
"t"
("t")))
("t")
"new"
("wx.lua.newfile")
"newfile"
("wx.lua.newfile")))
#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data
("emacs-lisp-mode"
("#env" "eltempl" "emacs-lisp-mode#closure" "emacs-lisp-mode#cond" "emacs-lisp-mode#defun" "emacs-lisp-mode#hash-table" "emacs-lisp-mode#let" "emacs-lisp-mode#ol" "emacs-lisp-mode#read-file" "emacs-lisp-mode#test" "let" "lisp#lambda")
Expand All @@ -169,4 +176,6 @@
"slime-repl-mode"
("lisp#lambda")
"org-mode"
("org-mode#head"))))
("org-mode#head")
"lua-mode"
("wx.lua.newfile"))))
2 changes: 1 addition & 1 deletion _lib/auto-pair.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(setq skeleton-pair t)
(define-key-s 1 '("(" "{" "\"" "[") 'skeleton-pair-insert-maybe))

(defadvice skeleton-pair-insert-maybe (around xxx activate)
(defadvice skeleton-pair-insert-maybe (around condition activate)
(let ((skeleton-pair-alist skeleton-pair-alist)
(c-before
(lambda(x)(save-excursion
Expand Down
50 changes: 25 additions & 25 deletions _lib/skeleton-pair.el
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
(setq skeleton-pair t)
(defvar skeleton-pair-cond-alist
'(
((char-bf '(?$ ?=)) . (?\{ _ "}"))
((or (char-bf ?/)(char-bf ?=)) . (?\[ n _ n "]"))
((bolp) . (?/ "*" n _ n "*/"))
(t . (?/ _))
((bolp) . (?. -1 "->"))
(t . (?. _))
(?\( . ((t _ ")")))
(?\{ . (((char-bf '(?$ ?=)) _ "}")
(t n _ n "}")))
(?\[ . (((or (char-bf ?/)(char-bf ?=)) n _ n "]")
(t _ "]")))
(?/ . (((bolp) "*" n _ n "*/")
(t _)))
(?. . (((bolp) -1 "->")
(t _)))
(?\" . ((t _ "\"")))
))
(defadvice skeleton-pair-insert-maybe (around xxx activate)
(let ((skeleton-pair-alist skeleton-pair-alist)
(x skeleton-pair-cond-alist))

(defadvice skeleton-pair-insert-maybe (around condition activate)
(let* ((skeleton-pair-alist skeleton-pair-alist)
(key last-command-event)
(cnd (cdr (assq key skeleton-pair-cond-alist))))
(while
(and
x
cnd
(null
(if (and
(eq last-command-event (cadr (car x)))
(eval (caar x)))
(setq skeleton-pair-alist (list (cdar x)))
(if (eval (caar cnd))
(setq skeleton-pair-alist (list (cons key (cdar cnd))))
nil)))
(setq x (cdr x)))
(setq cnd (cdr cnd)))
;; (message (format "%S" skeleton-pair-alist))
ad-do-it))
;; (defadvice skeleton-pair-insert-maybe (around xxx activate)
;; (let ((skeleton-pair-alist skeleton-pair-alist))
;; (mapc
;; (lambda(x)
;; (if (and (eq last-command-event (cadr x))(eval (car x)))
;; (setq skeleton-pair-alist (list (cdr x)))))
;; skeleton-pair-cond-alist)
;; ad-do-it))

(defun char-bf (x)
(let ((x (if (listp x) x (list x))))
(save-excursion
Expand All @@ -38,11 +37,12 @@
;;;###autoload
(defun skeleton-pair-alist-update ()
(interactive)
(mapcar
(mapc
(lambda(x)
;; (local-set-key (char-to-string (cadr x)) 'skeleton-pair-insert-maybe)
(define-key (current-local-map)
(eval `(kbd ,(char-to-string (cadr x))))
(eval `(kbd ,(char-to-string (car x))))
;; (char-to-string (cadr x))
'skeleton-pair-insert-maybe))
skeleton-pair-cond-alist))
;; (skeleton-pair-alist-update)
Expand Down

0 comments on commit 42d4554

Please sign in to comment.