;; -*- Emacs-Lisp -*- ;;; lessfile.el --- Use the lessfile inputfilter for view-file ;; Copyright (C) 2002 Claus Brunzema ;; Version: 0.9.3 ;; $Id: lessfile.el,v 1.5 2002/06/28 14:17:54 chb Exp $ ;; 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. ;; ;; It 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, 675 Mass Ave, Cambridge, MA 02139, USA. ;; ----------------------------------------------------------------------- ;;; Commentary: ;; Motivation: ;; ;; I often use locate to find files, especially lisp source ;; files. Unfortunately on my debian system the xemacs sources are gzipped by ;; default. I could always use less on the commandline to view these ;; files, but I wanted to do all this within my xemacs. So here it is... ;; ;; After I released lessfile into the public, ivank told me about ;; auto-compression-mode.... but lessfile.el is still useful to view ;; stuff xemacs doesn't handle automatically (e.g. with a ;; sophisticated lessfile script you could view html pages without ;; using the (rather slow) w3). ;; Prerequisites: ;; ;; I made query-replace-by-example with the following xemacs: ;; XEmacs 21.4 (patch 6) "Common Lisp" [Lucid] (i386-debian-linux) of Sat Apr 6 2002 on eeyore" ;; Please let me know if other versions work. ;; Installation: ;; ;; put this file in your load-path and the following in your init ;; file (~/.emacs or ~/.xemacs/init.el): ;; ;; (require 'lessfile) ;; ;; Some users (most notably SuSE users) may want to add ;; ;; (setq lessfile-lessopen "lessopen.sh %s") ;; (setq lessfile-lessclose "lessclose.sh %s %s") ;; ;; The default (see below) works on a debian GNU/Linux installation. ;; Usage: ;; ;; This module uses advice to change the behaviour of view-file. Just ;; use view-file like before, it now works with all the filetypes your ;; lessfile can handle. ;; History: ;; 2002-06-28 Claus Brunzema ;; * Comment about auto-compression-mode... Version 0.9.3 ;; ;; 2002-06-20 Claus Brunzema ;; * More Docs. Version 0.9.2 ;; ;; 2002-06-15 Claus Brunzema ;; * Initial version. ;; ToDo: ;; ;; - Get the values for lessfile-lessopen and lessfile-lessclose by ;; parsing the output of lessfile. ;;; Code: ;; -- Customisation ------------------------------------------------------- (defvar lessfile-lessopen "/usr/bin/lessfile %s") ; see 'man lessfile' (defvar lessfile-lessclose "/usr/bin/lessfile %s %s") ;; ------------------------------------------------------------------------ (require 'advice) (defadvice view-file (around lessfile-inputfilter activate) (let* ((internal-filename (ad-get-arg 0)) (internal-tmpfilename (concat (butlast (string-to-list (shell-command-to-string (format lessfile-lessopen (shell-quote-argument internal-filename)))))))) (unless (zerop (length internal-tmpfilename)) (ad-set-arg 0 internal-tmpfilename)) ad-do-it (unless (zerop (length internal-tmpfilename)) (rename-buffer (concat "less:" (generate-new-buffer-name (file-name-nondirectory internal-filename)))) (shell-command (format lessfile-lessclose (shell-quote-argument internal-filename) (shell-quote-argument internal-tmpfilename)))))) (provide 'lessfile) ;;; lessfile.el ends here