From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Matthew Leach Newsgroups: gmane.emacs.devel Subject: RFC Patch: add tty face attributes Date: Sun, 02 Nov 2014 00:30:39 +0000 Message-ID: <878ujuzbo0.fsf@loki.home> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1414899192 20232 80.91.229.3 (2 Nov 2014 03:33:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Nov 2014 03:33:12 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Nov 02 04:33:05 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XkluX-0006b0-HN for ged-emacs-devel@m.gmane.org; Sun, 02 Nov 2014 04:33:01 +0100 Original-Received: from localhost ([::1]:54808 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XkluX-0003mR-4d for ged-emacs-devel@m.gmane.org; Sat, 01 Nov 2014 23:33:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xkj4G-0001gv-Gk for emacs-devel@gnu.org; Sat, 01 Nov 2014 20:30:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xkj4A-0008Mw-7u for emacs-devel@gnu.org; Sat, 01 Nov 2014 20:30:52 -0400 Original-Received: from mx0.mattleach.net ([176.58.118.143]:40039) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xkj49-0008Ms-Uj for emacs-devel@gnu.org; Sat, 01 Nov 2014 20:30:46 -0400 Original-Received: by mx0.mattleach.net (Postfix, from userid 99) id 37DE42BB3C5; Sun, 2 Nov 2014 00:30:45 +0000 (GMT) Original-Received: from loki.home.mattleach.net (host86-171-121-249.range86-171.btcentralplus.com [86.171.121.249]) by mx0.mattleach.net (Postfix) with ESMTPSA id 2D4402BB3C4 for ; Sun, 2 Nov 2014 00:30:40 +0000 (GMT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 176.58.118.143 X-Mailman-Approved-At: Sat, 01 Nov 2014 23:32:58 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:176228 Archived-At: --=-=-= Content-Type: text/plain Hello, Please see the attached patch that allows one to define a different face to be shown when being displayed on the tty rather than with a windowing system. Some background: I use hl-sexp-mode when editing lisp code and I frequently edit through ssh as well as on the console; naturally I use the Emacs daemon to achieve this. However, the color schemes that I use on the tty and the windowing system are quite different and I find myself flip-flopping between colors for the background face of hl-sexp-face as it is unreadable when switching to a tty editing session form the windowing-system session. To overcome this I decided it would be a good idea to create a second set of 'tty' face attributes that, when defined, overwrite the windowing system colors but only when displayed on a tty. Any comments are welcome. Thanks, -- Matt --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-add-tty-face-attributes.patch >From b5a3e0022074c42e31c5f08a687506ddf3d8ba4a Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Sun, 2 Nov 2014 00:04:07 +0000 Subject: [PATCH] add tty face attributes. src/ChangeLog: 2014-11-02 Matthew Leach * xfaces.c: New Lisp Objects QCtty_foreground and QCtty_background. (LFACE_TTY_FOREGROUND): New. (LFACE_TTY_BACKGROUND): New. (Finternal_set_lisp_face_attribute): Add setter code for tty_background and tty_foreground lisp faces. (Finternal_get_lisp_face_attribute): Add getter code for tty_background and tty_foreground lisp faces. (map_tty_color): Make the tty faces take precedent if not Qundefined. (syms_of_xfaces): Define symbols for tty_foreground and tty_background. * dispextern.h (lface_attribute_index): Add LFACE_TTY_FOREGROUND_INDEX and LFACE_TTY_BACKGROUND_INDEX. lisp/ChangeLog: 2014-11-02 Matthew Leach * faces.el (set-face-tty-background): New. (set-face-tty-foreground): New. (face-valid-attribute-values): Add tty_foreground and tty_background. (face-attribute-name-alist): Add descriptive names for tty_foreground and tty_background. --- lisp/faces.el | 21 ++++++++++++++++++++- src/dispextern.h | 2 ++ src/xfaces.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/lisp/faces.el b/lisp/faces.el index d7b330e..5a225e6 100644 --- a/lisp/faces.el +++ b/lisp/faces.el @@ -845,6 +845,15 @@ When called interactively, prompts for the face and color." (interactive (read-face-and-attribute :background)) (set-face-attribute face frame :background (or color 'unspecified))) +(defun set-face-tty-background (face color &optional frame) + "Change the tty background color of face FACE to COLOR (a string). +FRAME nil or not specified means change face on all frames. +COLOR can be a system-defined color name (see +`list-colors-display') or a hex spec of the form #RRGGBB. When +called interactively, prompts for the face and color." + (interactive (read-face-and-attribute :tty_background)) + (set-face-attribute face frame :tty_background (or color 'unspecified))) + (defun set-face-foreground (face color &optional frame) "Change the foreground color of face FACE to COLOR (a string). @@ -855,6 +864,14 @@ When called interactively, prompts for the face and color." (interactive (read-face-and-attribute :foreground)) (set-face-attribute face frame :foreground (or color 'unspecified))) +(defun set-face-tty-foreground (face color &optional frame) + "Change the tty foreground color of face FACE to COLOR (a string). +FRAME nil or not specified means change face on all frames. +COLOR can be a system-defined color name (see +`list-colors-display') or a hex spec of the form #RRGGBB. When +called interactively, prompts for the face and color." + (interactive (read-face-and-attribute :tty_foreground)) + (set-face-attribute face frame :tty_foreground (or color 'unspecified))) (defun set-face-stipple (face stipple &optional frame) "Change the stipple pixmap of face FACE to STIPPLE. @@ -1052,7 +1069,7 @@ an integer value." (defined-colors frame))) (mapcar #'(lambda (x) (cons (symbol-name x) x)) (internal-lisp-face-attribute-values attribute)))) - ((or `:foreground `:background) + ((or `:foreground `:background `:tty_foreground `:tty_background) (mapcar #'(lambda (c) (cons c c)) (defined-colors frame))) (`:height @@ -1091,6 +1108,8 @@ an integer value." (:inverse-video . "inverse-video display") (:foreground . "foreground color") (:background . "background color") + (:tty_foreground . "tty foreground color") + (:tty_background . "tty background color") (:stipple . "background stipple") (:inherit . "inheritance")) "An alist of descriptive names for face attributes. diff --git a/src/dispextern.h b/src/dispextern.h index 0dd0887..c5d8e4c 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -1550,6 +1550,8 @@ enum lface_attribute_index LFACE_INVERSE_INDEX, LFACE_FOREGROUND_INDEX, LFACE_BACKGROUND_INDEX, + LFACE_TTY_FOREGROUND_INDEX, + LFACE_TTY_BACKGROUND_INDEX, LFACE_STIPPLE_INDEX, LFACE_OVERLINE_INDEX, LFACE_STRIKE_THROUGH_INDEX, diff --git a/src/xfaces.c b/src/xfaces.c index 446107e..9366fc1 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -284,6 +284,7 @@ Lisp_Object QCfamily, QCheight, QCweight, QCslant; static Lisp_Object QCunderline; static Lisp_Object QCinverse_video, QCstipple; Lisp_Object QCforeground, QCbackground; +Lisp_Object QCtty_foreground, QCtty_background; Lisp_Object QCwidth; static Lisp_Object QCfont, QCbold, QCitalic; static Lisp_Object QCreverse_video; @@ -1720,6 +1721,8 @@ the WIDTH times as wide as FACE on FRAME. */) #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX) #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX) #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX) +#define LFACE_TTY_FOREGROUND(LFACE) AREF ((LFACE), LFACE_TTY_FOREGROUND_INDEX) +#define LFACE_TTY_BACKGROUND(LFACE) AREF ((LFACE), LFACE_TTY_BACKGROUND_INDEX) #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX) #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX) #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX) @@ -3059,6 +3062,40 @@ FRAME 0 means change the face on all frames, and change the default old_value = LFACE_BACKGROUND (lface); ASET (lface, LFACE_BACKGROUND_INDEX, value); } + else if (EQ (attr, QCtty_foreground)) + { + /* Compatibility with 20.x. */ + if (NILP (value)) + value = Qunspecified; + if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value)) + { + /* Don't check for valid color names here because it depends + on the frame (display) whether the color will be valid + when the face is realized. */ + CHECK_STRING (value); + if (SCHARS (value) == 0) + signal_error ("Empty foreground tty color value", value); + } + old_value = LFACE_TTY_FOREGROUND (lface); + ASET (lface, LFACE_TTY_FOREGROUND_INDEX, value); + } + else if (EQ (attr, QCtty_background)) + { + /* Compatibility with 20.x. */ + if (NILP (value)) + value = Qunspecified; + if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value)) + { + /* Don't check for valid color names here because it depends + on the frame (display) whether the color will be valid + when the face is realized. */ + CHECK_STRING (value); + if (SCHARS (value) == 0) + signal_error ("Empty background terminal color value", value); + } + old_value = LFACE_TTY_BACKGROUND (lface); + ASET (lface, LFACE_TTY_BACKGROUND_INDEX, value); + } else if (EQ (attr, QCstipple)) { #if defined (HAVE_WINDOW_SYSTEM) @@ -3700,6 +3737,10 @@ frames). If FRAME is omitted or nil, use the selected frame. */) value = LFACE_DISTANT_FOREGROUND (lface); else if (EQ (keyword, QCbackground)) value = LFACE_BACKGROUND (lface); + else if (EQ (keyword, QCtty_foreground)) + value = LFACE_TTY_FOREGROUND (lface); + else if (EQ (keyword, QCtty_background)) + value = LFACE_TTY_BACKGROUND (lface); else if (EQ (keyword, QCstipple)) value = LFACE_STIPPLE (lface); else if (EQ (keyword, QCwidth)) @@ -5784,6 +5825,14 @@ map_tty_color (struct frame *f, struct face *face, eassert (idx == LFACE_FOREGROUND_INDEX || idx == LFACE_BACKGROUND_INDEX); + /* Check whether tty colors take precedence. */ + if (foreground_p && + !UNSPECIFIEDP (face->lface[LFACE_TTY_FOREGROUND_INDEX])) + idx = LFACE_TTY_FOREGROUND_INDEX; + else if (!foreground_p && + !UNSPECIFIEDP (face->lface[LFACE_TTY_BACKGROUND_INDEX])) + idx = LFACE_TTY_BACKGROUND_INDEX; + XSETFRAME (frame, f); color = face->lface[idx]; @@ -6412,6 +6461,8 @@ syms_of_xfaces (void) DEFSYM (QCreverse_video, ":reverse-video"); DEFSYM (QCforeground, ":foreground"); DEFSYM (QCbackground, ":background"); + DEFSYM (QCtty_foreground, ":tty_foreground"); + DEFSYM (QCtty_background, ":tty_background"); DEFSYM (QCstipple, ":stipple"); DEFSYM (QCwidth, ":width"); DEFSYM (QCfont, ":font"); -- 2.1.3 --=-=-=--