[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]


仕事で,Microsoft Excel のファイルを大量に閲覧しなければいけない状況に
追い込まれたものですから,ほとんど auto-image-file-mode() 関連コードの
パクリなんですが.excel-file-mode なんてものを作ってみました.末尾のコー
ドを評価して,C-x C-f foo.xls RET としてみてください.

最初は,octet-file-mode にしようと思っていたのですが,
octet-suffix-type-alist に登録されている拡張子を全て handler で受け付
けてしまうと,auto-compression-mode とも衝突するし,*.html なファイル
を開けなくなってしまうし,と副作用が巨大すぎたので,Excel ファイルだけ

土屋 雅稔 ( TSUCHIYA Masatoshi )
(defun excel-insert-file (file &rest visit beg end replace)
  (prog1 (let ((coding-system-for-read 'binary))
	   (excel-file-call-underlying #'insert-file-contents
				       file visit beg end replace))
    (require 'w3m)
    (require 'octet)
    (let ((w3m-fill-column -1))

(defun excel-file-handler (operation &rest args)
  "Filename handler for inserting Excel files.
OPERATION is the operation to perform, on ARGS.
See `file-name-handler-alist' for details."
  (if (and (eq operation 'insert-file-contents)
      (apply #'excel-insert-file args)
    ;; We don't handle OPERATION, use another handler or the default
    (apply #'excel-file-call-underlying operation operation args)))

(defun excel-file-call-underlying (function operation &rest args)
  "Call FUNCTION with `excel-file-handler' and OPERATION inhibited.
Optional argument ARGS are the arguments to call FUNCTION with."
  (let ((inhibit-file-name-handlers
	 (cons 'excel-file-handler
	       (and (eq inhibit-file-name-operation operation)
	(inhibit-file-name-operation operation))
    (apply function args)))

(define-minor-mode excel-file-mode
  "Toggle visiting of Excel files.
With prefix argument ARG, turn on if positive, otherwise off.
Returns non-nil if the new state is enabled."
  :global t
  :group 'octet
  ;; Remove existing handler
  (let ((existing-entry
	 (rassq 'excel-file-handler file-name-handler-alist)))
    (when existing-entry
      (setq file-name-handler-alist
	    (delq existing-entry file-name-handler-alist))))
  ;; Add new handler, if enabled
  (when excel-file-mode
    (push (cons "\\.\\(xls\\|XLS\\)\\'" 'excel-file-handler)

(excel-file-mode 1)