diff options
| author | Dmitry Antipov | 2014-07-16 12:45:22 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2014-07-16 12:45:22 +0400 |
| commit | e0b07ec3416d1ee7c77234e9dd0a7408b50da83c (patch) | |
| tree | 430fc691f2cc593268fd1ada8defcec5b9c78ef4 /src/data.c | |
| parent | 74660d84d923fd8252b166770ca2403f6025a7ac (diff) | |
| download | emacs-e0b07ec3416d1ee7c77234e9dd0a7408b50da83c.tar.gz emacs-e0b07ec3416d1ee7c77234e9dd0a7408b50da83c.zip | |
More precise control over values of some buffer-local variables.
* keyboard.c (Qvertical_scroll_bar):
* frame.c (Qleft, Qright): Move to ...
* buffer.c (Qleft, Qright, Qvertical_scroll_bar): ... here.
* buffer.c (Qchoice, Qrange, Qoverwrite_mode, Qfraction): New symbols.
(syms_of_buffer): DEFSYM all of the above, attach special properties.
Use special symbols to DEFVAR_PER_BUFFER overwrite-mode,
vertical-scroll-bar, scroll-up-aggressively
and scroll-down-aggressively.
* buffer.h (Qchoice, Qrange, Qleft, Qright, Qvertical_scroll_bar):
Add declarations.
* nsfns.m, frame.h (Qleft, Qright):
* nsterm.m (Qleft): Remove declarations.
* gtkutil.c (toplevel): Include buffer.h.
* data.c (wrong_choice, wrong_range): New functions.
(store_symval_forwarding): Handle special properties of buffer-local
variables and use functions from the above to signal error, if any.
Diffstat (limited to 'src/data.c')
| -rw-r--r-- | src/data.c | 71 |
1 files changed, 68 insertions, 3 deletions
diff --git a/src/data.c b/src/data.c index 2de1c19452c..790d0fee981 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -971,6 +971,48 @@ do_symval_forwarding (register union Lisp_Fwd *valcontents) | |||
| 971 | } | 971 | } |
| 972 | } | 972 | } |
| 973 | 973 | ||
| 974 | /* Used to signal a user-friendly error when symbol WRONG is | ||
| 975 | not a member of CHOICE, which should be a list of symbols. */ | ||
| 976 | |||
| 977 | static void | ||
| 978 | wrong_choice (Lisp_Object choice, Lisp_Object wrong) | ||
| 979 | { | ||
| 980 | ptrdiff_t i = 0, len = XINT (Flength (choice)); | ||
| 981 | Lisp_Object obj, *args; | ||
| 982 | |||
| 983 | USE_SAFE_ALLOCA; | ||
| 984 | SAFE_ALLOCA_LISP (args, len * 2 + 1); | ||
| 985 | |||
| 986 | args[i++] = build_string ("One of "); | ||
| 987 | |||
| 988 | for (obj = choice; !NILP (obj); obj = XCDR (obj)) | ||
| 989 | { | ||
| 990 | args[i++] = SYMBOL_NAME (XCAR (obj)); | ||
| 991 | args[i++] = build_string (NILP (XCDR (obj)) ? " should be specified" | ||
| 992 | : (NILP (XCDR (XCDR (obj))) ? " or " : ", ")); | ||
| 993 | } | ||
| 994 | |||
| 995 | obj = Fconcat (i, args); | ||
| 996 | SAFE_FREE (); | ||
| 997 | xsignal2 (Qerror, obj, wrong); | ||
| 998 | } | ||
| 999 | |||
| 1000 | /* Used to signal a user-friendly error if WRONG is not a number or | ||
| 1001 | integer/floating-point number outsize of inclusive MIN..MAX range. */ | ||
| 1002 | |||
| 1003 | static void | ||
| 1004 | wrong_range (Lisp_Object min, Lisp_Object max, Lisp_Object wrong) | ||
| 1005 | { | ||
| 1006 | Lisp_Object args[4]; | ||
| 1007 | |||
| 1008 | args[0] = build_string ("Value should be from "); | ||
| 1009 | args[1] = Fnumber_to_string (min); | ||
| 1010 | args[2] = build_string (" to "); | ||
| 1011 | args[3] = Fnumber_to_string (max); | ||
| 1012 | |||
| 1013 | xsignal2 (Qerror, Fconcat (4, args), wrong); | ||
| 1014 | } | ||
| 1015 | |||
| 974 | /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell | 1016 | /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell |
| 975 | of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the | 1017 | of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the |
| 976 | buffer-independent contents of the value cell: forwarded just one | 1018 | buffer-independent contents of the value cell: forwarded just one |
| @@ -1027,10 +1069,33 @@ store_symval_forwarding (union Lisp_Fwd *valcontents, register Lisp_Object newva | |||
| 1027 | int offset = XBUFFER_OBJFWD (valcontents)->offset; | 1069 | int offset = XBUFFER_OBJFWD (valcontents)->offset; |
| 1028 | Lisp_Object predicate = XBUFFER_OBJFWD (valcontents)->predicate; | 1070 | Lisp_Object predicate = XBUFFER_OBJFWD (valcontents)->predicate; |
| 1029 | 1071 | ||
| 1030 | if (!NILP (predicate) && !NILP (newval) | 1072 | if (!NILP (newval)) |
| 1031 | && NILP (call1 (predicate, newval))) | 1073 | { |
| 1032 | wrong_type_argument (predicate, newval); | 1074 | if (SYMBOLP (predicate)) |
| 1075 | { | ||
| 1076 | Lisp_Object prop; | ||
| 1077 | |||
| 1078 | if ((prop = Fget (predicate, Qchoice), !NILP (prop))) | ||
| 1079 | { | ||
| 1080 | if (NILP (Fmemq (newval, prop))) | ||
| 1081 | wrong_choice (prop, newval); | ||
| 1082 | } | ||
| 1083 | else if ((prop = Fget (predicate, Qrange), !NILP (prop))) | ||
| 1084 | { | ||
| 1085 | Lisp_Object min = XCAR (prop), max = XCDR (prop); | ||
| 1033 | 1086 | ||
| 1087 | if (!NUMBERP (newval) | ||
| 1088 | || !NILP (arithcompare (newval, min, ARITH_LESS)) | ||
| 1089 | || !NILP (arithcompare (newval, max, ARITH_GRTR))) | ||
| 1090 | wrong_range (min, max, newval); | ||
| 1091 | } | ||
| 1092 | else if (FUNCTIONP (predicate)) | ||
| 1093 | { | ||
| 1094 | if (NILP (call1 (predicate, newval))) | ||
| 1095 | wrong_type_argument (predicate, newval); | ||
| 1096 | } | ||
| 1097 | } | ||
| 1098 | } | ||
| 1034 | if (buf == NULL) | 1099 | if (buf == NULL) |
| 1035 | buf = current_buffer; | 1100 | buf = current_buffer; |
| 1036 | set_per_buffer_value (buf, offset, newval); | 1101 | set_per_buffer_value (buf, offset, newval); |