[macemacsjp-cvs 230] CVS update: CarbonEmacsPackage/GPL/mac

Back to archive index

Seiji Zenitani zenit****@users*****
2006年 1月 12日 (木) 20:37:29 JST


Index: CarbonEmacsPackage/GPL/mac/mac-preview-mode.el
diff -u CarbonEmacsPackage/GPL/mac/mac-preview-mode.el:1.1 CarbonEmacsPackage/GPL/mac/mac-preview-mode.el:removed
--- CarbonEmacsPackage/GPL/mac/mac-preview-mode.el:1.1	Sun Oct 23 13:18:04 2005
+++ CarbonEmacsPackage/GPL/mac/mac-preview-mode.el	Thu Jan 12 20:37:29 2006
@@ -1,144 +0,0 @@
-;;; mac-preview-mode.el --- a print-preview extension to Carbon Emacsen
-
-;; Copyright (C) 2005  Seiji Zenitani <zenit****@mac*****>
-
-
-(defadvice ps-print-buffer-with-faces
-  (around mac-preview-print())
-  (require 'pdf-preview)
-  (pdf-preview-buffer-with-faces))
-(defadvice ps-print-region-with-faces
-  (around mac-preview-print())
-  (require 'pdf-preview)
-  (pdf-preview-region-with-faces))
-(defadvice ps-print-buffer
-  (around mac-preview-print())
-  (require 'pdf-preview)
-  (pdf-preview-buffer))
-(defadvice ps-print-region
-  (around mac-preview-print())
-  (require 'pdf-preview)
-  (pdf-preview-region))
-(defadvice print-buffer (around mac-preview-print2(&optional mono))
-  (interactive "P")
-  (require 'pdf-preview)
-  (if mono (pdf-preview-buffer)(pdf-preview-buffer-with-faces)))
-(defadvice print-region (around mac-preview-print2(&optional mono))
-  (interactive "P")
-  (require 'pdf-preview)
-  (if mono (pdf-preview-region)(pdf-preview-region-with-faces)))
-
-(define-minor-mode mac-preview-mode
-  "Toggle Mac Preview mode."
-  :global t
-  (if mac-preview-mode
-      (ad-enable-regexp "mac-preview-print*")
-    (ad-disable-regexp "mac-preview-print*")
-    ))
-
-
-;; ;;; Commentary:
-
-;; ;; To use this package, add these lines to your .emacs file:
-;; ;;
-;; ;;     (require 'mac-preview-mode)
-;; ;;     (mac-preview-mode 1)
-;; ;;
-;; ;; This minor mode requires the gs program.
-;; ;;
-;; ;;     (setq mac-preview-gs-program "/sw/bin/gs")
-;; ;;
-
-
-;; ;;; Code:
-
-;; (defgroup mac-preview-mode nil
-;;   "A print-preview extension to Carbon Emacsen."
-;;   :group 'mac
-;;   :version "22.1")
-
-;; (defcustom mac-preview-gs-command "gs"
-;;   "The command by which to invoke the gs program."
-;;   :type 'string
-;;   :group 'mac-preview-mode)
-
-;; (defun mac-preview-lpr-switches ()
-;;   "Document forthcoming..."
-;;   (interactive)
-;;   (let ((tmpdir-function
-;;          (cond
-;;           ((featurep 'carbon-emacs-package)
-;;            'carbon-emacs-package-tmpdir)
-;; ;;         ((featurep 'some-compatible-emacsen)
-;; ;;          'some-compatible-emacsen-tmpdir)
-;;           (t 'mac-preview-prepare-tmpdir)
-;;           )))
-;;     (list "-q" "-dNOPAUSE" "-dBATCH" "-sDEVICE=pdfwrite"
-;;           "-dCompatibilityLevel=1.3" "-dAutoFilterGrayImages=false"
-;;           "-dAutoFilterColorImages=false"
-;;           "-dGrayImageFilter=/FlateEncode"
-;;           "-dColorImageFilter=/FlateEncode"
-;;           "-dUseFlateCompression=true"
-;;           "-sPAPERSIZE=a4"
-;;           (concat "-sOutputFile=\|cat\> "
-;;                   (funcall tmpdir-function) "preview.pdf"
-;;                   "&& /usr/bin/open -a Preview.app "
-;;                   (funcall tmpdir-function) "preview.pdf")
-;;           "-c .setpdfwrite" "-f" "-" "-c quit")
-;;     ))
-
-;; (defun mac-preview-prepare-tmpdir () (interactive) "/tmp/")
-
-
-;; ;; advices
-
-;; (defadvice ps-print-buffer-with-faces (around mac-preview-print())
-;;   (let((ps-multibyte-buffer 'non-latin-printer)
-;;        (ps-lpr-command mac-preview-gs-command)
-;;        (ps-lpr-switches (mac-preview-lpr-switches)))
-;;     ad-do-it
-;;     ))
-;; (defadvice ps-print-region-with-faces (around mac-preview-print())
-;;   (let((ps-multibyte-buffer 'non-latin-printer)
-;;        (ps-lpr-command mac-preview-gs-command)
-;;        (ps-lpr-switches (mac-preview-lpr-switches)))
-;;     ad-do-it
-;;     ))
-;; (defadvice ps-print-buffer (around mac-preview-print())
-;;   (let((ps-multibyte-buffer 'non-latin-printer)
-;;        (ps-lpr-command mac-preview-gs-command)
-;;        (ps-lpr-switches (mac-preview-lpr-switches)))
-;;     ad-do-it
-;;     ))
-;; (defadvice ps-print-region (around mac-preview-print())
-;;   (let((ps-multibyte-buffer 'non-latin-printer)
-;;        (ps-lpr-command mac-preview-gs-command)
-;;        (ps-lpr-switches (mac-preview-lpr-switches)))
-;;     ad-do-it
-;;     ))
-;; (defadvice print-buffer (around mac-preview-print2(&optional mono))
-;;   (interactive "P")
-;;   (if mono (ps-print-buffer)(ps-print-buffer-with-faces)))
-;; (defadvice print-region (around mac-preview-print2(&optional mono))
-;;   (interactive "P")
-;;   (if mono (ps-print-region)(ps-print-region-with-faces)))
-
-
-;; (define-minor-mode mac-preview-mode
-;;   "Toggle Mac Preview mode, a minor mode that provides
-;; a print-preview extension to Carbon Emacsen.
-;; When `mac-preview-gs-command' is well-configured,
-;; a preview image of the buffer or the region is shown by Preview.app."
-;;   :global t
-;; ;  :lighter " P" ; for debugging purpose
-;;   :group 'mac-preview-mode
-;;   (if mac-preview-mode
-;;       (ad-enable-regexp "mac-preview-print*")
-;;     (ad-disable-regexp "mac-preview-print*")
-;;     )
-;;   )
-
-
-(provide 'mac-preview-mode)
-
-;; mac-preview-mode.el ends here.
Index: CarbonEmacsPackage/GPL/mac/mac-print.el
diff -u /dev/null CarbonEmacsPackage/GPL/mac/mac-print.el:1.1
--- /dev/null	Thu Jan 12 20:37:29 2006
+++ CarbonEmacsPackage/GPL/mac/mac-print.el	Thu Jan 12 20:37:29 2006
@@ -0,0 +1,101 @@
+;;; mac-print.el --- Cocoa print dialog for Carbon Emacsen
+
+;; Copyright (C) 2005-2006  Seiji Zenitani <zenit****@mac*****>
+
+;; based on htmlize-view by Lennart Borgman
+;; http://ourcomments.org/Emacs/DL/elisp/htmlize-view.el
+
+;;; Commentary:
+
+;; In order to use this package,
+;; htmlize.el <http://fly.srk.fer.hr/~hniksic/emacs/htmlize.el>
+;; and coral <http://hmdt-web.net/coral/> are required.
+;;
+;;
+;; M-x mac-print-buffer
+;; or
+;; (mac-preview-mode 1)
+;;
+
+;;; Code:
+
+(require 'htmlize)
+
+(defvar mac-print-kill-view-buffers t
+  "If non-nil, delete temporary html buffers after sending to coral.")
+
+(defvar mac-print-coral-program "coral" "The coral program.")
+
+
+(defun mac-print-buffer(&optional region-only)
+  "Convert buffer to html, preserving colors and decoration and
+send it to the coral application.
+If REGION-ONLY is non-nil then only the region is printed."
+  (interactive)
+  (shell-command
+   (concat mac-print-coral-program " -d "
+           (mac-print-htmlize-buffer-to-tempfile region-only)
+           )))
+
+(defun mac-print-htmlize-buffer-to-tempfile(region-only)
+  "Convert buffer to html, preserving colors and decoration and
+send it to the coral application.
+If REGION-ONLY is non-nil then only the region is sent to the coral.
+Return a cons with temporary file name followed by temporary buffer."
+  (save-excursion
+    (let (;; Just use Fundamental mode for the temp buffer
+          magic-mode-alist
+          auto-mode-alist
+          (html-temp-buffer
+           (if (not region-only)
+               (htmlize-buffer (current-buffer))
+             (let ((start (mark)) (end (point)))
+               (or (<= start end)
+                   (setq start (prog1 end (setq end start))))
+               (htmlize-region start end))))
+          (file (mac-print-gettemp-file-name)))
+      (set-buffer html-temp-buffer)
+      (write-file file nil)
+      (if mac-print-kill-view-buffers (kill-buffer html-temp-buffer))
+      file)))
+
+(defun mac-print-gettemp-file-name()
+  "Get a temp file name for printing"
+  (make-temp-file
+   (expand-file-name
+    "preview"
+    (if (featurep 'carbon-emacs-package) (carbon-emacs-package-tmpdir) "/tmp")
+    ) nil ".html"))
+
+
+(defadvice ps-print-buffer-with-faces
+  (around mac-print-ad())
+  (mac-print-buffer))
+(defadvice ps-print-region-with-faces
+  (around mac-print-ad())
+  (mac-print-buffer t))
+(defadvice ps-print-buffer
+  (around mac-print-ad())
+  (mac-print-buffer))
+(defadvice ps-print-region
+  (around mac-print-ad())
+  (mac-print-buffer t))
+(defadvice print-buffer (around mac-print-ad2(&optional mono))
+  (interactive "P")
+  (mac-print-buffer))
+(defadvice print-region (around mac-print-ad2(&optional mono))
+  (interactive "P")
+  (mac-print-buffer t))
+
+(define-minor-mode mac-preview-mode
+  "Toggle Mac Preview mode."
+  :global t
+  (if mac-preview-mode
+      (ad-enable-regexp "mac-print-ad*")
+    (ad-disable-regexp "mac-print-ad*")
+    ))
+
+
+(provide 'mac-preview-mode)
+
+;; mac-print.el ends here.


macemacsjp-cvs メーリングリストの案内
Back to archive index