Skip to content
Browse files

Merge remote branch 'stepnem/master'

Conflicts:
	vimpulse-surround.el
  • Loading branch information...
2 parents ace333d + f4c6864 commit a8c05e999f867e5d04b735ff9eeebf97f18eb8ae @timcharper committed
Showing with 44 additions and 28 deletions.
  1. +44 −28 vimpulse-surround.el
View
72 vimpulse-surround.el
@@ -2,12 +2,12 @@
;; Copyright (C) 2010 Tim Harper
;;
-;; Author: Tim Harper
-;; Maintainer: Tim Harper <timcharper at gmail dat com>
+;; Author: Tim Harper <timcharper at gmail dat com>
;; Please send bug reports to the mailing list (see below).
;; Created: July 23 2010
+;; Time-stamp: "2010-08-19 18:27:50 CEST stepnem"
;; Version: 0.1+git
-;; Keywords: emulations, viper
+;; Keywords: emulations, vimpulse
;; Human-Keywords: vim, visual-mode, surround.vim
;; Mailing list: <implementations-list at lists.ourproject.org>
;; Subscribe: http://tinyurl.com/implementations-list
@@ -21,19 +21,23 @@
;; `vimpulse-surround' emulates surround.vim, a popular Vim plugin.
;;
-;; Requires a recent Vimpulse version. More information on Vimpulse and how to
-;; get it can be found here:
+;; The functionality is wrapped into a global minor mode, enabled by default.
+;;
+;; (require 'vimpulse-surround) is all you need to get going.
+;;
+;; The code requires a recent Vimpulse version. More information on Vimpulse
+;; and how to get it can be found here:
;; http://www.assembla.com/spaces/vimpulse
-;; Tested with GNU Emacs 23.2
+;; Tested with GNU Emacs 23.2 and 24 (development version)
;;; Code:
(require 'vimpulse)
(defgroup vimpulse-surround nil
- "surround.vim in Emacs"
+ "surround.vim for Emacs"
:prefix "vimpulse-surround-"
:group 'vimpulse)
@@ -45,21 +49,22 @@
("}" . ("{" . "}"))
("{" . ("{ " . " }"))
("#" . ("#{" . "}"))
- ("t" . 'vimpulse-surround-read-tag)
- ("<" . 'vimpulse-surround-read-tag))
+ ("t" . vimpulse-surround-read-tag)
+ ("<" . vimpulse-surround-read-tag))
"Alist of surround items.
Each item is of the form (TRIGGER . (LEFT . RIGHT)), all strings.
+Alternatively, a function can be put in place of (LEFT . RIGHT).
This only affects inserting pairs, not deleting or changing them."
:group 'vimpulse-surround
:type '(repeat (cons (regexp :tag "Key")
(symbol :tag "Surround pair"))))
(defun vimpulse-surround-char-to-pair (char)
- (let ((pairs (or (vimpulse-unquote (assoc-default char vimpulse-surround-pairs))
- (cons char char))))
- (if (symbolp pairs)
- (funcall pairs)
- pairs)))
+ (let ((pair (or (assoc-default char vimpulse-surround-pairs)
+ (cons char char))))
+ (if (functionp pair)
+ (funcall pair)
+ pair)))
(defvar *vimpulse-surrounding* nil
"Internal variable set by `vimpulse-surround-define-text-object'.
@@ -116,11 +121,9 @@ It triggers `vimpulse-change'. Nothing to see here, move along.")
(mapcar (lambda (key) (concat "s" key)) keys))
(defmacro vimpulse-surround-define-text-object (object args &rest body)
- (let (forward-args
- strip-keys
- (strip-object-name (intern (concat (symbol-name object) "-strip")))
- keys
- (docstring (pop body)))
+ (let ((strip-object-name (intern (concat (symbol-name object) "-strip")))
+ (docstring (pop body))
+ forward-args strip-keys keys)
(while (keywordp (car body))
(setq keyword (pop body))
(cond
@@ -187,9 +190,10 @@ range, dispatch to `vimpulse-surround-delete'.
Otherwise, dispatch to `vimpulse-delete'."
(interactive)
(let (*vimpulse-surrounding*)
- (when (not beg) (let ((range (vimpulse-range)))
- (setq beg (car range)
- end (cadr range))))
+ (unless beg
+ (let ((range (vimpulse-range)))
+ (setq beg (car range)
+ end (cadr range))))
(if *vimpulse-surrounding*
(vimpulse-surround-delete beg end (eq *vimpulse-surrounding* 'strip))
(vimpulse-delete beg end dont-save))))
@@ -201,19 +205,22 @@ range, dispatch to `vimpulse-surround-change'.
Otherwise, dispatch to `vimpulse-change'."
(interactive)
(let (*vimpulse-surrounding*)
- (when (not beg) (let ((range (vimpulse-range)))
- (setq beg (car range)
- end (cadr range))))
+ (unless beg
+ (let ((range (vimpulse-range)))
+ (setq beg (car range)
+ end (cadr range))))
(if *vimpulse-surrounding*
(vimpulse-surround-change beg end (eq *vimpulse-surrounding* 'strip))
(vimpulse-change beg end dont-save))))
+(add-to-list 'vimpulse-newline-cmds 'vimpulse-change-surround-or-change)
+(add-to-list 'vimpulse-newline-cmds 'vimpulse-delete-surround-or-delete)
+
(define-key viper-vi-basic-map "d" 'vimpulse-delete-surround-or-delete)
(define-key viper-vi-basic-map "c" 'vimpulse-change-surround-or-change)
(define-key vimpulse-visual-basic-map "s" 'vimpulse-surround-region)
(define-key vimpulse-visual-basic-map "S" 'vimpulse-Surround-region)
-
(vimpulse-surround-define-text-object vimpulse-surround-paren (arg)
"Select surrounding parentheses."
:keys '("b" ")")
@@ -221,9 +228,9 @@ Otherwise, dispatch to `vimpulse-change'."
(vimpulse-paren-range arg ?\( nil t))
(vimpulse-surround-define-text-object vimpulse-surround-bracket (arg)
- "Select surrounding brackets."
:keys '("]")
:strip-keys '("[")
+ "Select surrounding square brackets."
(vimpulse-paren-range arg ?\[ nil t))
(vimpulse-surround-define-text-object vimpulse-surround-brace (arg)
@@ -233,9 +240,9 @@ Otherwise, dispatch to `vimpulse-change'."
(vimpulse-paren-range arg ?\{ nil t))
(vimpulse-surround-define-text-object vimpulse-surround-angle (arg)
- "Select surrounding curly braces."
:keys '(">")
:strip-keys '("<")
+ "Select surrounding angle brackets."
(vimpulse-paren-range arg ?< nil t))
(vimpulse-surround-define-text-object vimpulse-surround-single-quote (arg)
@@ -248,5 +255,14 @@ Otherwise, dispatch to `vimpulse-change'."
:keys '("\"")
(vimpulse-quote-range arg ?\" t))
+(define-minor-mode vimpulse-surround-mode
+ "Emulate the surround.vim Vim plugin in Vimpulse."
+ t nil :global t)
+
+(vimpulse-define-key 'vimpulse-surround-mode 'vi-state "d" 'vimpulse-delete-surround-or-delete)
+(vimpulse-define-key 'vimpulse-surround-mode 'vi-state "c" 'vimpulse-change-surround-or-change)
+
+(vimpulse-define-key 'vimpulse-surround-mode 'visual-state "s" 'vimpulse-surround-region)
+
(provide 'vimpulse-surround)
;;; vimpulse-surround.el ends here

0 comments on commit a8c05e9

Please sign in to comment.
Something went wrong with that request. Please try again.