[Top][All Lists]

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

less.el 0.5

From: William Xu
Subject: less.el 0.5
Date: Sat, 23 Apr 2011 15:31:36 +0000 (UTC)
User-agent: Loom/3.14 (

Changes since 0.4:

| - Introduce `global-less-minor-mode'.
| - Handle movement in image-mode specically.
| - Some bug fixes.


;;; less.el --- less style view mode

;; Copyright (C) 2005, 2007, 2009, 2010, 2011 William Xu

;; Author: William Xu <address@hidden>
;; Version: 0.5

;; 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 3, 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
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
;; 02110-1301 USA

;;; Commentary:

;; View file like a simple `less'. Provide limited less keys, mainly j,
;; k, f, b, g, G, etc.

;; Put this file into your load-path and the following into your ~/.emacs:
;;   (require 'less)
;; Then use `M-x less-minor-mode' to toggle `less-minor-mode'.

;; There's also a `view-less.el' in XEmacs. But it does too much for me,
;; i just wanna less keys like j, k, f, b, g, G, not to mess with other
;; keys in major mode.

;;; Code:

(defcustom auto-less-exclude-regexp
   '("*Org Agenda*" "*code-conversion-work*" " *Compiler Input*"
     " *Echo Area"

     "*nntpd*" " *gnus work*" " *gnus article copy*"
     " *extract address components*" " *canonical address*"
     "*followup to" "*mail"))
  "Do not turn on `auto-less-minor-mode' for matched files and buffers."
  :type 'string
  :group 'convenience)

(defcustom auto-less-exclude-modes
  '(shell-mode term-mode comint-mode twittering-edit-mode calendar-mode
               log-edit-mode gnus-summary-mode gnus-group-mode message-mode
               dired-mode ibuffer-mode apropos-mode completion-list-mode
  "Do not turn on `auto-less-minor-mode' for these major modes."
  :type 'list
  :group 'convenience)

(define-global-minor-mode global-less-minor-mode
  less-minor-mode auto-less-minor-mode
  :group 'convenience)

(define-minor-mode less-minor-mode
  "Toggle less-minor-mode.

With less-minor-mode enabled, you could use `less' like keys to view files.
  nil " Less"
  '(("j" . less-scroll-up-line)
    ("k" . less-scroll-down-line)
    ("f" . scroll-up)
    ("b" . scroll-down)
    ("g" . less-beginning-of-buffer)
    ("G" . less-end-of-buffer)
    (" " . scroll-up)
    ("" . scroll-down)
    ("e" . less-quit))
  (set (make-local-variable 'buffer-read-only) less-minor-mode))

(defun less-scroll-up-line ()
  "Scroll up one line."
  (if (eq major-mode 'image-mode)
      (image-next-line 1)
    (scroll-up 1)))

(defun less-scroll-down-line ()
  "Scroll down one line."
  (if (eq major-mode 'image-mode)
      (image-previous-line 1)
    (scroll-down 1)))

(defun less-beginning-of-buffer ()
  (if (eq major-mode 'image-mode)
    (goto-char (point-min))))

(defun less-end-of-buffer ()
  (if (eq major-mode 'image-mode)
    (goto-char (point-max))
    ;; Similar to `end-of-buffer'.
    (recenter -3)))

(defun less-quit ()
  "Quit `less-minor-mode'."
  (less-minor-mode -1))

(defun auto-less-minor-mode ()
  "Turn on `less-minor-mode' for files not matching `auto-less-exclude-regexp'.

This is a useful hook to add to `find-file-hook'."
  (unless (or (and (not (string= auto-less-exclude-regexp ""))
                   (string-match auto-less-exclude-regexp
                                 (or buffer-file-name (buffer-name))))
              (memq major-mode auto-less-exclude-modes)
              (not (if buffer-file-name (file-exists-p buffer-file-name) t)))
    (less-minor-mode 1)))

(defun less-minor-mode-on ()
  "Turn on `less-minor-mode'."
  (less-minor-mode 1))

(defun less-minor-mode-off ()
  "Turn off `less-minor-mode'."
  (less-minor-mode -1))

(provide 'less)

;;; less.el ends here

reply via email to

[Prev in Thread] Current Thread [Next in Thread]