summaryrefslogtreecommitdiff
path: root/lisp/startup.el
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-09-09 02:21:16 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2015-09-09 02:22:24 -0700
commit6e5d81ff4536ed117dfac269357c46dbdc1890c9 (patch)
treece637dad553f16c3dab02720bee505c938416beb /lisp/startup.el
parent39dca94701de81d02c75316e32d67e3677bd685d (diff)
downloademacs-6e5d81ff4536ed117dfac269357c46dbdc1890c9.tar.gz
Improvements for curved quotes on Linux consule
This should help Emacs work better out-of-the-box on Linux consoles, which have only limited support for displaying Unicode characters. Also, undo the recent change that caused text-quoting-style to affect quote display on terminals, so that the two features are independent. See Alan Mackenzie in: http://lists.gnu.org/archive/html/emacs-devel/2015-09/msg00244.html Finally, add a style parameter to startup--setup-quote-display, so that this function can also be invoked after startup, with different styles depending on user preference at the time. * configure.ac: Check for linux/kd.h header. * doc/emacs/display.texi (Text Display): Document quote display. * doc/lispref/display.texi (Active Display Table): * etc/NEWS: * lisp/startup.el (startup--setup-quote-display, command-line): text-quoting-style no longer affects quote display. * doc/lispref/frames.texi (Terminal Parameters): Fix typo. * lisp/international/mule-util.el (char-displayable-p): * lisp/startup.el (startup--setup-quote-display): On a text terminal supporting glyph codes, use the reported glyph codes instead of the terminal coding system, as this is more accurate on the Linux console. * lisp/startup.el (startup--setup-quote-display): New optional arg STYLE. * src/fontset.c (Finternal_char_font): Report glyph codes for a text terminal, if they are available. Currently this is supported only for the Linux console. * src/termhooks.h (struct terminal): New member glyph-code-table. * src/terminal.c [HAVE_LINUX_KD_H]: Include <errno.h>, <linux/kd.h>. (calculate_glyph_code_table) [HAVE_LINUX_KD_H]: New function. (terminal_glyph_code): New function.
Diffstat (limited to 'lisp/startup.el')
-rw-r--r--lisp/startup.el73
1 files changed, 55 insertions, 18 deletions
diff --git a/lisp/startup.el b/lisp/startup.el
index 9caf485c1e8..971841fc0db 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -803,19 +803,61 @@ to prepare for opening the first frame (e.g. open a connection to an X server)."
(defvar server-name)
(defvar server-process)
-(defun startup--setup-quote-display ()
- "Display ASCII approximations on user request or if curved quotes don't work."
- (when (memq text-quoting-style '(nil grave straight))
- (dolist (char-repl '((?‘ . ?\`) (?’ . ?\') (?“ . ?\") (?” . ?\")))
- (let ((char (car char-repl))
- (repl (cdr char-repl)))
- (when (or text-quoting-style (not (char-displayable-p char)))
- (when (and (eq repl ?\`) (eq text-quoting-style 'straight))
- (setq repl ?\'))
- (unless standard-display-table
- (setq standard-display-table (make-display-table)))
- (aset standard-display-table char
- (vector (make-glyph-code repl 'shadow))))))))
+(defun startup--setup-quote-display (&optional style)
+ "If needed, display ASCII approximations to curved quotes.
+Do this by modifying `standard-display-table'. Optional STYLE
+specifies the desired quoting style, as in `text-quoting-style'.
+If STYLE is nil, display appropriately for the terminal."
+ (let ((repls (let ((style-repls (assq style '((grave . "`'\"\"")
+ (straight . "''\"\"")))))
+ (if style-repls (cdr style-repls) (make-vector 4 nil))))
+ glyph-count)
+ ;; REPLS is a sequence of the four replacements for "‘’“”", respectively.
+ ;; If STYLE is nil, infer REPLS from terminal characteristics.
+ (unless style
+ ;; On a terminal that supports glyph codes,
+ ;; GLYPH-COUNT[i] is the number of times that glyph code I
+ ;; represents either an ASCII character or one of the 4
+ ;; quote characters. This assumes glyph codes are valid
+ ;; Elisp characters, which is a safe assumption in practice.
+ (when (integerp (internal-char-font nil (max-char)))
+ (setq glyph-count (make-char-table nil 0))
+ (dotimes (i 132)
+ (let ((glyph (internal-char-font
+ nil (if (< i 128) i (aref "‘’“”" (- i 128))))))
+ (when (<= 0 glyph)
+ (aset glyph-count glyph (1+ (aref glyph-count glyph)))))))
+ (dotimes (i 2)
+ (let ((lq (aref "‘“" i)) (rq (aref "’”" i))
+ (lr (aref "`\"" i)) (rr (aref "'\"" i))
+ (i2 (* i 2)))
+ (unless (if glyph-count
+ ;; On a terminal that supports glyph codes, use
+ ;; ASCII replacements unless both quotes are displayable.
+ ;; If not using ASCII replacements, highlight
+ ;; quotes unless they are both unique among the
+ ;; 128 + 4 characters of concern.
+ (let ((lglyph (internal-char-font nil lq))
+ (rglyph (internal-char-font nil rq)))
+ (when (and (<= 0 lglyph) (<= 0 rglyph))
+ (setq lr lq rr rq)
+ (and (= 1 (aref glyph-count lglyph))
+ (= 1 (aref glyph-count rglyph)))))
+ ;; On a terminal that does not support glyph codes, use
+ ;; ASCII replacements unless both quotes are displayable.
+ (and (char-displayable-p lq)
+ (char-displayable-p rq)))
+ (aset repls i2 lr)
+ (aset repls (1+ i2) rr)))))
+ (dotimes (i 4)
+ (let ((char (aref "‘’“”" i))
+ (repl (aref repls i)))
+ (if repl
+ (aset (or standard-display-table
+ (setq standard-display-table (make-display-table)))
+ char (vector (make-glyph-code repl 'escape-glyph)))
+ (when standard-display-table
+ (aset standard-display-table char nil)))))))
(defun command-line ()
"A subroutine of `normal-top-level'.
@@ -1239,11 +1281,6 @@ the `--debug-init' option to view a complete error backtrace."
;; unibyte (display table, terminal coding system &c).
(set-language-environment current-language-environment)))
- ;; Setup quote display again, if the init file sets
- ;; text-quoting-style to a non-nil value.
- (when (and (not noninteractive) text-quoting-style)
- (startup--setup-quote-display))
-
;; Do this here in case the init file sets mail-host-address.
(if (equal user-mail-address "")
(setq user-mail-address (or (getenv "EMAIL")