2009-02-20 60 views
7

我在Windows XP上運行Emacs 23.0.60.1,從here下載,並將網絡打印機配置爲默認打印機。如何從Win32上的Emacs打印?

如何設置Emacs輕鬆打印緩衝區內容?

修補後的Emacs for Win32的documentation提到「快速和簡單」的打印,但沒有出現「快速打印」菜單條目,並且常規條目(「打印緩衝區」,「Postscript打印緩衝區」似乎什麼都不做。

編輯:
我與Emacs 22.3的官方Windows版本有相同的問題。因此,任何版本的設置/故障排除說明將不勝感激。

EDIT2:
我下面由喬Casadonte提出的PrintFile解決方案,它很好地工作去了。儘管如此,我仍然對任何想法都感興趣,爲什麼「正確」的方式不起作用。

(順便說一句,這是一個合適的SO問題,暫時只輕微編程有關?)

+0

我從Win32的Emacs的22升級到Win32的Emacs的23,並發現了同樣的問題,打印文件:打印緩衝區菜單不再工作的記錄。 當然,我完全沒有跟進。 – 2009-02-20 18:27:54

+1

回覆:適當的SO問題 - 是的,我相信這是適當的。 Emacs和VIM問題一直在這裏提出並回答。 – 2009-02-23 20:48:25

回答

4

它不是「正確」的方式,但我已經做了多年,這種方式奇妙的作品。我使用的是免費軟件打印程序PrintFile(也可以單獨使用)。然後,我有這個在我的.emacs:

(defun joc-make-fname-from-buffer-name (buffer-name-in) 
    "Returns a valid filename from a given buffer name" 
    (interactive "b") 
    (save-match-data 
    (let* ((start (string-match "[^ \*]" buffer-name-in)) 
      (end (string-match "[ \*]*$" buffer-name-in (match-end 0))) 
      (rc (substring buffer-name-in start end))) 
     ;; remove some special characters 
     (while (string-match "[:]+" rc) 
     (setq rc (replace-match "_" t t rc))) 
     rc))) 

(when is-win32 
    (defun joc-print-buffer-or-region (prefix) 
     "Prints buffer or region via PrintFile32. If a prefix arg is set (via C-u) then 
     the current region is printed, otherwise the current buffer is printed." 

     (interactive "P") 

     ;; ----- set the print directory, fname and args ----- 
     (let* ((print-dir (expand-file-name "~/emacs/print")) 
      (print-fname (joc-make-fname-from-buffer-name (buffer-name))) 
      (print-fullpath (concat print-dir "/" print-fname)) 
      (print-args "/delete") 
      ;; ----- set rstart and rend to the current region ----- 
      (rstart (point-min)) (rend (point-max))) 

     ;; ----- if prefix given, set them to region ----- 
     (if (and prefix) 
      (if (and (point) (mark) (/= (point) (mark))) 
       (progn (setq rstart (min (point) (mark))) 
         (setq rend (max (point) (mark)))) 
       (error "No region defined"))) 

     ;; ----- make the directory ----- 
     (if (not (file-directory-p print-dir)) 
      (make-directory print-dir)) 

     ;; ----- write buffer/region to a temp file, print it, delete directory ----- 
     (write-region rstart rend print-fullpath) 
     (call-process "prfile32" nil t nil print-args print-fullpath) 
     (delete-directory print-dir)))) 

我已經很多年沒有看它,因爲它只是工作,所以我敢肯定,這可以改善。

+0

在我的XP上很好用;感謝您指出一個優秀的應用程序!然而 - 我如何(a)添加對非拉丁字符(或UTF-8)的支持和(b)_words_而不是_characters_是否有換行符?但這些可能是PrintFile而不是Emacs的問題。謝謝! – marttt 2012-01-24 12:58:09

+0

恐怕我不知道 - 對不起。 – 2012-01-25 01:42:07

1

以下行添加到您的Emacs init文件

(setq printer-name "//domain/printer-name") 
5

我將描述所有的Windows 7與普通USB打印機。根據需要調整流程以適應您的版本。網絡通常可以以相同的方式訪問。只需使用//NetworkComputerName/SharedPrinterName而不是//我的電腦/ MyPrinter並跳過步驟1 - 6 ..

  1. 轉到開始 - >控制面板 - >硬件和聲音 - >設備和打印機
  2. 請右鍵單擊打印機選擇「打印機屬性」
  3. 進入「共享」,勾選「共享這臺打印機」和「渲染客戶端計算機上的打印作業」
  4. 輸入共享名:MyPrinter或東西,你可以記住並沒有空格。
  5. 單擊確定保存更改。
  6. 轉到開始 - >計算機檢查在左下角你的計算機的名稱(例如MyComputer
  7. 在Emacs的評估(setq printer-name "//MyComputer/MyPrinter")或把它放在做你.emacs.el文件
  8. 。你可以用M-x print-buffer