aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2015-11-13 14:28:57 +0200
committerSergey Poznyakoff <gray@gnu.org>2015-11-13 16:15:34 +0200
commit94745f4df6a77e9e36dc47a1b48f434c1fe03f5e (patch)
treeaeb3b3f3d5053a9d8a356835f6b1a04ce0d7f69d
parentd9afdff58c67b1d3e9fd7e59d12a98dddc58482f (diff)
downloadvcl-mode-94745f4df6a77e9e36dc47a1b48f434c1fe03f5e.tar.gz
vcl-mode-94745f4df6a77e9e36dc47a1b48f434c1fe03f5e.tar.bz2
New function: vcl-match-paren
-rw-r--r--vcl-mode.el77
1 files changed, 74 insertions, 3 deletions
diff --git a/vcl-mode.el b/vcl-mode.el
index 449252c..90e1ce6 100644
--- a/vcl-mode.el
+++ b/vcl-mode.el
@@ -24,11 +24,12 @@
24;; run: 24;; run:
25;; emacs -batch -f batch-byte-compile vcl-mode.el 25;; emacs -batch -f batch-byte-compile vcl-mode.el
26;; Install the file vcl-mode.elc (and, optionally, vcl-mode.el) to 26;; Install the file vcl-mode.elc (and, optionally, vcl-mode.el) to
27;; any directory in your Emacs load-path. 27;; a directory in your Emacs load-path.
28 28
29;; Customization: 29;; Customization:
30;; To your .emacs or site-start.el add: 30;; To your .emacs or site-start.el add:
31;; (autoload 'vcl-mode "vcl-mode") 31;; (autoload 'vcl-mode "vcl-mode" "Major mode for Varnish VCL sources" t)
32;; (add-to-list 'auto-mode-alist (cons (purecopy "\\.vcl\\'") 'vcl-mode))
32 33
33(require 'cc-langs) 34(require 'cc-langs)
34 35
@@ -36,7 +37,8 @@
36 "Keymap used in vcl-mode buffers.") 37 "Keymap used in vcl-mode buffers.")
37(if vcl-mode-map 38(if vcl-mode-map
38 nil 39 nil
39 (setq vcl-mode-map (c-make-inherited-keymap))) 40 (setq vcl-mode-map (c-make-inherited-keymap))
41 (define-key vcl-mode-map "\C-c%" 'vcl-match-paren))
40 42
41(defvar vcl-mode-syntax-table 43(defvar vcl-mode-syntax-table
42 (let ((st (make-syntax-table))) 44 (let ((st (make-syntax-table)))
@@ -344,6 +346,75 @@
344 (1 (ignore (vcl-sharp-comment-syntax)))) 346 (1 (ignore (vcl-sharp-comment-syntax))))
345 )) 347 ))
346 348
349(defun vcl-match-paren (&optional arg)
350 "If point is on a parenthesis (including VCL multi-line string delimiter),
351find the matching one and move point to it.
352With ARG, do it that many times.
353"
354 (interactive "p")
355 (let ((n (or arg 1))
356 (matcher (cond
357 ((looking-at "\\s\(")
358 (cons
359 (lexical-let ((s (buffer-substring
360 (match-beginning 0)
361 (match-end 0))))
362 (lambda ()
363 (search-forward s)
364 (backward-char)))
365 (lambda ()
366 (forward-list)
367 (backward-char))))
368 ((looking-at "\\s\)")
369 (cons
370 (lexical-let ((s (buffer-substring
371 (match-beginning 0)
372 (match-end 0))))
373 (lambda ()
374 (search-backward s)))
375 (lambda ()
376 (forward-char)
377 (backward-list))))
378 ((or (looking-at "{\"")
379 (save-excursion
380 (backward-char)
381 (looking-at "{\"")))
382 (cons
383 (lambda ()
384 (search-forward "{\""))
385 (lambda ()
386 (search-forward-regexp "\"}")
387 (backward-char))))
388 ((or (looking-at "\"}")
389 (save-excursion
390 (backward-char)
391 (looking-at "\"}")))
392 (cons
393 (lambda ()
394 (search-backward "\"}"))
395 (lambda ()
396 (search-backward-regexp "{\"")))))))
397 (if (not matcher)
398 (message "Point not at parenthesis")
399 (condition-case err
400 (let ((fx (car matcher))
401 (fn (cdr matcher)))
402 (catch 'stop
403 (while t
404 (funcall fn)
405 (setq n (1- n))
406 (if (= n 0)
407 (throw 'stop t)
408 (condition-case e
409 (funcall fx)
410 (search-failed
411 (message "Not enough groups to satisfy the request")
412 (throw 'stop t)))))))
413
414 (scan-error (goto-char (nth 2 err))
415 (message "%s" (nth 1 err)))
416 (search-failed (message "Unbalanced %s" (cdr err)))))))
417
347;;;###autoload 418;;;###autoload
348(add-to-list 'auto-mode-alist (cons (purecopy "\\.vcl\\'") 'vcl-mode)) 419(add-to-list 'auto-mode-alist (cons (purecopy "\\.vcl\\'") 'vcl-mode))
349 420

Return to:

Send suggestions and report system problems to the System administrator.