Permalink
Browse files

Enhance the % motion and zc,zo functions.

  • Loading branch information...
1 parent 1ac3948 commit 1b9e81f21fcc2f2b4b13967b7330d960520460a3 @winfred-lu committed Jan 25, 2013
Showing with 61 additions and 7 deletions.
  1. +61 −0 winfred-evil.el
  2. +0 −7 winfred-keys.el
View
@@ -120,6 +120,61 @@
(define-key evil-normal-state-map "\C-]" 'etags-select-find-tag-at-point)
(define-key evil-normal-state-map "\M-." 'etags-select-find-tag)
+(defun wf-jump-item ()
+ "An enhancement to evil-jump-item (%) for c-mode.
+It is able to jump between comments or conditionals."
+ (interactive)
+ (cond
+ ((and (not (string= major-mode "c-mode"))
+ (not (string= major-mode "c++-mode")))
+ (evil-jump-item))
+ ((or (and (char-equal (preceding-char) ?/)
+ (char-equal (following-char) ?*))
+ (and (char-equal (following-char) ?/)
+ (char-equal (char-after (+ 1 (point))) ?*)))
+ (search-forward "*/"))
+ ((or (and (char-equal (preceding-char) ?*)
+ (char-equal (following-char) ?/))
+ (and (char-equal (following-char) ?*)
+ (char-equal (char-after (+ 1 (point))) ?/)))
+ (search-backward "/*"))
+ ((string-match "^[ \t]*#[ \t]*\\(if\\|elif\\|else\\)" (thing-at-point 'line))
+ (progn
+ (when (fboundp 'hide-ifdef-mode)
+ (hide-ifdef-mode 1))
+ (hif-find-next-relevant)
+ (while (hif-looking-at-ifX)
+ (hif-ifdef-to-endif)
+ (hif-find-next-relevant))))
+ ((string-match "^[ \t]*#[ \t]*endif" (thing-at-point 'line))
+ (progn
+ (when (fboundp 'hide-ifdef-mode)
+ (hide-ifdef-mode 1))
+ (hif-endif-to-ifdef)))
+ (t (evil-jump-item))))
+
+(defun wf-close-fold ()
+ "An enhancement to evil-close-fold (zc) for c-mode to be able to hide conditionals."
+ (interactive)
+ (if (string-match "^[ \t]*#[ \t]*\\(if\\|elif\\|else\\|endif\\)"
+ (thing-at-point 'line))
+ (progn (when (fboundp 'hide-ifdef-mode)
+ (hide-ifdef-mode 1))
+ (when (fboundp 'hide-ifdef-block)
+ (hide-ifdef-block)))
+ (evil-close-fold)))
+
+(defun wf-open-fold ()
+ "An enhancement to evil-open-fold (zc) for c-mode to be able to show the hidden conditionals."
+ (interactive)
+ (if (string-match "^[ \t]*#[ \t]*\\(if\\|elif\\|else\\|endif\\)"
+ (thing-at-point 'line))
+ (progn (when (fboundp 'hide-ifdef-mode)
+ (hide-ifdef-mode 1))
+ (when (fboundp 'show-ifdef-block)
+ (show-ifdef-block)))
+ (evil-open-fold)))
+
;;;;;; key bindings according to major mode ;;;;;;
@@ -129,6 +184,12 @@
"J" 'bookmark-bmenu-this-window
"K" 'bookmark-bmenu-delete)))
+(add-hook 'c-mode-common-hook
+ '(lambda ()
+ (define-key evil-motion-state-map "%" 'wf-jump-item)
+ (define-key evil-normal-state-map "zo" 'wf-open-fold)
+ (define-key evil-normal-state-map "zc" 'wf-close-fold)))
+
(eval-after-load "browse-kill-ring"
'(progn
(evil-define-key 'emacs browse-kill-ring-mode-map
View
@@ -53,13 +53,6 @@
(define-key artist-mode-map "\C-c\C-o" 'artist-ido-select-operation)
(define-key artist-mode-map "\C-c\C-s" 'artist-ido-select-settings)))
-(add-hook 'c-mode-common-hook
- '(lambda ()
- (define-key c-mode-base-map "\C-c\C-f" 'c-forward-conditional)
- (define-key c-mode-base-map "\C-c\C-b" 'c-backward-conditional)
- (define-key c-mode-base-map "\C-c\C-n" 'c-down-conditional-with-else)
- (define-key c-mode-base-map "\C-c\C-p" 'c-up-conditional-with-else)))
-
(add-hook 'cscope-list-entry-hook
'(lambda ()
(evil-emacs-state)

0 comments on commit 1b9e81f

Please sign in to comment.