diff --git a/evil-command-window.el b/evil-command-window.el index 5201d7bf..379e556a 100644 --- a/evil-command-window.el +++ b/evil-command-window.el @@ -1,4 +1,4 @@ -;;; evil-command-window.el --- Evil command line window implementation +;;; evil-command-window.el --- Evil command line window implementation -*- lexical-binding: t -*- ;; Author: Emanuel Evans ;; Maintainer: Vegard Øye diff --git a/evil-commands.el b/evil-commands.el index e1749ac0..f7180ff6 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -1,4 +1,4 @@ -;;; evil-commands.el --- Evil commands and operators +;;; evil-commands.el --- Evil commands and operators -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-common.el b/evil-common.el index f10a6d2a..92447c58 100644 --- a/evil-common.el +++ b/evil-common.el @@ -1,4 +1,4 @@ -;;; evil-common.el --- Common functions and utilities +;;; evil-common.el --- Common functions and utilities -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-core.el b/evil-core.el index 8b74fa75..09101e4b 100644 --- a/evil-core.el +++ b/evil-core.el @@ -1,4 +1,4 @@ -;;; evil-core.el --- Core functionality +;;; evil-core.el --- Core functionality -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-development.el b/evil-development.el index 203b5de8..7cebf5bb 100644 --- a/evil-development.el +++ b/evil-development.el @@ -1,4 +1,4 @@ -;;; evil-development.el --- Useful features for Evil developers +;;; evil-development.el --- Useful features for Evil developers -*- lexical-binding: t -*- ;; Author: Justin Burkett diff --git a/evil-digraphs.el b/evil-digraphs.el index f0d89a3d..e2d533a4 100644 --- a/evil-digraphs.el +++ b/evil-digraphs.el @@ -1,4 +1,4 @@ -;;; evil-digraphs.el --- Digraphs +;;; evil-digraphs.el --- Digraphs -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-ex.el b/evil-ex.el index f257f4ee..e35e5b6d 100644 --- a/evil-ex.el +++ b/evil-ex.el @@ -1,4 +1,4 @@ -;;; evil-ex.el --- Ex-mode +;;; evil-ex.el --- Ex-mode -*- lexical-binding: nil -*- ;; Author: Frank Fischer ;; Maintainer: Vegard Øye @@ -923,6 +923,33 @@ POS defaults to the current position of point." (when contexts (nth pos contexts)))) +(defun evil-parser--dexp (obj) + "Parse a numerical dollar-sign symbol. +Given e.g. $4, return 4." + (when (symbolp obj) + (let ((str (symbol-name obj))) + (save-match-data + (when (string-match "\\$\\([0-9]+\\)" str) + (string-to-number (match-string 1 str))))))) + +(defun evil-parser--dval (obj result) + "Substitute all dollar-sign symbols in OBJ. +Each dollar-sign symbol is replaced with the corresponding +element in RESULT, so that $1 becomes the first element, etc. +The special value $0 is substituted with the whole list RESULT. +If RESULT is not a list, all dollar-sign symbols are substituted with +RESULT." + (if (listp obj) + (mapcar (lambda (obj) (evil-parser--dval obj result)) obj) + (let ((num (evil-parser--dexp obj))) + (if num + (if (not (listp result)) + result + (if (eq num 0) + `(list ,@result) + (nth (1- num) result))) + obj)))) + (defun evil-parser (string symbol grammar &optional greedy syntax) "Parse STRING as a SYMBOL in GRAMMAR. If GREEDY is non-nil, the whole of STRING must match. @@ -1120,54 +1147,33 @@ The following symbols have reserved meanings within a grammar: ;; semantic action (when (and pair func (not syntax)) (setq result (car pair)) - (let* ((dexp - #'(lambda (obj) - (when (symbolp obj) - (let ((str (symbol-name obj))) - (save-match-data - (when (string-match "\\$\\([0-9]+\\)" str) - (string-to-number (match-string 1 str)))))))) - ;; traverse a tree for dollar expressions - (dval nil) - (dval - #'(lambda (obj) - (if (listp obj) - (mapcar dval obj) - (let ((num (funcall dexp obj))) - (if num - (if (not (listp result)) - result - (if (eq num 0) - `(list ,@result) - (nth (1- num) result))) - obj)))))) - (cond - ((null func) - (setq result nil)) - ;; lambda function - ((eq (car-safe func) 'lambda) - (if (memq symbol '(+ seq)) - (setq result `(funcall ,func ,@result)) - (setq result `(funcall ,func ,result)))) - ;; string replacement - ((or (stringp func) (stringp (car-safe func))) - (let* ((symbol (or (car-safe (cdr-safe func)) - (and (boundp 'context) context) - (car-safe (car-safe grammar)))) - (string (if (stringp func) func (car-safe func)))) - (setq result (car-safe (evil-parser string symbol grammar - greedy syntax))))) - ;; dollar expression - ((funcall dexp func) - (setq result (funcall dval func))) - ;; function call - ((listp func) - (setq result (funcall dval func))) - ;; symbol - (t - (if (memq symbol '(+ seq)) - (setq result `(,func ,@result)) - (setq result `(,func ,result)))))) + (cond + ((null func) + (setq result nil)) + ;; lambda function + ((eq (car-safe func) 'lambda) + (if (memq symbol '(+ seq)) + (setq result `(funcall ,func ,@result)) + (setq result `(funcall ,func ,result)))) + ;; string replacement + ((or (stringp func) (stringp (car-safe func))) + (let* ((symbol (or (car-safe (cdr-safe func)) + (and (boundp 'context) context) + (car-safe (car-safe grammar)))) + (string (if (stringp func) func (car-safe func)))) + (setq result (car-safe (evil-parser string symbol grammar + greedy syntax))))) + ;; dollar expression + ((evil-parser--dexp func) + (setq result (evil-parser--dval func result))) + ;; function call + ((listp func) + (setq result (evil-parser--dval func result))) + ;; symbol + (t + (if (memq symbol '(+ seq)) + (setq result `(,func ,@result)) + (setq result `(,func ,result))))) (setcar pair result)))) ;; weed out incomplete matches (when pair diff --git a/evil-integration.el b/evil-integration.el index 284f9d48..3eac3c5b 100644 --- a/evil-integration.el +++ b/evil-integration.el @@ -1,4 +1,4 @@ -;;; evil-integration.el --- Integrate Evil with other modules +;;; evil-integration.el --- Integrate Evil with other modules -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-jumps.el b/evil-jumps.el index 4afb2bd9..c02de01f 100644 --- a/evil-jumps.el +++ b/evil-jumps.el @@ -1,4 +1,4 @@ -;;; evil-jumps.el --- Jump list implementation +;;; evil-jumps.el --- Jump list implementation -*- lexical-binding: t -*- ;; Author: Bailey Ling diff --git a/evil-keybindings.el b/evil-keybindings.el index 83111872..3df4f982 100644 --- a/evil-keybindings.el +++ b/evil-keybindings.el @@ -1,4 +1,4 @@ -;;; evil-keybindings.el --- Add some Evil keybindings to other modules +;;; evil-keybindings.el --- Add some Evil keybindings to other modules -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-macros.el b/evil-macros.el index 51426497..42e18df8 100644 --- a/evil-macros.el +++ b/evil-macros.el @@ -1,4 +1,4 @@ -;;; evil-macros.el --- Macros +;;; evil-macros.el --- Macros -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-maps.el b/evil-maps.el index c57a33f8..214d8a61 100644 --- a/evil-maps.el +++ b/evil-maps.el @@ -1,4 +1,4 @@ -;;; evil-maps.el --- Default keymaps +;;; evil-maps.el --- Default keymaps -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-repeat.el b/evil-repeat.el index d9f1f90f..01168c9b 100644 --- a/evil-repeat.el +++ b/evil-repeat.el @@ -1,4 +1,4 @@ -;;; evil-repeat.el --- Repeat system +;;; evil-repeat.el --- Repeat system -*- lexical-binding: t -*- ;; Author: Frank Fischer ;; Maintainer: Vegard Øye diff --git a/evil-search.el b/evil-search.el index d77034e6..1989cab6 100644 --- a/evil-search.el +++ b/evil-search.el @@ -1,4 +1,4 @@ -;;; evil-search.el --- Search and substitute +;;; evil-search.el --- Search and substitute -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-states.el b/evil-states.el index ee136a32..9365678a 100644 --- a/evil-states.el +++ b/evil-states.el @@ -1,4 +1,4 @@ -;;; evil-states.el --- States +;;; evil-states.el --- States -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-test-helpers.el b/evil-test-helpers.el index 6f8d02f1..1461c8a5 100644 --- a/evil-test-helpers.el +++ b/evil-test-helpers.el @@ -1,4 +1,4 @@ -;;; evil-test-helpers.el --- unit test helpers for Evil -*- coding: utf-8 -*- +;;; evil-test-helpers.el --- unit test helpers for Evil -*- coding: utf-8; lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-types.el b/evil-types.el index 3cf9f2dd..be894afd 100644 --- a/evil-types.el +++ b/evil-types.el @@ -1,4 +1,4 @@ -;;; evil-types.el --- Type system +;;; evil-types.el --- Type system -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye diff --git a/evil-vars.el b/evil-vars.el index e42a087b..d5bb0978 100644 --- a/evil-vars.el +++ b/evil-vars.el @@ -1,4 +1,4 @@ -;;; evil-vars.el --- Settings and variables +;;; evil-vars.el --- Settings and variables -*- lexical-binding: t -*- ;; Author: Vegard Øye ;; Maintainer: Vegard Øye