comparison lispref/files.texi @ 61949:d0cfb9c978f9

(Magic File Names): Document `operations' property.
author Richard M. Stallman <rms@gnu.org>
date Sat, 30 Apr 2005 20:30:03 +0000
parents 8757023049af
children 78962e585d20 08185296b491
comparison
equal deleted inserted replaced
61948:722ca07ff821 61949:d0cfb9c978f9
2439 All the Emacs primitives for file access and file name transformation 2439 All the Emacs primitives for file access and file name transformation
2440 check the given file name against @code{file-name-handler-alist}. If 2440 check the given file name against @code{file-name-handler-alist}. If
2441 the file name matches @var{regexp}, the primitives handle that file by 2441 the file name matches @var{regexp}, the primitives handle that file by
2442 calling @var{handler}. 2442 calling @var{handler}.
2443 2443
2444 The first argument given to @var{handler} is the name of the 2444 The first argument given to @var{handler} is the name of the
2445 primitive, as a symbol; the remaining arguments are the arguments that 2445 primitive, as a symbol; the remaining arguments are the arguments that
2446 were passed to that primitive. (The first of these arguments is most 2446 were passed to that primitive. (The first of these arguments is most
2447 often the file name itself.) For example, if you do this: 2447 often the file name itself.) For example, if you do this:
2448 2448
2449 @example 2449 @example
2456 2456
2457 @example 2457 @example
2458 (funcall @var{handler} 'file-exists-p @var{filename}) 2458 (funcall @var{handler} 'file-exists-p @var{filename})
2459 @end example 2459 @end example
2460 2460
2461 When a function takes two or more arguments that must be file names, 2461 When a function takes two or more arguments that must be file names,
2462 it checks each of those names for a handler. For example, if you do 2462 it checks each of those names for a handler. For example, if you do
2463 this: 2463 this:
2464 2464
2465 @example 2465 @example
2466 (expand-file-name @var{filename} @var{dirname}) 2466 (expand-file-name @var{filename} @var{dirname})
2477 2477
2478 @noindent 2478 @noindent
2479 The @var{handler} then needs to figure out whether to handle 2479 The @var{handler} then needs to figure out whether to handle
2480 @var{filename} or @var{dirname}. 2480 @var{filename} or @var{dirname}.
2481 2481
2482 If the specified file name matches more than one handler, the one 2482 If the specified file name matches more than one handler, the one
2483 whose match starts last in the file name gets precedence. This rule 2483 whose match starts last in the file name gets precedence. This rule
2484 is chosen so that handlers for jobs such as uncompression are handled 2484 is chosen so that handlers for jobs such as uncompression are handled
2485 first, before handlers for jobs such as remote file access. 2485 first, before handlers for jobs such as remote file access.
2486 2486
2487 Here are the operations that a magic file name handler gets to handle: 2487 Here are the operations that a magic file name handler gets to handle:
2573 @code{verify-visited-file-modtime}, 2573 @code{verify-visited-file-modtime},
2574 @code{write-region}. 2574 @code{write-region}.
2575 @end flushleft 2575 @end flushleft
2576 @end iftex 2576 @end iftex
2577 2577
2578 Handlers for @code{insert-file-contents} typically need to clear the 2578 Handlers for @code{insert-file-contents} typically need to clear the
2579 buffer's modified flag, with @code{(set-buffer-modified-p nil)}, if the 2579 buffer's modified flag, with @code{(set-buffer-modified-p nil)}, if the
2580 @var{visit} argument is non-@code{nil}. This also has the effect of 2580 @var{visit} argument is non-@code{nil}. This also has the effect of
2581 unlocking the buffer if it is locked. 2581 unlocking the buffer if it is locked.
2582 2582
2583 The handler function must handle all of the above operations, and 2583 The handler function must handle all of the above operations, and
2584 possibly others to be added in the future. It need not implement all 2584 possibly others to be added in the future. It need not implement all
2585 these operations itself---when it has nothing special to do for a 2585 these operations itself---when it has nothing special to do for a
2586 certain operation, it can reinvoke the primitive, to handle the 2586 certain operation, it can reinvoke the primitive, to handle the
2587 operation ``in the usual way''. It should always reinvoke the primitive 2587 operation ``in the usual way''. It should always reinvoke the primitive
2588 for an operation it does not recognize. Here's one way to do this: 2588 for an operation it does not recognize. Here's one way to do this:
2601 inhibit-file-name-handlers))) 2601 inhibit-file-name-handlers)))
2602 (inhibit-file-name-operation operation)) 2602 (inhibit-file-name-operation operation))
2603 (apply operation args))))) 2603 (apply operation args)))))
2604 @end smallexample 2604 @end smallexample
2605 2605
2606 When a handler function decides to call the ordinary Emacs primitive for 2606 When a handler function decides to call the ordinary Emacs primitive for
2607 the operation at hand, it needs to prevent the primitive from calling 2607 the operation at hand, it needs to prevent the primitive from calling
2608 the same handler once again, thus leading to an infinite recursion. The 2608 the same handler once again, thus leading to an infinite recursion. The
2609 example above shows how to do this, with the variables 2609 example above shows how to do this, with the variables
2610 @code{inhibit-file-name-handlers} and 2610 @code{inhibit-file-name-handlers} and
2611 @code{inhibit-file-name-operation}. Be careful to use them exactly as 2611 @code{inhibit-file-name-operation}. Be careful to use them exactly as
2612 shown above; the details are crucial for proper behavior in the case of 2612 shown above; the details are crucial for proper behavior in the case of
2613 multiple handlers, and for operations that have two file names that may 2613 multiple handlers, and for operations that have two file names that may
2614 each have handlers. 2614 each have handlers.
2615 2615
2616 @kindex safe-magic (@r{property}) 2616 @kindex safe-magic (@r{property})
2617 Handlers that don't really do anything special for actual access to the 2617 Handlers that don't really do anything special for actual access to the
2618 file---such as the ones that implement completion of host names for 2618 file---such as the ones that implement completion of host names for
2619 remote file names---should have a non-@code{nil} @code{safe-magic} 2619 remote file names---should have a non-@code{nil} @code{safe-magic}
2620 property. For instance, Emacs normally ``protects'' directory names 2620 property. For instance, Emacs normally ``protects'' directory names
2621 it finds in @code{PATH} from becoming magic, if they look like magic 2621 it finds in @code{PATH} from becoming magic, if they look like magic
2622 file names, by prefixing them with @samp{/:}. But if the handler that 2622 file names, by prefixing them with @samp{/:}. But if the handler that
2623 would be used for them has a non-@code{nil} @code{safe-magic} 2623 would be used for them has a non-@code{nil} @code{safe-magic}
2624 property, the @samp{/:} is not added. 2624 property, the @samp{/:} is not added.
2625
2626 @kindex operations (@r{property})
2627 A file name handler can have an @code{operations} property to
2628 declare which operations it handles in a nontrivial way. If this
2629 property has a non-@code{nil} value, it should be a list of
2630 operations; then only those operations will call the handler. This
2631 avoids inefficiency, but its main purpose is for autoloaded handler
2632 functions, so that they won't be loaded except when they have real
2633 work to do.
2625 2634
2626 @defvar inhibit-file-name-handlers 2635 @defvar inhibit-file-name-handlers
2627 This variable holds a list of handlers whose use is presently inhibited 2636 This variable holds a list of handlers whose use is presently inhibited
2628 for a certain operation. 2637 for a certain operation.
2629 @end defvar 2638 @end defvar