diff options
| author | Paul Eggert | 2015-09-09 02:21:16 -0700 |
|---|---|---|
| committer | Paul Eggert | 2015-09-09 02:22:24 -0700 |
| commit | 6e5d81ff4536ed117dfac269357c46dbdc1890c9 (patch) | |
| tree | ce637dad553f16c3dab02720bee505c938416beb /lisp | |
| parent | 39dca94701de81d02c75316e32d67e3677bd685d (diff) | |
| download | emacs-6e5d81ff4536ed117dfac269357c46dbdc1890c9.tar.gz emacs-6e5d81ff4536ed117dfac269357c46dbdc1890c9.zip | |
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')
| -rw-r--r-- | lisp/international/mule-util.el | 77 | ||||
| -rw-r--r-- | lisp/startup.el | 73 |
2 files changed, 96 insertions, 54 deletions
diff --git a/lisp/international/mule-util.el b/lisp/international/mule-util.el index f3aa70fd66c..90258636464 100644 --- a/lisp/international/mule-util.el +++ b/lisp/international/mule-util.el | |||
| @@ -273,43 +273,48 @@ per-character basis, this may not be accurate." | |||
| 273 | ((not enable-multibyte-characters) | 273 | ((not enable-multibyte-characters) |
| 274 | ;; Maybe there's a font for it, but we can't put it in the buffer. | 274 | ;; Maybe there's a font for it, but we can't put it in the buffer. |
| 275 | nil) | 275 | nil) |
| 276 | ((display-multi-font-p) | ||
| 277 | ;; On a window system, a character is displayable if we have | ||
| 278 | ;; a font for that character in the default face of the | ||
| 279 | ;; currently selected frame. | ||
| 280 | (car (internal-char-font nil char))) | ||
| 281 | (t | 276 | (t |
| 282 | ;; On a terminal, a character is displayable if the coding | 277 | (let ((font-glyph (internal-char-font nil char))) |
| 283 | ;; system for the terminal can encode it. | 278 | (if font-glyph |
| 284 | (let ((coding (terminal-coding-system))) | 279 | (if (consp font-glyph) |
| 285 | (when coding | 280 | ;; On a window system, a character is displayable |
| 286 | (let ((cs-list (coding-system-get coding :charset-list))) | 281 | ;; if a font for that character is in the default |
| 287 | (cond | 282 | ;; face of the currently selected frame. |
| 288 | ((listp cs-list) | 283 | (car font-glyph) |
| 289 | (catch 'tag | 284 | ;; On a text terminal supporting glyph codes, CHAR is |
| 290 | (mapc #'(lambda (charset) | 285 | ;; displayable if its glyph code is nonnegative. |
| 291 | (if (encode-char char charset) | 286 | (<= 0 font-glyph)) |
| 292 | (throw 'tag charset))) | 287 | ;; On a teext terminal without glyph codes, CHAR is displayable |
| 293 | cs-list) | 288 | ;; if the coding system for the terminal can encode it. |
| 294 | nil)) | 289 | (let ((coding (terminal-coding-system))) |
| 295 | ((eq cs-list 'iso-2022) | 290 | (when coding |
| 296 | (catch 'tag2 | 291 | (let ((cs-list (coding-system-get coding :charset-list))) |
| 297 | (mapc #'(lambda (charset) | 292 | (cond |
| 298 | (if (and (plist-get (charset-plist charset) | 293 | ((listp cs-list) |
| 299 | :iso-final-char) | 294 | (catch 'tag |
| 300 | (encode-char char charset)) | 295 | (mapc #'(lambda (charset) |
| 301 | (throw 'tag2 charset))) | 296 | (if (encode-char char charset) |
| 302 | charset-list) | 297 | (throw 'tag charset))) |
| 303 | nil)) | 298 | cs-list) |
| 304 | ((eq cs-list 'emacs-mule) | 299 | nil)) |
| 305 | (catch 'tag3 | 300 | ((eq cs-list 'iso-2022) |
| 306 | (mapc #'(lambda (charset) | 301 | (catch 'tag2 |
| 307 | (if (and (plist-get (charset-plist charset) | 302 | (mapc #'(lambda (charset) |
| 308 | :emacs-mule-id) | 303 | (if (and (plist-get (charset-plist charset) |
| 309 | (encode-char char charset)) | 304 | :iso-final-char) |
| 310 | (throw 'tag3 charset))) | 305 | (encode-char char charset)) |
| 311 | charset-list) | 306 | (throw 'tag2 charset))) |
| 312 | nil))))))))) | 307 | charset-list) |
| 308 | nil)) | ||
| 309 | ((eq cs-list 'emacs-mule) | ||
| 310 | (catch 'tag3 | ||
| 311 | (mapc #'(lambda (charset) | ||
| 312 | (if (and (plist-get (charset-plist charset) | ||
| 313 | :emacs-mule-id) | ||
| 314 | (encode-char char charset)) | ||
| 315 | (throw 'tag3 charset))) | ||
| 316 | charset-list) | ||
| 317 | nil))))))))))) | ||
| 313 | 318 | ||
| 314 | (defun filepos-to-bufferpos--dos (byte f) | 319 | (defun filepos-to-bufferpos--dos (byte f) |
| 315 | (let ((eol-offset 0) | 320 | (let ((eol-offset 0) |
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)." | |||
| 803 | (defvar server-name) | 803 | (defvar server-name) |
| 804 | (defvar server-process) | 804 | (defvar server-process) |
| 805 | 805 | ||
| 806 | (defun startup--setup-quote-display () | 806 | (defun startup--setup-quote-display (&optional style) |
| 807 | "Display ASCII approximations on user request or if curved quotes don't work." | 807 | "If needed, display ASCII approximations to curved quotes. |
| 808 | (when (memq text-quoting-style '(nil grave straight)) | 808 | Do this by modifying `standard-display-table'. Optional STYLE |
| 809 | (dolist (char-repl '((?‘ . ?\`) (?’ . ?\') (?“ . ?\") (?” . ?\"))) | 809 | specifies the desired quoting style, as in `text-quoting-style'. |
| 810 | (let ((char (car char-repl)) | 810 | If STYLE is nil, display appropriately for the terminal." |
| 811 | (repl (cdr char-repl))) | 811 | (let ((repls (let ((style-repls (assq style '((grave . "`'\"\"") |
| 812 | (when (or text-quoting-style (not (char-displayable-p char))) | 812 | (straight . "''\"\""))))) |
| 813 | (when (and (eq repl ?\`) (eq text-quoting-style 'straight)) | 813 | (if style-repls (cdr style-repls) (make-vector 4 nil)))) |
| 814 | (setq repl ?\')) | 814 | glyph-count) |
| 815 | (unless standard-display-table | 815 | ;; REPLS is a sequence of the four replacements for "‘’“”", respectively. |
| 816 | (setq standard-display-table (make-display-table))) | 816 | ;; If STYLE is nil, infer REPLS from terminal characteristics. |
| 817 | (aset standard-display-table char | 817 | (unless style |
| 818 | (vector (make-glyph-code repl 'shadow)))))))) | 818 | ;; On a terminal that supports glyph codes, |
| 819 | ;; GLYPH-COUNT[i] is the number of times that glyph code I | ||
| 820 | ;; represents either an ASCII character or one of the 4 | ||
| 821 | ;; quote characters. This assumes glyph codes are valid | ||
| 822 | ;; Elisp characters, which is a safe assumption in practice. | ||
| 823 | (when (integerp (internal-char-font nil (max-char))) | ||
| 824 | (setq glyph-count (make-char-table nil 0)) | ||
| 825 | (dotimes (i 132) | ||
| 826 | (let ((glyph (internal-char-font | ||
| 827 | nil (if (< i 128) i (aref "‘’“”" (- i 128)))))) | ||
| 828 | (when (<= 0 glyph) | ||
| 829 | (aset glyph-count glyph (1+ (aref glyph-count glyph))))))) | ||
| 830 | (dotimes (i 2) | ||
| 831 | (let ((lq (aref "‘“" i)) (rq (aref "’”" i)) | ||
| 832 | (lr (aref "`\"" i)) (rr (aref "'\"" i)) | ||
| 833 | (i2 (* i 2))) | ||
| 834 | (unless (if glyph-count | ||
| 835 | ;; On a terminal that supports glyph codes, use | ||
| 836 | ;; ASCII replacements unless both quotes are displayable. | ||
| 837 | ;; If not using ASCII replacements, highlight | ||
| 838 | ;; quotes unless they are both unique among the | ||
| 839 | ;; 128 + 4 characters of concern. | ||
| 840 | (let ((lglyph (internal-char-font nil lq)) | ||
| 841 | (rglyph (internal-char-font nil rq))) | ||
| 842 | (when (and (<= 0 lglyph) (<= 0 rglyph)) | ||
| 843 | (setq lr lq rr rq) | ||
| 844 | (and (= 1 (aref glyph-count lglyph)) | ||
| 845 | (= 1 (aref glyph-count rglyph))))) | ||
| 846 | ;; On a terminal that does not support glyph codes, use | ||
| 847 | ;; ASCII replacements unless both quotes are displayable. | ||
| 848 | (and (char-displayable-p lq) | ||
| 849 | (char-displayable-p rq))) | ||
| 850 | (aset repls i2 lr) | ||
| 851 | (aset repls (1+ i2) rr))))) | ||
| 852 | (dotimes (i 4) | ||
| 853 | (let ((char (aref "‘’“”" i)) | ||
| 854 | (repl (aref repls i))) | ||
| 855 | (if repl | ||
| 856 | (aset (or standard-display-table | ||
| 857 | (setq standard-display-table (make-display-table))) | ||
| 858 | char (vector (make-glyph-code repl 'escape-glyph))) | ||
| 859 | (when standard-display-table | ||
| 860 | (aset standard-display-table char nil))))))) | ||
| 819 | 861 | ||
| 820 | (defun command-line () | 862 | (defun command-line () |
| 821 | "A subroutine of `normal-top-level'. | 863 | "A subroutine of `normal-top-level'. |
| @@ -1239,11 +1281,6 @@ the `--debug-init' option to view a complete error backtrace." | |||
| 1239 | ;; unibyte (display table, terminal coding system &c). | 1281 | ;; unibyte (display table, terminal coding system &c). |
| 1240 | (set-language-environment current-language-environment))) | 1282 | (set-language-environment current-language-environment))) |
| 1241 | 1283 | ||
| 1242 | ;; Setup quote display again, if the init file sets | ||
| 1243 | ;; text-quoting-style to a non-nil value. | ||
| 1244 | (when (and (not noninteractive) text-quoting-style) | ||
| 1245 | (startup--setup-quote-display)) | ||
| 1246 | |||
| 1247 | ;; Do this here in case the init file sets mail-host-address. | 1284 | ;; Do this here in case the init file sets mail-host-address. |
| 1248 | (if (equal user-mail-address "") | 1285 | (if (equal user-mail-address "") |
| 1249 | (setq user-mail-address (or (getenv "EMAIL") | 1286 | (setq user-mail-address (or (getenv "EMAIL") |