[libcode-tidyall-perl] 147/374: add etc/editors/tidyall.el

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:26:07 UTC 2013


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libcode-tidyall-perl.

commit 1ca6127b935e6b79ec5bd8a6a4f3401b85210f77
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Thu Aug 16 17:35:11 2012 -0700

    add etc/editors/tidyall.el
---
 bin/tidyall            |   25 +++++++++++---
 etc/editors/tidyall.el |   86 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+), 4 deletions(-)

diff --git a/bin/tidyall b/bin/tidyall
index b8b28a8..432e454 100755
--- a/bin/tidyall
+++ b/bin/tidyall
@@ -382,6 +382,11 @@ above the plugin sections. Replace dashes with underscores. e.g.
 
 If an option is passed in both places, the command-line takes precedence.
 
+=head1 EXIT STATUS
+
+C<tidyall> will exit with status 1 if any errors occurred while processing
+files, and 0 otherwise.
+
 =head1 MODES
 
 You can use tidyall in a number of different contexts, and you may not want to
@@ -456,17 +461,29 @@ L<Time::Duration::Parse|Time::Duration::Parse>. It defaults to "1h" (1 hour).
 
 You can turn off backups with C<--no-backups>.
 
-=head1 EXIT STATUS
+=head1 RELATED TOOLS
 
-C<tidyall> will exit with status 1 if any errors occurred while processing
-files, and 0 otherwise.
+=over
 
-=head1 SUBVERSION PRECOMMIT
+=item *
+
+C<etc/editors/tidyall.el> in this distribution is an Emacs function that runs
+C<tidyall> on the current buffer. You can assign this to ctrl-t or your
+favorite key binding.
+
+=item *
 
 L<Code::TidyAll::SVN::Precommit|Code::TidyAll::SVN::Precommit> implements a
 subversion precommit hook that checks if all files are tidied and valid
 according to C<tidyall>, and rejects the commit if not.
 
+=item *
+
+L<Test::Code::TidyAll|Test::Code::TidyAll> is a testing library to check that
+all the files in your project are in a tidied and valid state.
+
+=back
+
 =head1 KNOWN BUGS
 
 =over
diff --git a/etc/editors/tidyall.el b/etc/editors/tidyall.el
new file mode 100644
index 0000000..d672afc
--- /dev/null
+++ b/etc/editors/tidyall.el
@@ -0,0 +1,86 @@
+;;; tidyall.el -- Apply tidyall (https://metacpan.org/module/tidyall) to the current buffer
+
+;; Copyright (C) 2012  Jonathan Swartz
+
+;; Author: Jonathan Swartz <swartz at pobox.com>
+;; Keywords: extensions
+;; Status: Tested with Emacs 24.1.1
+
+;; This file is *NOT* part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+
+;; This package implements a single function, tidyall-buffer, which
+;; runs tidyall (https://metacpan.org/module/tidyall) on the current buffer.
+
+;; More specifically, the function runs tidyall on the current file, outputting
+;; its results to a temporary file; then replaces the contents of the current
+;; buffer with the contents of the temporary file and saves the buffer.
+;; Any modifications should be undoable.
+
+;; If tidyall generates any errors, the buffer is not changed, and a separate window
+;; called *tidyall-output* is opened displaying the error.
+
+;; e.g. To assign this command to ctrl-t in perl-mode and pod-mode:
+;;
+;;   (setq perl-mode-hook
+;;        '(lambda ()
+;;           (local-set-key "\C-t" 'tidyall-buffer)
+;;           ))
+;;   
+;;   (setq pod-mode-hook
+;;        '(lambda ()
+;;           (local-set-key "\C-t" 'tidyall-buffer)
+;;           ))
+;;
+;; or to assign it globally:
+;;
+;;   (global-set-key "\C-t" 'tidyall-buffer)
+;;
+;; (This replaces the default binding to transpose-chars, which I never use but ymmv.)
+
+;; The variable `tidyall-cmd` contains the path to the tidyall command.
+;;
+
+(setq tidyall-cmd "tidyall")
+
+(defun tidyall-buffer ()
+  "Run tidyall on the current file."
+  (interactive)
+  (let ((file (buffer-file-name)))
+    (cond (file
+           (if (buffer-modified-p)
+               (save-buffer))
+           (let* ((cmd (concat tidyall-cmd " --refresh-cache --output-suffix .tdy -m editor " file))
+                  (tidyall-buffer (get-buffer-create "*tidyall-output*"))
+                  (result (shell-command cmd tidyall-buffer))
+                  (tidied-file (concat file ".tdy"))
+                  (output (with-current-buffer tidyall-buffer (buffer-string)))
+                  (window-positions (mapcar (lambda (w) (window-start w)) (window-list)))
+                  (orig-point (point)))
+             (when (string-match "[\t\n ]*$" output)
+               (replace-match "" nil nil output))
+             (cond ((zerop result)
+                    (cond ((string-match "\\[tidied\\]" output)
+                           (cond ((file-exists-p tidied-file)
+                                  (erase-buffer)
+                                  (insert-file-contents tidied-file)
+                                  (delete-file tidied-file)
+                                  (mapcar (lambda (w) (set-window-start w (pop window-positions))) (window-list))
+                                  (goto-char orig-point)
+                                  (save-buffer))
+                                 (t
+                                  (message (concat "Could not find '" tidied-file "'!")))))))
+                   (t
+                    (message nil)
+                    (split-window-vertically)
+                    (set-window-buffer (next-window) tidyall-buffer))))))))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git



More information about the Pkg-perl-cvs-commits mailing list