Changes between Initial Version and Version 1 of HemlockProgrammer/Miscellaneous


Ignore:
Timestamp:
Nov 5, 2007, 3:31:04 PM (13 years ago)
Author:
rme
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HemlockProgrammer/Miscellaneous

    v1 v1  
     1[[PageOutline]]
     2
     3= 17. Miscellaneous =
     4
     5This chapter is somewhat of a catch-all for comments and features that
     6don't fit well anywhere else.
     7
     8== 17.1. Generic Pointer Up ==
     9
     10Generic Pointer Up is a Hemlock command bound to mouse up-clicks. It
     11invokes a function supplied with the interface described in this
     12section. This command allows different commands to be bound to the
     13same down-click in various modes with one command bound to the
     14corresponding up-click.
     15
     16supply-generic-pointer-up-function      function         [Function]
     17               
     18This function supplies a function that Generic Pointer Up invokes the
     19next time it executes.
     20
     21
     22
     23== 17.2. Using View Mode ==
     24
     25View mode supports scrolling through files automatically terminating
     26the buffer at end-of-file as well as commands for quitting the mode
     27and popping back to the buffer that spawned the View mode
     28buffer. Modes such as Dired and Lisp-Lib use this to view files and
     29description of library entries.
     30
     31Modes that want similar commands should use view-file-command to view
     32a file and get a handle on the view buffer. To allow the View Return
     33and View Quit commands to return to the originating buffer, you must
     34set the variable View Return Function in the viewing buffer to a
     35function that knows how to do this. Furthermore, since you now have a
     36reference to the originating buffer, you must add a buffer local
     37delete hook to it that will clear the view return function's
     38reference. This needs to happen for two reasons in case the user
     39deletes the originating buffer:
     40
     41 1. You don't want the return function to go to a non-existing,
     42 invalid buffer.
     43
     44 2. Since the viewing buffer still exists, its View Return Function
     45 buffer local variable still exists. This means the function still
     46 references the deleted originating buffer, and garbage collection
     47 cannot reclaim the memory locked down by the deleted buffer.
     48
     49The following is a piece of code that could implement part of Dired
     50View File that uses two closures to accomplish that described above:
     51{{{
     52(let* ((dired-buf (current-buffer))
     53       (buffer (view-file-command nil pathname)))
     54  (push #'(lambda (buffer)
     55            (declare (ignore buffer))
     56            (setf dired-buf nil))
     57        (buffer-delete-hook dired-buf))
     58  (setf (variable-value 'view-return-function :buffer buffer)
     59        #'(lambda ()
     60            (if dired-buf
     61              (change-to-buffer dired-buf)
     62              (dired-from-buffer-pathname-command nil)))))
     63}}}
     64
     65The Dired buffer's delete hook clears the return function's reference
     66to the Dired buffer. The return function tests the variable to see if
     67it still holds a buffer when the function executes.
     68
     69
     70