Mercurial > emacs
comparison lisp/descr-text.el @ 47601:7d00d911e8b9
(describe-text-category): Use *Help*. Don't kill-buffer.
(describe-text-properties, describe-char):
Delay self-inspection test. Use *Help*.
Use syntax-after. Use `pos' rather than (point).
Distinguish the before/after part of a composition.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 24 Sep 2002 21:11:25 +0000 |
parents | 0c38024f4c40 |
children | e84990b6ae01 |
comparison
equal
deleted
inserted
replaced
47600:6ff56be7780a | 47601:7d00d911e8b9 |
---|---|
134 ;;; Describe-Text Commands. | 134 ;;; Describe-Text Commands. |
135 | 135 |
136 (defun describe-text-category (category) | 136 (defun describe-text-category (category) |
137 "Describe a text property category." | 137 "Describe a text property category." |
138 (interactive "S") | 138 (interactive "S") |
139 (when (get-buffer "*Text Category*") | |
140 (kill-buffer "*Text Category*")) | |
141 (save-excursion | 139 (save-excursion |
142 (with-output-to-temp-buffer "*Text Category*" | 140 (with-output-to-temp-buffer "*Help*" |
143 (set-buffer "*Text Category*") | 141 (set-buffer standard-output) |
144 (widget-insert "Category " (format "%S" category) ":\n\n") | 142 (widget-insert "Category " (format "%S" category) ":\n\n") |
145 (describe-property-list (symbol-plist category)) | 143 (describe-property-list (symbol-plist category)) |
146 (describe-text-mode) | 144 (describe-text-mode) |
147 (goto-char (point-min))))) | 145 (goto-char (point-min))))) |
148 | 146 |
152 Interactively, describe them for the character after point. | 150 Interactively, describe them for the character after point. |
153 If optional second argument OUTPUT-BUFFER is non-nil, | 151 If optional second argument OUTPUT-BUFFER is non-nil, |
154 insert the output into that buffer, and don't initialize or clear it | 152 insert the output into that buffer, and don't initialize or clear it |
155 otherwise." | 153 otherwise." |
156 (interactive "d") | 154 (interactive "d") |
157 (when (eq (current-buffer) (get-buffer "*Text Description*")) | |
158 (error "Can't do self inspection")) | |
159 (if (>= pos (point-max)) | 155 (if (>= pos (point-max)) |
160 (error "No character follows specified position")) | 156 (error "No character follows specified position")) |
161 (if output-buffer | 157 (if output-buffer |
162 (describe-text-properties-1 pos output-buffer) | 158 (describe-text-properties-1 pos output-buffer) |
163 (if (not (or (text-properties-at pos) (overlays-at pos))) | 159 (if (not (or (text-properties-at pos) (overlays-at pos))) |
164 (message "This is plain text.") | 160 (message "This is plain text.") |
165 (let ((buffer (current-buffer))) | 161 (let ((buffer (current-buffer))) |
162 (when (eq buffer (get-buffer "*Help*")) | |
163 (error "Can't do self inspection")) | |
166 (save-excursion | 164 (save-excursion |
167 (with-output-to-temp-buffer "*Text Description*" | 165 (with-output-to-temp-buffer "*Help*" |
168 (set-buffer "*Text Description*") | 166 (set-buffer standard-output) |
169 (setq output-buffer (current-buffer)) | 167 (setq output-buffer (current-buffer)) |
170 (widget-insert "Text content at position " (format "%d" pos) ":\n\n") | 168 (widget-insert "Text content at position " (format "%d" pos) ":\n\n") |
171 (with-current-buffer buffer | 169 (with-current-buffer buffer |
172 (describe-text-properties-1 pos output-buffer)) | 170 (describe-text-properties-1 pos output-buffer)) |
173 (describe-text-mode) | 171 (describe-text-mode) |
224 The information includes character code, charset and code points in it, | 222 The information includes character code, charset and code points in it, |
225 syntax, category, how the character is encoded in a file, | 223 syntax, category, how the character is encoded in a file, |
226 character composition information (if relevant), | 224 character composition information (if relevant), |
227 as well as widgets, buttons, overlays, and text properties." | 225 as well as widgets, buttons, overlays, and text properties." |
228 (interactive "d") | 226 (interactive "d") |
229 (when (eq (current-buffer) (get-buffer "*Text Description*")) | |
230 (error "Can't do self inspection")) | |
231 (if (>= pos (point-max)) | 227 (if (>= pos (point-max)) |
232 (error "No character follows specified position")) | 228 (error "No character follows specified position")) |
233 (let* ((char (char-after pos)) | 229 (let* ((char (char-after pos)) |
234 (charset (char-charset char)) | 230 (charset (char-charset char)) |
235 (buffer (current-buffer)) | 231 (buffer (current-buffer)) |
236 (composition (find-composition (point) nil nil t)) | 232 (composition (find-composition pos nil nil t)) |
237 (composed (if composition (buffer-substring (car composition) | 233 (composed (if composition (buffer-substring (car composition) |
238 (nth 1 composition)))) | 234 (nth 1 composition)))) |
239 (multibyte-p enable-multibyte-characters) | 235 (multibyte-p enable-multibyte-characters) |
240 item-list max-width) | 236 item-list max-width) |
241 (if (eq charset 'unknown) | 237 (if (eq charset 'unknown) |
259 ,(let ((split (split-char char))) | 255 ,(let ((split (split-char char))) |
260 (if (= (charset-dimension charset) 1) | 256 (if (= (charset-dimension charset) 1) |
261 (format "%d" (nth 1 split)) | 257 (format "%d" (nth 1 split)) |
262 (format "%d %d" (nth 1 split) (nth 2 split))))) | 258 (format "%d %d" (nth 1 split) (nth 2 split))))) |
263 ("syntax" | 259 ("syntax" |
264 ,(let ((syntax (get-char-property (point) 'syntax-table))) | 260 ,(let ((syntax (syntax-after pos))) |
265 (with-temp-buffer | 261 (with-temp-buffer |
266 (internal-describe-syntax-value | 262 (internal-describe-syntax-value syntax) |
267 (if (consp syntax) syntax | |
268 (aref (or syntax (syntax-table)) char))) | |
269 (buffer-string)))) | 263 (buffer-string)))) |
270 ("category" | 264 ("category" |
271 ,@(let ((category-set (char-category-set char))) | 265 ,@(let ((category-set (char-category-set char))) |
272 (if (not category-set) | 266 (if (not category-set) |
273 '("-- none --") | 267 '("-- none --") |
291 (list (encoded-string-description encoded coding) | 285 (list (encoded-string-description encoded coding) |
292 (format "(encoded by coding system %S)" coding)) | 286 (format "(encoded by coding system %S)" coding)) |
293 (list "not encodable by coding system" | 287 (list "not encodable by coding system" |
294 (symbol-name coding))))) | 288 (symbol-name coding))))) |
295 ,@(if (or (memq 'mule-utf-8 | 289 ,@(if (or (memq 'mule-utf-8 |
296 (find-coding-systems-region (point) (1+ (point)))) | 290 (find-coding-systems-region pos (1+ pos))) |
297 (get-char-property (point) 'untranslated-utf-8)) | 291 (get-char-property pos 'untranslated-utf-8)) |
298 (let ((uc (or (get-char-property (point) | 292 (let ((uc (or (get-char-property pos 'untranslated-utf-8) |
299 'untranslated-utf-8) | 293 (encode-char char 'ucs)))) |
300 (encode-char (char-after) 'ucs)))) | |
301 (if uc | 294 (if uc |
302 (list (list "Unicode" | 295 (list (list "Unicode" |
303 (format "%04X" uc)))))) | 296 (format "%04X" uc)))))) |
304 ,(if (display-graphic-p (selected-frame)) | 297 ,(if (display-graphic-p (selected-frame)) |
305 (list "font" (or (internal-char-font (point)) | 298 (list "font" (or (internal-char-font pos) |
306 "-- none --")) | 299 "-- none --")) |
307 (list "terminal code" | 300 (list "terminal code" |
308 (let* ((coding (terminal-coding-system)) | 301 (let* ((coding (terminal-coding-system)) |
309 (encoded (encode-coding-char char coding))) | 302 (encoded (encode-coding-char char coding))) |
310 (if encoded | 303 (if encoded |
311 (encoded-string-description encoded coding) | 304 (encoded-string-description encoded coding) |
312 "not encodable"))))))) | 305 "not encodable"))))))) |
313 (setq max-width (apply #'max (mapcar #'(lambda (x) (length (car x))) | 306 (setq max-width (apply #'max (mapcar #'(lambda (x) (length (car x))) |
314 item-list))) | 307 item-list))) |
315 (when (get-buffer "*Help*") | 308 (when (eq (current-buffer) (get-buffer "*Help*")) |
316 (kill-buffer "*Help*")) | 309 (error "Can't do self inspection")) |
317 (with-output-to-temp-buffer "*Help*" | 310 (with-output-to-temp-buffer "*Help*" |
318 (save-excursion | 311 (with-current-buffer standard-output |
319 (set-buffer standard-output) | |
320 (set-buffer-multibyte multibyte-p) | 312 (set-buffer-multibyte multibyte-p) |
321 (let ((formatter (format "%%%ds:" max-width))) | 313 (let ((formatter (format "%%%ds:" max-width))) |
322 (dolist (elt item-list) | 314 (dolist (elt item-list) |
323 (insert (format formatter (car elt))) | 315 (insert (format formatter (car elt))) |
324 (dolist (clm (cdr elt)) | 316 (dolist (clm (cdr elt)) |
329 (insert "\n") | 321 (insert "\n") |
330 (indent-to (1+ max-width))) | 322 (indent-to (1+ max-width))) |
331 (insert " " clm)) | 323 (insert " " clm)) |
332 (insert "\n"))) | 324 (insert "\n"))) |
333 (when composition | 325 (when composition |
334 (insert "\nComposed with the following character(s) " | 326 (insert "\nComposed with the " |
335 (mapconcat (lambda (x) (format "`%c'" x)) | 327 (cond |
336 (substring composed 1) | 328 ((eq pos (car composition)) "following ") |
337 ", ") | 329 ((eq (1+ pos) (cadr composition)) "preceding ") |
338 " to form `" composed "'") | 330 (t "")) |
331 "character(s) `" | |
332 (cond | |
333 ((eq pos (car composition)) (substring composed 1)) | |
334 ((eq (1+ pos) (cadr composition)) (substring composed 0 -1)) | |
335 (t (concat (substring composed 0 (- pos (car composition))) | |
336 "' and `" | |
337 (substring composed (- (1+ pos) (car composition)))))) | |
338 | |
339 "' to form `" composed "'") | |
339 (if (nth 3 composition) | 340 (if (nth 3 composition) |
340 (insert ".\n") | 341 (insert ".\n") |
341 (insert "\nby the rule (" | 342 (insert "\nby the rule (" |
342 (mapconcat (lambda (x) | 343 (mapconcat (lambda (x) |
343 (format (if (consp x) "%S" "?%c") x)) | 344 (format (if (consp x) "%S" "?%c") x)) |