comparison lisp/emacs-lisp/lisp-mode.el @ 56840:14c8ead25d14

(prin1-char): Don't turn S-a into A. Don't return a string that would read as the wrong character code.
author Richard M. Stallman <rms@gnu.org>
date Mon, 30 Aug 2004 16:05:38 +0000
parents ff83c10bdcf0
children 5418c6e288fc 3219f94257bc
comparison
equal deleted inserted replaced
56839:8425c441196c 56840:14c8ead25d14
458 "Return a string representing CHAR as a character rather than as an integer. 458 "Return a string representing CHAR as a character rather than as an integer.
459 If CHAR is not a character, return nil." 459 If CHAR is not a character, return nil."
460 (and (integerp char) 460 (and (integerp char)
461 (eventp char) 461 (eventp char)
462 (let ((c (event-basic-type char)) 462 (let ((c (event-basic-type char))
463 (mods (event-modifiers char))) 463 (mods (event-modifiers char))
464 string)
464 ;; Prevent ?A from turning into ?\S-a. 465 ;; Prevent ?A from turning into ?\S-a.
465 (if (and (memq 'shift mods) 466 (if (and (memq 'shift mods)
467 (zerop (logand char ?\S-\^@))
466 (not (let ((case-fold-search nil)) 468 (not (let ((case-fold-search nil))
467 (char-equal c (upcase c))))) 469 (char-equal c (upcase c)))))
468 (setq c (upcase c) mods nil)) 470 (setq c (upcase c) mods nil))
469 (concat 471 ;; What string are we considering using?
470 "?" 472 (condition-case nil
471 (mapconcat 473 (setq string
472 (lambda (modif) 474 (concat
473 (cond ((eq modif 'super) "\\s-") 475 "?"
474 (t (string ?\\ (upcase (aref (symbol-name modif) 0)) ?-)))) 476 (mapconcat
475 mods "") 477 (lambda (modif)
476 (cond 478 (cond ((eq modif 'super) "\\s-")
477 ((memq c '(?\; ?\( ?\) ?\{ ?\} ?\[ ?\] ?\" ?\' ?\\)) (string ?\\ c)) 479 (t (string ?\\ (upcase (aref (symbol-name modif) 0)) ?-))))
478 ((eq c 127) "\\C-?") 480 mods "")
479 (t 481 (cond
480 (condition-case nil 482 ((memq c '(?\; ?\( ?\) ?\{ ?\} ?\[ ?\] ?\" ?\' ?\\)) (string ?\\ c))
481 (string c) 483 ((eq c 127) "\\C-?")
482 (error nil)))))))) 484 (t
485 (string c)))))
486 (error nil))
487 ;; Verify the string reads a CHAR, not to some other character.
488 ;; If it doesn't, return nil instead.
489 (and string
490 (= (car (read-from-string string)) char)
491 string))))
492
483 493
484 (defun eval-last-sexp-1 (eval-last-sexp-arg-internal) 494 (defun eval-last-sexp-1 (eval-last-sexp-arg-internal)
485 "Evaluate sexp before point; print value in minibuffer. 495 "Evaluate sexp before point; print value in minibuffer.
486 With argument, print output into current buffer." 496 With argument, print output into current buffer."
487 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t))) 497 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t)))