Reputation: 168229
I want to add functionality to javascript-mode
so that, whenever I save a Javascript file on the current buffer, it creates a minified file of it in a directory defined with relative path such as ../foo
with the same file name. How can I do that?
I am using Ubuntu as OS. Is there a good program that I should call in emacs for doing this?
Upvotes: 0
Views: 675
Reputation: 66099
You can add a function to the after-save-hook
, but make it specific to javascript mode, add the hook in the js-mode-hook
. Also, set add-hook
's fourth parameter LOCAL
to a non-nil value. For example:
(add-hook 'js-mode-hook
(lambda ()
(add-hook 'after-save-hook 'my-minify-function nil t)))
(defun my-minify-function ()
(shell-command (format "minify %s ../foo/%s"
(buffer-file-name)
(buffer-file-name))))
Upvotes: 2