Skip to content

Commit 7d29d72

Browse files
committed
Added function to wrap string in t().
Bound to `C-c C-v C-t`. Fixes #15.
1 parent 2517b39 commit 7d29d72

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drupal-mode.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ Include path to the executable if it is not in your $PATH."
195195
(define-key map [(control c) (control v) (control h)] #'drupal-insert-hook)
196196
(define-key map [(control c) (control v) (control f)] #'drupal-insert-function)
197197
(define-key map [(control c) (control v) (control m)] #'drupal-module-name)
198+
(define-key map [(control c) (control v) (control t)] #'drupal-wrap-string-in-t-function)
198199
(define-key map [(control a)] #'drupal-mode-beginning-of-line)
199200
map)
200201
"Keymap for `drupal-mode'")
@@ -421,6 +422,18 @@ buffer."
421422
(find-file-other-window dd)
422423
(auto-revert-tail-mode 1)))))
423424

425+
(defun drupal-wrap-string-in-t-function ()
426+
"If point is inside a string wrap the string in the t() function."
427+
(interactive)
428+
(when (eq (get-text-property (point) 'face) 'font-lock-string-face)
429+
(save-excursion
430+
(atomic-change-group
431+
(search-backward-regexp "\\(\"\\|'\\)")
432+
(insert "t(")
433+
(forward-char)
434+
(search-forward-regexp "\\(\"\\|'\\)")
435+
(insert ")")))))
436+
424437

425438

426439
(defvar drupal-form-id-history nil

0 commit comments

Comments
 (0)