From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Lennart Borgman (gmail)" Newsgroups: gmane.emacs.devel Subject: File name handler for http web URLs Date: Sun, 01 Jun 2008 21:13:29 +0200 Message-ID: <4842F4D9.5070005@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090103010407090906060406" X-Trace: ger.gmane.org 1212347635 25100 80.91.229.12 (1 Jun 2008 19:13:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Jun 2008 19:13:55 +0000 (UTC) To: Emacs Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jun 01 21:14:35 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K2t0h-0001Aw-5f for ged-emacs-devel@m.gmane.org; Sun, 01 Jun 2008 21:14:31 +0200 Original-Received: from localhost ([127.0.0.1]:53590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K2szv-0003wS-2B for ged-emacs-devel@m.gmane.org; Sun, 01 Jun 2008 15:13:43 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K2szq-0003w1-Vn for emacs-devel@gnu.org; Sun, 01 Jun 2008 15:13:39 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K2szo-0003vp-C5 for emacs-devel@gnu.org; Sun, 01 Jun 2008 15:13:37 -0400 Original-Received: from [199.232.76.173] (port=42157 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K2szo-0003vm-93 for emacs-devel@gnu.org; Sun, 01 Jun 2008 15:13:36 -0400 Original-Received: from ch-smtp01.sth.basefarm.net ([80.76.149.212]:35265) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K2szn-0006nP-IE for emacs-devel@gnu.org; Sun, 01 Jun 2008 15:13:36 -0400 Original-Received: from c83-254-145-59.bredband.comhem.se ([83.254.145.59]:63813 helo=[127.0.0.1]) by ch-smtp01.sth.basefarm.net with esmtp (Exim 4.68) (envelope-from ) id 1K2szl-0006OE-5j for emacs-devel@gnu.org; Sun, 01 Jun 2008 21:13:34 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666 X-Antivirus: avast! (VPS 080531-1, 2008-05-31), Outbound message X-Antivirus-Status: Clean X-Originating-IP: 83.254.145.59 X-Scan-Result: No virus found in message 1K2szl-0006OE-5j. X-Scan-Signature: ch-smtp01.sth.basefarm.net 1K2szl-0006OE-5j 1d175395ee724a399d5825d8fb4bea82 X-detected-kernel: by monty-python.gnu.org: Linux 2.6? (barebone, rare!) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:98194 Archived-At: This is a multi-part message in MIME format. --------------090103010407090906060406 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I am getting so used to opening files with recentf-mode so I decided to see if it could be conveniently used for any files. It looks quite easy to do so, at least on w32. I have attached an example. However one thing that surprised me is that there is no file name handler for web URLs. (I am using Firefox.) Am I missing something? Is there perhaps such a file name handler? Or is there any obstacle against having one for opening web URL in external browsers? --------------090103010407090906060406 Content-Type: text/plain; name="sex-mode.el" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="sex-mode.el" ;;; sex-mode.el --- Shell EXecute mode / Send to EXterna program ;; ;; Author: Lennart Borgman (lennart O borgman A gmail O com) ;; Created: 2008-06-01T18:41:50+0200 Sun ;; Version: 0.1 ;; Last-Updated: 2008-06-01T20:21:06+0200 Sun ;; URL: ;; Keywords: ;; Compatibility: ;; ;; Features that might be required by this library: ;; ;; None ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Commentary: ;; ;; Open files in other programs, but add to recentf-mode etc. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Change log: ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; 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. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth ;; Floor, Boston, MA 02110-1301, USA. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Code: (defcustom sex-open-alist '( "\\.pdf\\'" "\\.doc\\'" ) "Alist of file name patterns to handle. Adding to this list will cause those patterns to be added to to `auto-mode-alist' and `file-name-handler-alist' when `sex-mode' is on. This means that opening those files will create a dummy buffer in Emacs in `sex-file-mode' and an external program is called to handle the file." :type '(repeat regexp) :group 'sex) (defcustom sex-keep-dummy-buffer t "Keep dummy buffer after opening file. See `sex-open-alist'." :type 'boolean :group 'sex) (defvar sex-file-name nil) (make-variable-buffer-local 'sex-file-name) (defun sex-file-handler (operation &rest args) "Handler for `insert-file-contents'." (cond ((eq operation 'insert-file-contents) (unless (= 0 (buffer-size)) (error "Buffer must be empty")) (let* ((name (nth 0 args)) (exists (nth 1 args)) (result (sex-handle-by-external name)) (success (nth 0 result)) (msg (nth 1 result))) (setq buffer-file-name name) (if success (progn (insert "This dummy buffer is used just for opening a file.\n" "The file itself was sent to system for opening.\n\n" "To open the file again click here:\n\n ") (save-excursion (insert-text-button buffer-file-name 'action (lambda (button) (sex-handle-by-external buffer-file-name))))) (insert (propertize "Error\n\n" 'face 'font-lock-warning-face) "Tried to send file\n\n\t" buffer-file-name "\n\nto system but it failed with message:\n" msg)))) ;; Handle any operation we don't know about. (t (let ((inhibit-file-name-handlers (cons 'sex-file-handler (and (eq inhibit-file-name-operation operation) inhibit-file-name-handlers))) (inhibit-file-name-operation operation)) (apply operation args))))) (defun sex-handle-by-external (&optional file) "Give file FILE to external program. Return a list: (SUCCESS MESSAGE) where SUCCESS is non-nil if operation succeeded and MESSAGE is an informational message." (unless file (setq file buffer-file-name)) (cond ((fboundp 'w32-shell-execute) (condition-case err (progn (w32-shell-execute "open" (convert-standard-filename file)) (list t "Sent file to system")) (error (list nil (error-message-string err))))) (t (error "Don't know how to handle the file on your OS yet.")))) (define-derived-mode sex-file-mode nil "External" "Mode for files opened in external programs." (set-keymap-parent (current-local-map) button-buffer-map) (set-buffer-modified-p nil) (setq buffer-read-only t)) (define-minor-mode sex-mode "Open certain files in external programs using shell execute." nil :group 'sex :global t (if sex-mode (progn (dolist (patt sex-open-alist) (add-to-list 'auto-mode-alist (cons patt 'sex-file-mode)) (add-to-list 'file-name-handler-alist (cons patt 'sex-file-handler) t))) ;; Remove from the lists: (dolist (patt sex-open-alist) (setq auto-mode-alist (delete (cons patt 'sex-file-mode) auto-mode-alist)) (setq file-name-handler-alist (delete (cons patt 'sex-file-handler) file-name-handler-alist))))) (provide 'sex-mode) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; sex-mode.el ends here --------------090103010407090906060406--