branch: elpa/drupal-mode
commit 7d29d72a620727415215261fe5c3fd0a6831ff3b
Author: Arne Jørgensen <[email protected]>
Commit: Arne Jørgensen <[email protected]>
Added function to wrap string in t().
Bound to `C-c C-v C-t`.
Fixes #15.
---
drupal-mode.el | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drupal-mode.el b/drupal-mode.el
index c08a2108ce..b783da3424 100644
--- a/drupal-mode.el
+++ b/drupal-mode.el
@@ -195,6 +195,7 @@ Include path to the executable if it is not in your $PATH."
(define-key map [(control c) (control v) (control h)] #'drupal-insert-hook)
(define-key map [(control c) (control v) (control f)]
#'drupal-insert-function)
(define-key map [(control c) (control v) (control m)] #'drupal-module-name)
+ (define-key map [(control c) (control v) (control t)]
#'drupal-wrap-string-in-t-function)
(define-key map [(control a)] #'drupal-mode-beginning-of-line)
map)
"Keymap for `drupal-mode'")
@@ -421,6 +422,18 @@ buffer."
(find-file-other-window dd)
(auto-revert-tail-mode 1)))))
+(defun drupal-wrap-string-in-t-function ()
+ "If point is inside a string wrap the string in the t() function."
+ (interactive)
+ (when (eq (get-text-property (point) 'face) 'font-lock-string-face)
+ (save-excursion
+ (atomic-change-group
+ (search-backward-regexp "\\(\"\\|'\\)")
+ (insert "t(")
+ (forward-char)
+ (search-forward-regexp "\\(\"\\|'\\)")
+ (insert ")")))))
+
(defvar drupal-form-id-history nil