Frank Fischer avatar Frank Fischer committed 1250012

add special marks ( ) { }

Comments (0)

Files changed (1)

   "Returns t if `mark-char' is a global mark."
   (and (>= mark-char ?A) (<= mark-char ?z)))
 
+(defun vim:special-mark-p (mark-char)
+  "Returns t if `mark-char' is one of the special marks ( ) { }."
+  (member mark-char '(?\( ?\) ?{ ?})))
+
+(defconst vim:special-mark-functions-alist
+  '((?\( . vim:motion-bwd-sentence)
+    (?\) . vim:motion-fwd-sentence)
+    (?{  . vim:motion-bwd-paragraph)
+    (?}  . vim:motion-fwd-paragraph))
+  "Assocative list for special marks to corresponding functions.")
+
 (defun vim:set-mark (mark-char &optional pos)
   "Sets the mark `mark-char' to `pos' or (point)."
   (let (m)
       (unless m
         (setq m (make-marker))
         (push (cons mark-char m) vim:global-marks-alist)))
+     ((vim:special-mark-p mark-char)
+      (error "Can't set special mark '%c'" mark-char))
      (t (error "Unknown mark '%c'" mark-char)))
     (set-marker m (or pos (point)))))
 
               m
             (error "Global mark '%c' not in current buffer." mark-char))
         (error "No mark '%c' defined." mark-char))))
+   ((vim:special-mark-p mark-char)
+    (save-excursion
+      (funcall (cdr (assoc mark-char vim:special-mark-functions-alist)))
+      (point)))
    (t
     (error "Unknown mark: '%c'" mark-char))))
 
+(defun vim:set-change-mark (beg end)
+  "Sets the change mark . to `beg'."
+  (vim:set-mark ?. beg))
+
 (add-hook 'vim-mode-on-hook
 	  #'(lambda ()
 	      (add-hook 'before-change-functions 'vim:set-change-mark)))
 	  #'(lambda ()
 	      (remove-hook 'before-change-functions 'vim:set-change-mark)))
 
-(defun vim:set-change-mark (beg end)
-  "Sets the change mark . to `beg'."
-  (vim:set-mark ?. beg))
-
 (vim:defmotion vim:motion-left (exclusive count)
   "Move the cursor count characters left."
   (goto-char (max (line-beginning-position)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.