Created
January 21, 2011 11:20
-
-
Save kiwanami/789549 to your computer and use it in GitHub Desktop.
toggle astah of the current 'let'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun toggle-let-astah-search-let () | |
(save-excursion | |
(let ((point-min (point-min)) | |
(re "(\\(lexical-\\)?let\\(\\*\\)?") | |
(continue t) pos ast ret) | |
(while (and continue (/= (point-min) (point))) | |
(goto-char (or (ignore-errors (scan-lists (point) -1 1)) | |
(point-min))) | |
(save-excursion | |
(when (and (looking-at re) (re-search-forward re nil t)) | |
(setq pos (match-end 0) | |
ast (match-string 2)) | |
(unless (ignore-errors (scan-lists (point) 1 0)) | |
(setq ret (cons pos ast) | |
continue nil))))) | |
ret))) | |
(defun toggle-let-astah () | |
(interactive) | |
(let (replaced (org-pos (point))) | |
(save-excursion | |
(let ((limit (or (save-excursion | |
(re-search-backward "\\bdef" nil t)) | |
(point-min))) | |
pair pos ast) | |
(save-restriction | |
(narrow-to-region limit org-pos) | |
(setq pair (toggle-let-astah-search-let) | |
pos (car pair) ast (cdr pair)) | |
(when pos | |
(goto-char pos) | |
(cond | |
(ast (delete-backward-char 1)) | |
(t (insert "*"))) | |
(setq replaced t))))) | |
(cond | |
(replaced (message "toggle let-aster !")) | |
(t (message "let not found."))))) | |
;(define-key emacs-lisp-mode-map (kbd "C-8") 'toggle-let-astah) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment