home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.emacs.sources
- Path: sparky!uunet!stanford.edu!CSD-NewsHost.Stanford.EDU!times!wmesard
- From: wmesard@Pescadero.Stanford.EDU (Wayne Mesard)
- Subject: wsm-xm-expand: an x-sb-mouse customization
- Message-ID: <WMESARD.92Jul24161825@Pescadero.Stanford.EDU>
- Sender: news@CSD-NewsHost.Stanford.EDU
- Organization: /pescadero/u3/wmesard/.organization
- Date: 24 Jul 92 16:18:25
- Lines: 277
-
- Enclosed is a file which implements a bunch of mode-specific extensions
- to Sullivan Beck's excellent mouse handler that he posted here a couple
- of weeks ago.
-
- Basically, it "expands" whatever the mouse is pointing at when you click
- the left button while holding down the Control key. The exact meaning
- of "expand" depends on the mode of the buffer. See the DESCRIPTION
- section at the top of the file for details.
-
- Comments, suggestions, questions welcome.
-
- Wayne();
- WMesard@cs.stanford.edu
-
- ---snip---crickle---pip---
- ;;; wsm-xm-expand.el: WSM's Control-left-click customizations for x-sb-mouse
- ;;; Copyright (C) 1992 Wayne Mesard
- ;;;
- ;;; 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 1, 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.
- ;;;
- ;;; The GNU General Public License is available by anonymouse ftp from
- ;;; prep.ai.mit.edu in pub/gnu/COPYING. Alternately, you can write to
- ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
- ;;; USA.
- ;;--------------------------------------------------------------------
-
- ;;; DESCRIPTION
- ;; This file binds the mouse gesture Control-Left-click to various
- ;; functions which "expand" the thing being pointed to according to
- ;; the buffer's mode.
- ;;
- ;; Mode Action
- ;; ---- -----------
- ;; Info follows the indicated cross-reference, menu item, or the
- ;; "Next", "Previous" or "Up" field from the top line of the node.
- ;; Compile goes to the indicated line of source code.
- ;; C and Emacs-Lisp
- ;; does a find-tag on the thing being pointed to.
- ;; GNUS selects the indicated newsgroup or article.
- ;; Dired selects the indicated file.
- ;; RMail-Summary
- ;; selects the indicated message.
- ;; Buffer selects the indicated buffer in another window.
-
- ;;; NOTES
- ;; The compilation stuff uses several private constructs from
- ;; compile.el. It works in Emacs 18.58. But it could easily break
- ;; in a later release. Contact me if you need an update.
- ;;
- ;; I know I'm missing "expanders" for mh-letter-mode and mh-folder-mode.
- ;; I plan to start using MH-E sometime soon, so I'll add these then.
- ;; Send me email if you want the mod's when they're ready.
- ;;
- ;; Wayne Mesard: wmesard@cs.stanford.edu
-
- ;;; HISTORY
- ;; 1.0 wmesard - Jul 16, 1992: Created
-
- ;;;
- ;;; DEPENDENCIES
- ;;;
-
- ;; x-sb-mouse version 1.6
- (require 'x-sb-mouse)
-
- ;;;
- ;;; BINDINGS
- ;;;
-
- (x-mouse-define-key "x-mouse-c1-window-click" t
- 'default 'x-mouse-set-point
- 'gnus-Group-mode 'wsm-x-mouse-Group-read
- 'gnus-Subject-mode 'wsm-x-mouse-Subject-select
- 'dired-mode 'wsm-x-mouse-dired-find-file
- 'rmail-summary-mode 'wsm-x-mouse-rmail-summary-jump
- 'Buffer-menu-mode 'wsm-x-mouse-buffer-menu
- 'Info-mode 'wsm-x-mouse-Info-follow-link
- ;; There is no compilation mode, so this function will have to check
- ;; to make sure that it really is a *compilation* buffer.
- 'fundamental-mode 'wsm-x-mouse-maybe-compilation-goto
- 'c-mode 'wsm-x-mouse-find-tag
- 'emacs-lisp-mode 'wsm-x-mouse-find-tag
- )
-
-
- ;; We have to restore Left-click to set-point anyway, since we just
- ;; stole Control-left-click, which is the only way to do set-point in
- ;; GNUS using vanilla x-sb-mouse.
-
- (x-mouse-undefine-key "x-mouse-1-window-click"
- 'gnus-Group-mode
- 'gnus-Subject-mode)
-
- ;;;
- ;;; GNUS
- ;;;
-
- (defun wsm-x-mouse-Group-read ()
- "For GNUS: Move point to the mouse location and read the indicated newsgroup"
- (x-mouse-set-point)
- (gnus-Group-read-group nil))
-
- (defun wsm-x-mouse-Subject-select ()
- "For GNUS: Move point to the mouse location and read the indicated article"
- (x-mouse-set-point)
- (gnus-Subject-select-article))
-
- ;;;
- ;;; DIRED
- ;;;
-
- (defun wsm-x-mouse-dired-find-file ()
- "For Dired: Move point to the mouse location and find the indicated file."
- (x-mouse-set-point)
- (dired-find-file-other-window))
-
- ;;;
- ;;; RMAIL SUMMARY
- ;;;
-
- (defun wsm-x-mouse-rmail-summary-jump ()
- (x-mouse-set-point)
- (rmail-summary-goto-msg))
-
- ;;;
- ;;; BUFFER MENU
- ;;;
-
- (defun wsm-x-mouse-buffer-menu ()
- "For Buffer Menu: Move to mouse location and select the indicated buffer."
- (x-mouse-set-point)
- (Buffer-menu-other-window))
-
- ;;;
- ;;; COMPILATION
- ;;;
-
- (defun wsm-x-mouse-maybe-compilation-goto ()
- "Jump to the source code line indicated by a message in *compilation* buffer.
- This is essentially a random-access version of the sequential \\[next-error].
- \\[next-error] clears markers once it visits an error, so if you use both of
- these at the same time, this function may have to reparse the compilation
- buffer to reacquire the markers.
-
- If it isn't a compilation buffer, simply moves point to the mouse location."
- (if (equal (buffer-name (window-buffer x-mouse-win-u))
- "*compilation*")
- (wsm-compilation-jump x-mouse-point-u)
- (x-mouse-set-point)))
-
- ;; Private variable used to detect clicking in the same place twice in a row
- ;; when there's no marker there. This forces a reparse.
-
- (defvar wsm-compilation-last-msgloc nil)
-
- (defun wsm-compilation-jump (msgloc)
- (if (or (eq compilation-error-list t)
- (eq wsm-compilation-last-msgloc msgloc))
- (progn (compilation-forget-errors)
- (setq compilation-parsing-end 1)))
- (if (or (null compilation-error-list)
- (> msgloc compilation-parsing-end))
- (save-excursion
- (set-buffer "*compilation*")
- (set-buffer-modified-p nil)
- (compilation-parse-errors)))
- (let ((lst compilation-error-list)
- curr)
- (while (and lst (<= (car (car lst)) msgloc))
- (setq curr (car lst))
- (setq lst (cdr lst))
- )
- (if (null curr)
- (progn
- (setq wsm-compilation-last-msgloc msgloc)
- (error
- "Marker is null. Click again to force a reparse of the buffer.")
- )
- (setq wsm-compilation-last-msgloc nil))
- (if (<= (car curr) msgloc)
- (progn
- (if (string= "*compilation*" (buffer-name (current-buffer)))
- (other-window 1))
- (switch-to-buffer (marker-buffer (car (cdr curr))))
- (goto-char (car (cdr curr)))
- )
- (error "Couldn't find mark"))
- ))
-
- ;;;
- ;;; INFO
- ;;;
-
- (defun wsm-x-mouse-Info-follow-link ()
- "For Info mode: Go to the indicated cross-reference, menu item or link
- (where a link is the Prev, Next or Up fields in the first line of a node)."
- (select-window x-mouse-win-u)
- (wsm-Info-goto-link-at x-mouse-point-u))
-
- (defun wsm-Info-goto-link-at (loc)
- (let (func arg)
- (save-excursion
- (goto-char loc)
- ;; Links in first line of node
- (if (save-excursion (beginning-of-line)
- (bobp))
- (let (end)
- (if (not
- (progn ; Point in link type (Next, Up, Prev)
- (skip-chars-forward "A-Za-z")
- (= ?\: (char-after (point)))
- ))
- (progn ; Point in name ("(dir)", "top", etc)
- (goto-char loc)
- (search-backward ":" nil t)
- ))
- (setq end (point))
- (forward-word -1)
- ;; Okay, now we know point is at the start of the link type
- (setq func
- (cdr (assoc (buffer-substring (point) end)
- '(("Up" . Info-up) ("Next" . Info-next)
- ("Prev" . Info-prev)("Previous" . Info-prev)
- ))))
- )
- ;; Menus and References
- (if (or (= ?\* (char-after (point))) (search-backward "*" nil t))
- (let ((starloc (point))
- (link-func
- (if (re-search-forward
- "^\\* \\([^:]*\\):[^.,:\n]*" nil t)
- (function Info-menu)
- (if (re-search-forward
- "\\*note \\([^:]*\\):[^.,:]*" nil t)
- (function Info-follow-reference))))
- )
- (if (and (= starloc (match-beginning 0))
- (<= starloc loc)
- (< loc (point)))
- ;; loc really was w/in the link. Set func and arg.
- (setq func link-func
- arg (buffer-substring (match-beginning 1)
- (match-end 1)))
- )
- ))
- ))
- (if func
- (if arg (funcall func arg)
- (funcall func))
- (error "Point at a link or don't point at all"))
- ))
-
- ;;;
- ;;; C / ELisp
- ;;;
-
- (defun wsm-x-mouse-find-tag ()
- "For C: Do a find-tag on the indicated symbol."
- ;; The awkward nested let's are to handle the case mouse-point isn't
- ;; in the current buffer.
- (let (str)
- (save-excursion
- (set-buffer (window-buffer x-mouse-win-u))
- (let ((begend (thing-boundaries x-mouse-point-u)))
- (setq str (buffer-substring (car begend) (cdr begend)))
- ))
- (find-tag str)
- ))
-
-