From 3b7c727affc6c06c975b798bcfb68b02fcef4995 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 14 Dec 2015 05:19:25 -0500 Subject: [PATCH] Extract module-sh defuns into defuns-sh.el --- modules/lib/defuns-sh.el | 45 +++++++++++++++++++++++++++++++++++++++ modules/module-sh.el | 46 +++++----------------------------------- 2 files changed, 50 insertions(+), 41 deletions(-) create mode 100644 modules/lib/defuns-sh.el diff --git a/modules/lib/defuns-sh.el b/modules/lib/defuns-sh.el new file mode 100644 index 000000000..1502e1110 --- /dev/null +++ b/modules/lib/defuns-sh.el @@ -0,0 +1,45 @@ +;;; defuns-sh.el + +(defvar sh-extra-font-lock--keywords + '((narf/sh-extra-font-lock--match-var-in-double-quoted-string + (2 font-lock-variable-name-face prepend)))) + +;;;###autoload +(defun narf/sh-extra-font-lock--is-in-double-quoted-string () + "Non-nil if point in inside a double-quoted string." + (let ((state (syntax-ppss))) + (eq (nth 3 state) ?\"))) + +;;;###autoload +(defun narf/sh-extra-font-lock--match-var-in-double-quoted-string (limit) + "Search for variables in double-quoted strings bounded by LIMIT." + (let (res) + (while + (and (setq res + (re-search-forward + "\\$\\({#?\\)?\\([[:alpha:]_][[:alnum:]_]*\\|[-#?@!]\\)" + limit t)) + (not (narf/sh-extra-font-lock--is-in-double-quoted-string)))) + res)) + +;;;###autoload +(defun narf|sh-extra-font-lock-activate () + "Activate sh-extra-font-lock." + (interactive) + (font-lock-add-keywords nil sh-extra-font-lock--keywords) + (if (fboundp 'font-lock-flush) + (font-lock-flush) + (when font-lock-mode + (with-no-warnings + (font-lock-fontify-buffer))))) + +;;;###autoload +(defun narf/inf-shell () + (let* ((dest-sh (symbol-name sh-shell)) + (sh-shell-file dest-sh)) + (sh-shell-process t) + (with-current-buffer "*shell*" + (rename-buffer (format "*shell [%s]*" dest-sh))))) + +(provide 'defuns-sh) +;;; defuns-sh.el ends here diff --git a/modules/module-sh.el b/modules/module-sh.el index 47a7fa500..3eff7cf5a 100644 --- a/modules/module-sh.el +++ b/modules/module-sh.el @@ -1,51 +1,15 @@ ;;; module-sh.el --- description (after! sh-script - (define-repl! sh-mode narf-inf-shell) - (add-hook! sh-mode 'flycheck-mode) - - (defun sh-extra-font-lock--is-in-double-quoted-string () - "Non-nil if point in inside a double-quoted string." - (let ((state (syntax-ppss))) - (eq (nth 3 state) ?\"))) - - (defun sh-extra-font-lock--match-var-in-double-quoted-string (limit) - "Search for variables in double-quoted strings bounded by LIMIT." - (let (res) - (while - (and (setq res - (re-search-forward - "\\$\\({#?\\)?\\([[:alpha:]_][[:alnum:]_]*\\|[-#?@!]\\)" - limit t)) - (not (sh-extra-font-lock--is-in-double-quoted-string)))) - res)) - - (defvar sh-extra-font-lock--keywords - '((sh-extra-font-lock--match-var-in-double-quoted-string - (2 font-lock-variable-name-face prepend)))) - - (defun sh-extra-font-lock-activate () - "Activate sh-extra-font-lock." - (interactive) - (font-lock-add-keywords nil sh-extra-font-lock--keywords) - (if (fboundp 'font-lock-flush) - (font-lock-flush) - (when font-lock-mode - (with-no-warnings - (font-lock-fontify-buffer))))) - - (add-hook 'sh-mode-hook 'sh-script-extra-font-lock-activate) - ;; [pedantry intensifies] (defadvice sh-mode (after sh-mode-rename-modeline activate) (setq mode-name "sh")) - (defun narf-inf-shell () - (let* ((dest-sh (symbol-name sh-shell)) - (sh-shell-file dest-sh)) - (sh-shell-process t) - (with-current-buffer "*shell*" - (rename-buffer (format "*shell [%s]*" dest-sh)))))) + (define-repl! sh-mode narf/inf-shell) + (add-hook! sh-mode 'flycheck-mode) + + ;; Fontify variables in strings + (add-hook 'sh-mode-hook 'narf|sh-extra-font-lock-activate)) (provide 'module-sh) ;;; module-sh.el ends here