From 9c274c29f566f4933c6911e0bfff1dca17bea2b9 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Thu, 13 Aug 2015 21:33:11 -0700 Subject: [PATCH] sync-function-names with imalison:js-sync-function-names --- .../emacs.d/load.d/sync-function-names.el | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 dotfiles/emacs.d/load.d/sync-function-names.el diff --git a/dotfiles/emacs.d/load.d/sync-function-names.el b/dotfiles/emacs.d/load.d/sync-function-names.el new file mode 100644 index 00000000..53155185 --- /dev/null +++ b/dotfiles/emacs.d/load.d/sync-function-names.el @@ -0,0 +1,35 @@ +(defun imalison:get-args-location-or-eol () + (save-excursion + (end-of-line) + (let ((bound (point))) + (beginning-of-line) + (or (let ((value (re-search-forward "\(" bound t))) + (when value (- value 1))) (progn (end-of-line) (point)))))) + +(defun imalison:js-get-params-string () + (save-excursion + (end-of-line) + (let ((bound (point))) + (beginning-of-line) + (if (re-search-forward "\(" bound t) + (let ((start (progn (backward-char) (point))) + (end (progn (forward-sexp) (point)))) + (buffer-substring (+ start 1) (- end 1))) + "")))) + +(defun imalison:js-get-left-name () + (save-excursion + (beginning-of-line) + (re-search-forward "\.?\\(\[^ .:\]*\\)\[ =:\n\]") + (match-string-no-properties 1))) + +(defun imalison:js-sync-function-names () + (interactive) + (save-excursion + (let ((params-start (imalison:get-args-location-or-eol)) + (end (progn (end-of-line) (point)))) + (beginning-of-line) + (or (re-search-forward "\[ =:\]+" end t) + (end-of-line)) + (delete-region (point) params-start) + (insert (format "function %s" (imalison:js-get-left-name))))))