Browse Source

Merge pull request #9 from axyz/melpa-naming

Adopt melpa naming convention as in #8
pull/10/head
Brett Langdon 11 years ago
parent
commit
a9aba98924
1 changed files with 12 additions and 12 deletions
  1. +12
    -12
      jsfmt.el

+ 12
- 12
jsfmt.el View File

@ -24,17 +24,17 @@
:type 'string :type 'string
:group 'js) :group 'js)
(defun js--goto-line (line)
(defun jsfmt--goto-line (line)
(goto-char (point-min)) (goto-char (point-min))
(forward-line (1- line))) (forward-line (1- line)))
(defalias 'js--kill-whole-line
(defalias 'jsfmt--kill-whole-line
(if (fboundp 'kill-whole-line) (if (fboundp 'kill-whole-line)
#'kill-whole-line #'kill-whole-line
#'kill-entire-line)) #'kill-entire-line))
;; Delete the current line without putting it in the kill-ring. ;; Delete the current line without putting it in the kill-ring.
(defun js--delete-whole-line (&optional arg)
(defun jsfmt--delete-whole-line (&optional arg)
;; Emacs uses both kill-region and kill-new, Xemacs only uses ;; Emacs uses both kill-region and kill-new, Xemacs only uses
;; kill-region. In both cases we turn them into operations that do ;; kill-region. In both cases we turn them into operations that do
;; not modify the kill ring. This solution does depend on the ;; not modify the kill ring. This solution does depend on the
@ -43,9 +43,9 @@
(flet ((kill-region (beg end) (flet ((kill-region (beg end)
(delete-region beg end)) (delete-region beg end))
(kill-new (s) ())) (kill-new (s) ()))
(js--kill-whole-line arg)))
(jsfmt--kill-whole-line arg)))
(defun js--apply-rcs-patch (patch-buffer)
(defun jsfmt--apply-rcs-patch (patch-buffer)
"Apply an RCS-formatted diff from PATCH-BUFFER to the current "Apply an RCS-formatted diff from PATCH-BUFFER to the current
buffer." buffer."
(let ((target-buffer (current-buffer)) (let ((target-buffer (current-buffer))
@ -65,7 +65,7 @@ buffer."
(goto-char (point-min)) (goto-char (point-min))
(while (not (eobp)) (while (not (eobp))
(unless (looking-at "^\\([ad]\\)\\([0-9]+\\) \\([0-9]+\\)") (unless (looking-at "^\\([ad]\\)\\([0-9]+\\) \\([0-9]+\\)")
(error "invalid rcs patch or internal error in js--apply-rcs-patch"))
(error "invalid rcs patch or internal error in jsfmt--apply-rcs-patch"))
(forward-line) (forward-line)
(let ((action (match-string 1)) (let ((action (match-string 1))
(from (string-to-number (match-string 2))) (from (string-to-number (match-string 2)))
@ -82,11 +82,11 @@ buffer."
(insert text))))) (insert text)))))
((equal action "d") ((equal action "d")
(with-current-buffer target-buffer (with-current-buffer target-buffer
(js--goto-line (- from line-offset))
(jsfmt--goto-line (- from line-offset))
(incf line-offset len) (incf line-offset len)
(js--delete-whole-line len)))
(jsfmt--delete-whole-line len)))
(t (t
(error "invalid rcs patch or internal error in js--apply-rcs-patch")))))))))
(error "invalid rcs patch or internal error in jsfmt--apply-rcs-patch")))))))))
(defun run-jsfmt (save &optional ast &optional) (defun run-jsfmt (save &optional ast &optional)
"Formats the current buffer according to the jsfmt tool." "Formats the current buffer according to the jsfmt tool."
@ -124,7 +124,7 @@ buffer."
(progn (progn
(kill-buffer errbuf) (kill-buffer errbuf)
(message "Buffer is already jsfmted")) (message "Buffer is already jsfmted"))
(js--apply-rcs-patch patchbuf)
(jsfmt--apply-rcs-patch patchbuf)
(kill-buffer errbuf) (kill-buffer errbuf)
(message "Applied jsfmt")) (message "Applied jsfmt"))
(message "Could not apply jsfmt. Check errors for details") (message "Could not apply jsfmt. Check errors for details")
@ -183,11 +183,11 @@ buffer."
(when (memq major-mode '(js-mode js2-mode js3-mode)) (jsfmt-load-ast))) (when (memq major-mode '(js-mode js2-mode js3-mode)) (jsfmt-load-ast)))
;;;###autoload ;;;###autoload
(defun jsfmt-ast-mode ()
(defun jsfmt-ast ()
"Add this to .emacs to run enabling jsfmt loading .ast files as javascript and saving "Add this to .emacs to run enabling jsfmt loading .ast files as javascript and saving
the javascript back as ast the javascript back as ast
(add-to-list 'auto-mode-alist '(\"\\.ast$\" . (lambda() (add-to-list 'auto-mode-alist '(\"\\.ast$\" . (lambda()
(jsfmt-ast-mode)
(jsfmt-ast)
(js-mode))))" (js-mode))))"
(interactive) (interactive)
;; before saving convert to AST ;; before saving convert to AST


Loading…
Cancel
Save