diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/coding.c | 126 |
1 files changed, 88 insertions, 38 deletions
diff --git a/src/coding.c b/src/coding.c index e6d314786b2..a6c0e7d8345 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -263,7 +263,7 @@ int eol_mnemonic_undecided; | |||
| 263 | 263 | ||
| 264 | #ifdef emacs | 264 | #ifdef emacs |
| 265 | 265 | ||
| 266 | Lisp_Object Qcoding_system_vector, Qcoding_system_p, Qcoding_system_error; | 266 | Lisp_Object Qcoding_system_spec, Qcoding_system_p, Qcoding_system_error; |
| 267 | 267 | ||
| 268 | /* Coding-systems are handed between Emacs Lisp programs and C internal | 268 | /* Coding-systems are handed between Emacs Lisp programs and C internal |
| 269 | routines by the following three variables. */ | 269 | routines by the following three variables. */ |
| @@ -280,7 +280,9 @@ struct coding_system terminal_coding; | |||
| 280 | /* Coding-system of what is sent from terminal keyboard. */ | 280 | /* Coding-system of what is sent from terminal keyboard. */ |
| 281 | struct coding_system keyboard_coding; | 281 | struct coding_system keyboard_coding; |
| 282 | 282 | ||
| 283 | Lisp_Object Vcoding_system_alist; | 283 | Lisp_Object Vfile_coding_system_alist; |
| 284 | Lisp_Object Vprocess_coding_system_alist; | ||
| 285 | Lisp_Object Vnetwork_coding_system_alist; | ||
| 284 | 286 | ||
| 285 | #endif /* emacs */ | 287 | #endif /* emacs */ |
| 286 | 288 | ||
| @@ -317,6 +319,9 @@ Lisp_Object Qcharacter_unification_table; | |||
| 317 | /* Alist of charsets vs revision number. */ | 319 | /* Alist of charsets vs revision number. */ |
| 318 | Lisp_Object Vcharset_revision_alist; | 320 | Lisp_Object Vcharset_revision_alist; |
| 319 | 321 | ||
| 322 | /* Default coding systems used for process I/O. */ | ||
| 323 | Lisp_Object Vdefault_process_coding_system; | ||
| 324 | |||
| 320 | 325 | ||
| 321 | /*** 2. Emacs internal format (emacs-mule) handlers ***/ | 326 | /*** 2. Emacs internal format (emacs-mule) handlers ***/ |
| 322 | 327 | ||
| @@ -2771,9 +2776,9 @@ get_conversion_buffer (size) | |||
| 2771 | #ifdef emacs | 2776 | #ifdef emacs |
| 2772 | /*** 7. Emacs Lisp library functions ***/ | 2777 | /*** 7. Emacs Lisp library functions ***/ |
| 2773 | 2778 | ||
| 2774 | DEFUN ("coding-system-vector", Fcoding_system_vector, Scoding_system_vector, | 2779 | DEFUN ("coding-system-spec", Fcoding_system_spec, Scoding_system_spec, |
| 2775 | 1, 1, 0, | 2780 | 1, 1, 0, |
| 2776 | "Return coding-vector of CODING-SYSTEM.\n\ | 2781 | "Return coding-spec of CODING-SYSTEM.\n\ |
| 2777 | If CODING-SYSTEM is not a valid coding-system, return nil.") | 2782 | If CODING-SYSTEM is not a valid coding-system, return nil.") |
| 2778 | (obj) | 2783 | (obj) |
| 2779 | Lisp_Object obj; | 2784 | Lisp_Object obj; |
| @@ -2790,7 +2795,7 @@ See document of make-coding-system for coding-system object.") | |||
| 2790 | (obj) | 2795 | (obj) |
| 2791 | Lisp_Object obj; | 2796 | Lisp_Object obj; |
| 2792 | { | 2797 | { |
| 2793 | return ((NILP (obj) || !NILP (Fcoding_system_vector (obj))) ? Qt : Qnil); | 2798 | return ((NILP (obj) || !NILP (Fcoding_system_spec (obj))) ? Qt : Qnil); |
| 2794 | } | 2799 | } |
| 2795 | 2800 | ||
| 2796 | DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system, | 2801 | DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system, |
| @@ -2802,7 +2807,7 @@ DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system, | |||
| 2802 | Lisp_Object val; | 2807 | Lisp_Object val; |
| 2803 | do | 2808 | do |
| 2804 | { | 2809 | { |
| 2805 | val = Fcompleting_read (prompt, Vobarray, Qcoding_system_vector, | 2810 | val = Fcompleting_read (prompt, Vobarray, Qcoding_system_spec, |
| 2806 | Qt, Qnil, Qnil, Qnil); | 2811 | Qt, Qnil, Qnil, Qnil); |
| 2807 | } | 2812 | } |
| 2808 | while (XSTRING (val)->size == 0); | 2813 | while (XSTRING (val)->size == 0); |
| @@ -2832,7 +2837,7 @@ The value of property should be a vector of length 5.") | |||
| 2832 | if (!NILP (Fcoding_system_p (coding_system))) | 2837 | if (!NILP (Fcoding_system_p (coding_system))) |
| 2833 | return coding_system; | 2838 | return coding_system; |
| 2834 | while (1) | 2839 | while (1) |
| 2835 | Fsignal (Qcoding_system_error, coding_system); | 2840 | Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); |
| 2836 | } | 2841 | } |
| 2837 | 2842 | ||
| 2838 | DEFUN ("detect-coding-region", Fdetect_coding_region, Sdetect_coding_region, | 2843 | DEFUN ("detect-coding-region", Fdetect_coding_region, Sdetect_coding_region, |
| @@ -3398,10 +3403,12 @@ TARGET has a meaning which depends on OPERATION:\n\ | |||
| 3398 | For process I/O, TARGET is a process name.\n\ | 3403 | For process I/O, TARGET is a process name.\n\ |
| 3399 | For network I/O, TARGET is a service name or a port number\n\ | 3404 | For network I/O, TARGET is a service name or a port number\n\ |
| 3400 | \n\ | 3405 | \n\ |
| 3401 | This function looks up what `coding-system-alist' specifies for\n\ | 3406 | This function looks up what specified for TARGET in,\n\ |
| 3402 | OPERATION and TARGET. It may specify a cons cell which represents\n\ | 3407 | `file-coding-system-alist', `process-coding-system-alist',\n\ |
| 3403 | a particular coding system or it may have a function to call.\n\ | 3408 | or `network-coding-system-alist' depending on OPERATION.\n\ |
| 3404 | In the latter case, we call the function with one argument,\n\ | 3409 | They may specify a coding system, a cons of coding systems,\n\ |
| 3410 | or a function symbol to call.\n\ | ||
| 3411 | In the last case, we call the function with one argument,\n\ | ||
| 3405 | which is a list of all the arguments given to `find-coding-system'.") | 3412 | which is a list of all the arguments given to `find-coding-system'.") |
| 3406 | (nargs, args) | 3413 | (nargs, args) |
| 3407 | int nargs; | 3414 | int nargs; |
| @@ -3424,11 +3431,15 @@ which is a list of all the arguments given to `find-coding-system'.") | |||
| 3424 | || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) | 3431 | || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) |
| 3425 | error ("Invalid %dth argument", XINT (target_idx) + 1); | 3432 | error ("Invalid %dth argument", XINT (target_idx) + 1); |
| 3426 | 3433 | ||
| 3427 | chain = Fassq (operation, Vcoding_system_alist); | 3434 | chain = (operation == Qinsert_file_contents || operation == Qwrite_region |
| 3435 | ? Vfile_coding_system_alist | ||
| 3436 | : (operation == Qopen_network_stream | ||
| 3437 | ? Vnetwork_coding_system_alist | ||
| 3438 | : Vprocess_coding_system_alist)); | ||
| 3428 | if (NILP (chain)) | 3439 | if (NILP (chain)) |
| 3429 | return Qnil; | 3440 | return Qnil; |
| 3430 | 3441 | ||
| 3431 | for (chain = XCONS (chain)->cdr; CONSP (chain); chain = XCONS (chain)->cdr) | 3442 | for (; CONSP (chain); chain = XCONS (chain)->cdr) |
| 3432 | { | 3443 | { |
| 3433 | Lisp_Object elt = XCONS (chain)->car; | 3444 | Lisp_Object elt = XCONS (chain)->car; |
| 3434 | 3445 | ||
| @@ -3437,11 +3448,18 @@ which is a list of all the arguments given to `find-coding-system'.") | |||
| 3437 | && STRINGP (XCONS (elt)->car) | 3448 | && STRINGP (XCONS (elt)->car) |
| 3438 | && fast_string_match (XCONS (elt)->car, target) >= 0) | 3449 | && fast_string_match (XCONS (elt)->car, target) >= 0) |
| 3439 | || (INTEGERP (target) && EQ (target, XCONS (elt)->car)))) | 3450 | || (INTEGERP (target) && EQ (target, XCONS (elt)->car)))) |
| 3440 | return (val = XCONS (elt)->cdr, CONSP (val) | 3451 | { |
| 3441 | ? val | 3452 | val = XCONS (elt)->cdr; |
| 3442 | : ((SYMBOLP (val) && !NILP (Fboundp (val)) | 3453 | if (CONSP (val)) |
| 3443 | ? call2 (val, Flist (nargs, args)) | 3454 | return val; |
| 3444 | : Qnil))); | 3455 | if (! SYMBOLP (val)) |
| 3456 | return Qnil; | ||
| 3457 | if (! NILP (Fcoding_system_p (val))) | ||
| 3458 | return Fcons (val, val); | ||
| 3459 | if (!NILP (Fboundp (val))) | ||
| 3460 | return call2 (val, Flist (nargs, args)); | ||
| 3461 | return Qnil; | ||
| 3462 | } | ||
| 3445 | } | 3463 | } |
| 3446 | return Qnil; | 3464 | return Qnil; |
| 3447 | } | 3465 | } |
| @@ -3539,8 +3557,8 @@ syms_of_coding () | |||
| 3539 | Qpre_write_conversion = intern ("pre-write-conversion"); | 3557 | Qpre_write_conversion = intern ("pre-write-conversion"); |
| 3540 | staticpro (&Qpre_write_conversion); | 3558 | staticpro (&Qpre_write_conversion); |
| 3541 | 3559 | ||
| 3542 | Qcoding_system_vector = intern ("coding-system-vector"); | 3560 | Qcoding_system_spec = intern ("coding-system-spec"); |
| 3543 | staticpro (&Qcoding_system_vector); | 3561 | staticpro (&Qcoding_system_spec); |
| 3544 | 3562 | ||
| 3545 | Qcoding_system_p = intern ("coding-system-p"); | 3563 | Qcoding_system_p = intern ("coding-system-p"); |
| 3546 | staticpro (&Qcoding_system_p); | 3564 | staticpro (&Qcoding_system_p); |
| @@ -3572,7 +3590,7 @@ syms_of_coding () | |||
| 3572 | Fput (Qcharacter_unification_table, Qchar_table_extra_slots, | 3590 | Fput (Qcharacter_unification_table, Qchar_table_extra_slots, |
| 3573 | make_number (0)); | 3591 | make_number (0)); |
| 3574 | 3592 | ||
| 3575 | defsubr (&Scoding_system_vector); | 3593 | defsubr (&Scoding_system_spec); |
| 3576 | defsubr (&Scoding_system_p); | 3594 | defsubr (&Scoding_system_p); |
| 3577 | defsubr (&Sread_coding_system); | 3595 | defsubr (&Sread_coding_system); |
| 3578 | defsubr (&Sread_non_nil_coding_system); | 3596 | defsubr (&Sread_non_nil_coding_system); |
| @@ -3619,26 +3637,51 @@ If not, an appropriate element in `coding-system-alist' (which see) is used."); | |||
| 3619 | "Coding-system used in the latest file or process I/O."); | 3637 | "Coding-system used in the latest file or process I/O."); |
| 3620 | Vlast_coding_system_used = Qnil; | 3638 | Vlast_coding_system_used = Qnil; |
| 3621 | 3639 | ||
| 3622 | DEFVAR_LISP ("coding-system-alist", &Vcoding_system_alist, | 3640 | DEFVAR_LISP ("file-coding-system-alist", &Vfile_coding_system_alist, |
| 3623 | "Nested alist to decide a coding system for a specific I/O operation.\n\ | 3641 | "Alist to decide a coding system to use for a file I/O operation.\n\ |
| 3624 | The format is ((OPERATION . ((REGEXP . CODING-SYSTEMS) ...)) ...).\n\ | 3642 | The format is ((PATTERN . VAL) ...),\n\ |
| 3643 | where PATTERN is a regular expression matching a file name,\n\ | ||
| 3644 | VAL is a coding system, a cons of coding systems, or a function symbol.\n\ | ||
| 3645 | If VAL is a coding system, it is used for both decoding and encoding\n\ | ||
| 3646 | the file contents.\n\ | ||
| 3647 | If VAL is a cons of coding systems, the car part is used for decoding,\n\ | ||
| 3648 | and the cdr part is used for encoding.\n\ | ||
| 3649 | If VAL is a function symbol, the function must return a coding system\n\ | ||
| 3650 | or a cons of coding systems which are used as above.\n\ | ||
| 3625 | \n\ | 3651 | \n\ |
| 3626 | OPERATION is one of the following Emacs I/O primitives:\n\ | 3652 | See also the function `find-coding-system'."); |
| 3627 | For file I/O, insert-file-contents and write-region.\n\ | 3653 | Vfile_coding_system_alist = Qnil; |
| 3628 | For process I/O, call-process, call-process-region, and start-process.\n\ | 3654 | |
| 3629 | For network I/O, open-network-stream.\n\ | 3655 | DEFVAR_LISP ("process-coding-system-alist", &Vprocess_coding_system_alist, |
| 3630 | In addition, for process I/O, `process-argument' can be specified for\n\ | 3656 | "Alist to decide a coding system to use for a process I/O operation.\n\ |
| 3631 | encoding arguments of the process.\n\ | 3657 | The format is ((PATTERN . VAL) ...),\n\ |
| 3658 | where PATTERN is a regular expression matching a program name,\n\ | ||
| 3659 | VAL is a coding system, a cons of coding systems, or a function symbol.\n\ | ||
| 3660 | If VAL is a coding system, it is used for both decoding what received\n\ | ||
| 3661 | from the program and encoding what sent to the program.\n\ | ||
| 3662 | If VAL is a cons of coding systems, the car part is used for decoding,\n\ | ||
| 3663 | and the cdr part is used for encoding.\n\ | ||
| 3664 | If VAL is a function symbol, the function must return a coding system\n\ | ||
| 3665 | or a cons of coding systems which are used as above.\n\ | ||
| 3632 | \n\ | 3666 | \n\ |
| 3633 | REGEXP is a regular expression matching a target of OPERATION, where\n\ | 3667 | See also the function `find-coding-system'."); |
| 3634 | target is a file name for file I/O operations, a process name for\n\ | 3668 | Vprocess_coding_system_alist = Qnil; |
| 3635 | process I/O operations, or a service name for network I/O\n\ | 3669 | |
| 3636 | operations. REGEXP might be a port number for network I/O operation.\n\ | 3670 | DEFVAR_LISP ("network-coding-system-alist", &Vnetwork_coding_system_alist, |
| 3671 | "Alist to decide a coding system to use for a network I/O operation.\n\ | ||
| 3672 | The format is ((PATTERN . VAL) ...),\n\ | ||
| 3673 | where PATTERN is a regular expression matching a network service name\n\ | ||
| 3674 | or is a port number to connect to,\n\ | ||
| 3675 | VAL is a coding system, a cons of coding systems, or a function symbol.\n\ | ||
| 3676 | If VAL is a coding system, it is used for both decoding what received\n\ | ||
| 3677 | from the network stream and encoding what sent to the network stream.\n\ | ||
| 3678 | If VAL is a cons of coding systems, the car part is used for decoding,\n\ | ||
| 3679 | and the cdr part is used for encoding.\n\ | ||
| 3680 | If VAL is a function symbol, the function must return a coding system\n\ | ||
| 3681 | or a cons of coding systems which are used as above.\n\ | ||
| 3637 | \n\ | 3682 | \n\ |
| 3638 | CODING-SYSTEMS is a cons of coding systems to encode and decode\n\ | 3683 | See also the function `find-coding-system'."); |
| 3639 | character code on OPERATION, or a function symbol returning the cons.\n\ | 3684 | Vnetwork_coding_system_alist = Qnil; |
| 3640 | See the documentation of `find-coding-system' for more detail."); | ||
| 3641 | Vcoding_system_alist = Qnil; | ||
| 3642 | 3685 | ||
| 3643 | DEFVAR_INT ("eol-mnemonic-unix", &eol_mnemonic_unix, | 3686 | DEFVAR_INT ("eol-mnemonic-unix", &eol_mnemonic_unix, |
| 3644 | "Mnemonic character indicating UNIX-like end-of-line format (i.e. LF) ."); | 3687 | "Mnemonic character indicating UNIX-like end-of-line format (i.e. LF) ."); |
| @@ -3675,6 +3718,13 @@ See the documentation of `find-coding-system' for more detail."); | |||
| 3675 | While encoding, if a charset (car part of an element) is found,\n\ | 3718 | While encoding, if a charset (car part of an element) is found,\n\ |
| 3676 | designate it with the escape sequence identifing revision (cdr part of the element)."); | 3719 | designate it with the escape sequence identifing revision (cdr part of the element)."); |
| 3677 | Vcharset_revision_alist = Qnil; | 3720 | Vcharset_revision_alist = Qnil; |
| 3721 | |||
| 3722 | DEFVAR_LISP ("default-process-coding-system", | ||
| 3723 | &Vdefault_process_coding_system, | ||
| 3724 | "Cons of coding systems used for process I/O by default.\n\ | ||
| 3725 | The car part is used for decoding a process output,\n\ | ||
| 3726 | the cdr part is used for encoding a text to be sent to a process."); | ||
| 3727 | Vdefault_process_coding_system = Qnil; | ||
| 3678 | } | 3728 | } |
| 3679 | 3729 | ||
| 3680 | #endif /* emacs */ | 3730 | #endif /* emacs */ |