Mercurial > hg > xemacs-beta
comparison man/lispref/text.texi @ 377:d883f39b8495 r21-2b4
Import from CVS: tag r21-2b4
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:05:42 +0200 |
parents | c9fe270a4101 |
children | 74fd4e045ea6 |
comparison
equal
deleted
inserted
replaced
376:e2295b4d9f2e | 377:d883f39b8495 |
---|---|
51 * Substitution:: Replacing a given character wherever it appears. | 51 * Substitution:: Replacing a given character wherever it appears. |
52 * Registers:: How registers are implemented. Accessing the text or | 52 * Registers:: How registers are implemented. Accessing the text or |
53 position stored in a register. | 53 position stored in a register. |
54 * Transposition:: Swapping two portions of a buffer. | 54 * Transposition:: Swapping two portions of a buffer. |
55 * Change Hooks:: Supplying functions to be run when text is changed. | 55 * Change Hooks:: Supplying functions to be run when text is changed. |
56 * Transformations:: MD5 and base64 support. | |
56 @end menu | 57 @end menu |
57 | 58 |
58 @node Near Point | 59 @node Near Point |
59 @section Examining Text Near Point | 60 @section Examining Text Near Point |
60 | 61 |
2666 | 2667 |
2667 @defvar first-change-hook | 2668 @defvar first-change-hook |
2668 This variable is a normal hook that is run whenever a buffer is changed | 2669 This variable is a normal hook that is run whenever a buffer is changed |
2669 that was previously in the unmodified state. | 2670 that was previously in the unmodified state. |
2670 @end defvar | 2671 @end defvar |
2672 | |
2673 @node Transformations | |
2674 @section Textual transformations---MD5 and base64 support | |
2675 @cindex MD5 digests | |
2676 @cindex base64 | |
2677 | |
2678 Some textual operations inherently require examining each character in | |
2679 turn, and performing arithmetic operations on them. Such operations | |
2680 can, of course, be implemented in Emacs Lisp, but tend to be very slow | |
2681 for large portions of text or data. This is why some of them are | |
2682 implemented in C, with an appropriate interface for Lisp programmers. | |
2683 Examples of algorithms thus provided are MD5 and base64 support. | |
2684 | |
2685 MD5 is an algorithm for calculating message digests, as described in | |
2686 rfc1321. Given a message of arbitrary length, MD5 produces an 128-bit | |
2687 ``fingerprint'' (``message digest'') corresponding to that message. It | |
2688 is considered computationally infeasible to produce two messages having | |
2689 the same MD5 digest, or to produce a message having a prespecified | |
2690 target digest. MD5 is used heavily by various authentication schemes. | |
2691 | |
2692 Emacs Lisp interface to MD5 consists of a single function @code{md5}: | |
2693 | |
2694 @defun md5 object &optional start end | |
2695 This function returns the MD5 message digest of @var{object}, a buffer | |
2696 or string. | |
2697 | |
2698 Optional arguments @var{start} and @var{end} denote positions for | |
2699 computing the digest of a portion of @var{object}. | |
2700 | |
2701 Some examples of usage: | |
2702 | |
2703 @example | |
2704 @group | |
2705 ;; @r{Calculate the digest of the entire buffer} | |
2706 (md5 (current-buffer)) | |
2707 @result{} "8842b04362899b1cda8d2d126dc11712" | |
2708 @end group | |
2709 | |
2710 @group | |
2711 ;; @r{Calculate the digest of the current line} | |
2712 (md5 (current-buffer) (point-at-bol) (point-at-eol)) | |
2713 @result{} "60614d21e9dee27dfdb01fa4e30d6d00" | |
2714 @end group | |
2715 | |
2716 @group | |
2717 ;; @r{Calculate the digest of your name and email address} | |
2718 (md5 (concat (format "%s <%s>" (user-full-name) user-mail-address))) | |
2719 @result{} "0a2188c40fd38922d941fe6032fce516" | |
2720 @end group | |
2721 @end example | |
2722 @end defun | |
2723 | |
2724 Base64 is a portable encoding for arbitrary sequences of octets, in a | |
2725 form that need not be readable by humans. It uses a 65-character subset | |
2726 of US-ASCII, as described in rfc2045. Base64 is used by MIME to encode | |
2727 binary bodies, and to encode binary characters in message headers. | |
2728 | |
2729 The Lisp interface to base64 consists of four functions: | |
2730 | |
2731 @defun base64-encode-region beg end &optional no-line-break | |
2732 This function encodes the region between @var{beg} and @var{end} of the | |
2733 current buffer to base64 format. This means that the original region is | |
2734 deleted, and replaced with its base64 equivalent. | |
2735 | |
2736 Normally, encoded base64 output is multi-line, with 76-character lines. | |
2737 If @var{no-line-break} is non-@code{nil}, newlines will not be inserted, | |
2738 resulting in single-line output. | |
2739 | |
2740 Mule note: you should make sure that you convert the multibyte | |
2741 characters (those that do not fit into 0--255 range) to something else, | |
2742 because they cannot be meaningfully converted to base64. If the | |
2743 @code{base64-encode-region} encounters such characters, it will signal | |
2744 an error. | |
2745 | |
2746 @code{base64-encode-region} returns the length of the encoded text. | |
2747 | |
2748 @example | |
2749 @group | |
2750 ;; @r{Encode the whole buffer in base64} | |
2751 (base64-encode-region (point-min) (point-max)) | |
2752 @end group | |
2753 @end example | |
2754 | |
2755 The function can also be used interactively, in which case it works on | |
2756 the currently active region. | |
2757 @end defun | |
2758 | |
2759 @defun base64-encode-string string | |
2760 This function encodes @var{string} to base64, and returns the encoded | |
2761 string. | |
2762 | |
2763 For Mule, the same considerations apply as for | |
2764 @code{base64-encode-region}. | |
2765 | |
2766 @example | |
2767 @group | |
2768 (base64-encode-string "fubar") | |
2769 @result{} "ZnViYXI=" | |
2770 @end group | |
2771 @end example | |
2772 @end defun | |
2773 | |
2774 @defun base64-decode-region beg end | |
2775 This function decodes the region between @var{beg} and @var{end} of the | |
2776 current buffer. The region should be in base64 encoding. | |
2777 | |
2778 If the region was decoded correctly, @code{base64-decode-region} returns | |
2779 the length of the decoded region. If the decoding failed, @code{nil} is | |
2780 returned. | |
2781 | |
2782 @example | |
2783 @group | |
2784 ;; @r{Decode a base64 buffer, and replace it with the decoded version} | |
2785 (base64-decode-region (point-min) (point-max)) | |
2786 @end group | |
2787 @end example | |
2788 @end defun | |
2789 | |
2790 @defun base64-decode-string string | |
2791 This function decodes @var{string} to base64, and returns the decoded | |
2792 string. @var{string} should be valid base64-encoded text. | |
2793 | |
2794 If encoding was not possible, @code{nil} is returned. | |
2795 | |
2796 @example | |
2797 @group | |
2798 (base64-decode-string "ZnViYXI=") | |
2799 @result{} "fubar" | |
2800 @end group | |
2801 | |
2802 @group | |
2803 (base64-decode-string "totally bogus") | |
2804 @result{} nil | |
2805 @end group | |
2806 @end example | |
2807 @end defun |