From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: Re: using glyphs by default in perl-mode Date: Tue, 04 Jun 2013 16:06:05 -0400 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87ppw13aky.fsf@lifelogs.com> References: <83li7ocdkb.fsf@gnu.org> <87d2sp92vb.fsf@lifelogs.com> <87bo877kf7.fsf@lifelogs.com> <87obbs7cew.fsf@lifelogs.com> <87ip1y54fx.fsf@lifelogs.com> <87ehck6670.fsf@lifelogs.com> <87a9n854tx.fsf@lifelogs.com> <8761xw54rv.fsf@lifelogs.com> <87sj0y4p7h.fsf@lifelogs.com> Reply-To: emacs-devel@gnu.org NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1370376394 30540 80.91.229.3 (4 Jun 2013 20:06:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 4 Jun 2013 20:06:34 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 04 22:06:35 2013 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 1UjxV4-0006VM-K1 for ged-emacs-devel@m.gmane.org; Tue, 04 Jun 2013 22:06:34 +0200 Original-Received: from localhost ([::1]:45889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjxV4-0001x3-4S for ged-emacs-devel@m.gmane.org; Tue, 04 Jun 2013 16:06:34 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjxUt-0001wG-2w for emacs-devel@gnu.org; Tue, 04 Jun 2013 16:06:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UjxUm-0007vL-FH for emacs-devel@gnu.org; Tue, 04 Jun 2013 16:06:23 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:46031) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjxUm-0007un-13 for emacs-devel@gnu.org; Tue, 04 Jun 2013 16:06:16 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UjxUk-0006Dh-7R for emacs-devel@gnu.org; Tue, 04 Jun 2013 22:06:14 +0200 Original-Received: from pool-72-93-26-80.bstnma.east.verizon.net ([72.93.26.80]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 04 Jun 2013 22:06:14 +0200 Original-Received: from tzz by pool-72-93-26-80.bstnma.east.verizon.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 04 Jun 2013 22:06:14 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Lines: 429 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: pool-72-93-26-80.bstnma.east.verizon.net X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Mail-Copies-To: never User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:jnHHeRJKY3NvistSzgqnnEODu4A= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:160083 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On Tue, 04 Jun 2013 13:20:28 -0400 Stefan Monnier wrote: >> It's easy to do this once you start doing it but it still feels like >> an annoying amount of work. SM> We definitely need to add some helper functions to make it easier. SM> The major modes should really only need to do SM> (setq-local prog-prettify-symbols-alist ) SM> and then SM> (prog-prettify-setup-font-lock) SM> but we'll figure that out later. OK :) >> I couldn't move the code to prog-mode.el. SM> Fine. >> The emacs-lisp-mode include needs the prog-mode map and barfed all >> over. Sorry. But it should be OK otherwise. SM> prog-mode.el needs to be preloaded (i.e. added to loadup.el), indeed. See attached patch. It only fixes comments and attempts to move to prog-mode.el. Maybe you'll know the way to fix it. I get: Attempt to autoload define-derived-mode while preparing to dump If it's trivial to fix, please let me know how. If not, I'll commit as simple.el and update the ChangeLog. >> +;; used to add font-lock keywords dynamically SM> Please capitalize and punctuate your comments. Done. >> +(defconst lisp--prettify-symbols-alist >> + `(("lambda" . ,(make-char 'greek-iso8859-7 107)))) SM> We'd probably want to refine it so it's only prettified when it comes SM> right after a parenthesis, but it's OK for now. OTOH using make-char SM> here is a bad idea: better just put the Unicode char in there (this SM> make-char seems to be copied from old pre-Unicode code) either as ?λ SM> or as ?\u03BB. Done. >> + ("bundle agent" . ?⊕) >> + ("bundle server" . ?∑) >> + ("body" . ?⊙) >> + ("bundle" . ?𝛽))) SM> Interesting! That's exactly what the CFEngine guys said :) Reverted to just arrows and :: prettification, although I may add more to reflect the Promise Theory notation Mark Burgess uses. On Tue, 04 Jun 2013 08:28:42 -0600 Davis Herring wrote: >> +When set to `basic' or `extended' or `all', the actual choices >> +are made by the mode that derives from `prog-mode'." DH> This was missed in the conversion to boolean. Thanks, nice catch. Fixed. Ted --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=prog-prettify5.patch Content-Transfer-Encoding: 8bit === modified file 'lisp/emacs-lisp/lisp-mode.el' --- lisp/emacs-lisp/lisp-mode.el 2013-05-29 14:14:16 +0000 +++ lisp/emacs-lisp/lisp-mode.el 2013-06-04 19:53:24 +0000 @@ -187,6 +187,11 @@ font-lock-string-face)))) font-lock-comment-face)) +;; Temporary variables used to add font-lock keywords dynamically. +(defvar lisp--augmented-font-lock-keywords) +(defvar lisp--augmented-font-lock-keywords-1) +(defvar lisp--augmented-font-lock-keywords-2) + (defun lisp-mode-variables (&optional lisp-syntax keywords-case-insensitive) "Common initialization routine for lisp modes. The LISP-SYNTAX argument is used by code in inf-lisp.el and is @@ -223,9 +228,20 @@ (setq-local imenu-generic-expression lisp-imenu-generic-expression) (setq-local multibyte-syntax-as-symbol t) (setq-local syntax-begin-function 'beginning-of-defun) + (setq-local prog-prettify-symbols-alist lisp--prettify-symbols-alist) + (setq lisp--augmented-font-lock-keywords + (append lisp-font-lock-keywords + (prog-prettify-font-lock-symbols-keywords))) + (setq lisp--augmented-font-lock-keywords-1 + (append lisp-font-lock-keywords-1 + (prog-prettify-font-lock-symbols-keywords))) + (setq lisp--augmented-font-lock-keywords-2 + (append lisp-font-lock-keywords-2 + (prog-prettify-font-lock-symbols-keywords))) (setq font-lock-defaults - `((lisp-font-lock-keywords - lisp-font-lock-keywords-1 lisp-font-lock-keywords-2) + `((lisp--augmented-font-lock-keywords + lisp--augmented-font-lock-keywords-1 + lisp--augmented-font-lock-keywords-2) nil ,keywords-case-insensitive nil nil (font-lock-mark-block-function . mark-defun) (font-lock-syntactic-face-function @@ -448,6 +464,9 @@ :type 'hook :group 'lisp) +(defconst lisp--prettify-symbols-alist + '(("lambda" . ?λ))) + (define-derived-mode emacs-lisp-mode prog-mode "Emacs-Lisp" "Major mode for editing Lisp code to run in Emacs. Commands: === modified file 'lisp/loadup.el' --- lisp/loadup.el 2013-05-16 09:58:56 +0000 +++ lisp/loadup.el 2013-06-04 20:01:08 +0000 @@ -206,6 +206,7 @@ (load "rfn-eshadow") (load "menu-bar") +(load "prog-mode") (load "emacs-lisp/lisp") (load "textmodes/page") (load "register") === added file 'lisp/prog-mode.el' --- lisp/prog-mode.el 1970-01-01 00:00:00 +0000 +++ lisp/prog-mode.el 2013-06-04 19:57:53 +0000 @@ -0,0 +1,99 @@ +;;; prog-mode.el --- basic programming support for Emacs -*- lexical-binding: t -*- + +;; Copyright (C) 2013 Free Software Foundation, Inc. + +;; Maintainer: FSF +;; Keywords: internal,languages +;; Package: emacs + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;; Major mode meant to be the parent of programming modes. + +;;; Code: + +(defvar prog-mode-map + (let ((map (make-sparse-keymap))) + (define-key map [?\C-\M-q] 'prog-indent-sexp) + map) + "Keymap used for programming modes.") + +(defun prog-indent-sexp (&optional defun) + "Indent the expression after point. +When interactively called with prefix, indent the enclosing defun +instead." + (interactive "P") + (save-excursion + (when defun + (end-of-line) + (beginning-of-defun)) + (let ((start (point)) + (end (progn (forward-sexp 1) (point)))) + (indent-region start end nil)))) + +(define-derived-mode prog-mode fundamental-mode "Prog" + "Major mode for editing programming language source code." + (set (make-local-variable 'require-final-newline) mode-require-final-newline) + (set (make-local-variable 'parse-sexp-ignore-comments) t) + (make-local-variable 'prog-prettify-symbols-alist) + ;; Any programming language is always written left to right. + (setq bidi-paragraph-direction 'left-to-right)) + +(defvar prog-prettify-symbols-alist nil) + +(defcustom prog-prettify-symbols nil + "Whether symbols should be prettified. +When set to an alist in the form `(STRING . CHARACTER)' it will +augment the mode's native prettify alist." + :type '(choice + (const :tag "No thanks" nil) + (const :tag "Mode defaults" t) + (alist :tag "Mode defaults augmented with your own list" + :key-type string :value-type character)) + :group 'languages) + +(defun prog--prettify-font-lock-compose-symbol (alist) + "Compose a sequence of ascii chars into a symbol. +Regexp match data 0 points to the chars." + ;; Check that the chars should really be composed into a symbol. + (let* ((start (match-beginning 0)) + (end (match-end 0)) + (syntaxes (if (eq (char-syntax (char-after start)) ?w) + '(?w) '(?. ?\\)))) + (if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes) + (memq (char-syntax (or (char-after end) ?\ )) syntaxes) + (nth 8 (syntax-ppss))) + ;; No composition for you. Let's actually remove any composition + ;; we may have added earlier and which is now incorrect. + (remove-text-properties start end '(composition)) + ;; That's a symbol alright, so add the composition. + (compose-region start end (cdr (assoc (match-string 0) alist))))) + ;; Return nil because we're not adding any face property. + nil) + +(defun prog-prettify-font-lock-symbols-keywords () + (when prog-prettify-symbols + (let ((alist (append prog-prettify-symbols-alist + (if (listp prog-prettify-symbols) + prog-prettify-symbols + nil)))) + `((,(regexp-opt (mapcar 'car alist) t) + (0 (prog--prettify-font-lock-compose-symbol ',alist))))))) + +(provide 'prog-mode) +;;; prog-mode.el ends here === modified file 'lisp/progmodes/cfengine.el' --- lisp/progmodes/cfengine.el 2013-03-22 19:06:53 +0000 +++ lisp/progmodes/cfengine.el 2013-06-04 19:54:07 +0000 @@ -527,6 +527,13 @@ ;; Doze path separators. (modify-syntax-entry ?\\ "." table)) +(defconst cfengine3--prettify-symbols-alist + '(("->" . ?→) + ("=>" . ?⇒) + ("::" . ?∷))) + +(defvar cfengine3--augmented-font-lock-keywords) + ;;;###autoload (define-derived-mode cfengine3-mode prog-mode "CFE3" "Major mode for editing CFEngine3 input. @@ -538,8 +545,18 @@ (cfengine-common-syntax cfengine3-mode-syntax-table) (set (make-local-variable 'indent-line-function) #'cfengine3-indent-line) + + ;; Define the symbols to be prettified + (setq-local prog-prettify-symbols-alist cfengine3--prettify-symbols-alist) + + ;; Tell font-lock.el how to handle cfengine3 keywords.. + (setq cfengine3--augmented-font-lock-keywords + (append cfengine3-font-lock-keywords + (prog-prettify-font-lock-symbols-keywords))) + (setq font-lock-defaults - '(cfengine3-font-lock-keywords nil nil nil beginning-of-defun)) + '(cfengine3--augmented-font-lock-keywords + nil nil nil beginning-of-defun)) ;; Use defuns as the essential syntax block. (set (make-local-variable 'beginning-of-defun-function) === modified file 'lisp/progmodes/perl-mode.el' --- lisp/progmodes/perl-mode.el 2013-05-07 18:06:13 +0000 +++ lisp/progmodes/perl-mode.el 2013-06-04 19:54:45 +0000 @@ -158,44 +158,10 @@ ;; Regexps updated with help from Tom Tromey and ;; Jim Campbell . -(defcustom perl-prettify-symbols t - "If non-nil, some symbols will be displayed using Unicode chars." - :version "24.4" - :type 'boolean) - (defconst perl--prettify-symbols-alist - '(;;("andalso" . ?∧) ("orelse" . ?∨) ("as" . ?≡)("not" . ?¬) - ;;("div" . ?÷) ("*" . ?×) ("o" . ?○) - ("->" . ?→) + '(("->" . ?→) ("=>" . ?⇒) - ;;("<-" . ?←) ("<>" . ?≠) (">=" . ?≥) ("<=" . ?≤) ("..." . ?⋯) - ("::" . ?∷) - )) - -(defun perl--font-lock-compose-symbol () - "Compose a sequence of ascii chars into a symbol. -Regexp match data 0 points to the chars." - ;; Check that the chars should really be composed into a symbol. - (let* ((start (match-beginning 0)) - (end (match-end 0)) - (syntaxes (if (eq (char-syntax (char-after start)) ?w) - '(?w) '(?. ?\\)))) - (if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes) - (memq (char-syntax (or (char-after end) ?\ )) syntaxes) - (nth 8 (syntax-ppss))) - ;; No composition for you. Let's actually remove any composition - ;; we may have added earlier and which is now incorrect. - (remove-text-properties start end '(composition)) - ;; That's a symbol alright, so add the composition. - (compose-region start end (cdr (assoc (match-string 0) - perl--prettify-symbols-alist))))) - ;; Return nil because we're not adding any face property. - nil) - -(defun perl--font-lock-symbols-keywords () - (when perl-prettify-symbols - `((,(regexp-opt (mapcar 'car perl--prettify-symbols-alist) t) - (0 (perl--font-lock-compose-symbol)))))) + ("::" . ?∷))) (defconst perl-font-lock-keywords-1 '(;; What is this for? @@ -243,13 +209,17 @@ ;; Fontify keywords with/and labels as we do in `c++-font-lock-keywords'. ("\\<\\(continue\\|goto\\|last\\|next\\|redo\\)\\>[ \t]*\\(\\sw+\\)?" (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)) - ("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-constant-face) - ,@(perl--font-lock-symbols-keywords))) + ("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-constant-face))) "Gaudy level highlighting for Perl mode.") (defvar perl-font-lock-keywords perl-font-lock-keywords-1 "Default expressions to highlight in Perl mode.") +;; Temporary variables used to add font-lock keywords dynamically. +(defvar perl--augmented-font-lock-keywords) +(defvar perl--augmented-font-lock-keywords-1) +(defvar perl--augmented-font-lock-keywords-2) + (defvar perl-quote-like-pairs '((?\( . ?\)) (?\[ . ?\]) (?\{ . ?\}) (?\< . ?\>))) @@ -685,11 +655,25 @@ (setq-local comment-start-skip "\\(^\\|\\s-\\);?#+ *") (setq-local comment-indent-function #'perl-comment-indent) (setq-local parse-sexp-ignore-comments t) + + ;; Define the symbols to be prettified. + (setq-local prog-prettify-symbols-alist perl--prettify-symbols-alist) + ;; Tell font-lock.el how to handle Perl. - (setq font-lock-defaults '((perl-font-lock-keywords - perl-font-lock-keywords-1 - perl-font-lock-keywords-2) - nil nil ((?\_ . "w")) nil + (setq perl--augmented-font-lock-keywords + (append perl-font-lock-keywords + (prog-prettify-font-lock-symbols-keywords))) + (setq perl--augmented-font-lock-keywords-1 + (append perl-font-lock-keywords-1 + (prog-prettify-font-lock-symbols-keywords))) + (setq perl--augmented-font-lock-keywords-2 + (append perl-font-lock-keywords-2 + (prog-prettify-font-lock-symbols-keywords))) + + (setq font-lock-defaults '((perl--augmented-font-lock-keywords + perl--augmented-font-lock-keywords-1 + perl--augmented-font-lock-keywords-2) + nil nil ((?\_ . "w")) nil (font-lock-syntactic-face-function . perl-font-lock-syntactic-face-function))) (setq-local syntax-propertize-function #'perl-syntax-propertize-function) === modified file 'lisp/simple.el' --- lisp/simple.el 2013-05-25 02:21:49 +0000 +++ lisp/simple.el 2013-06-04 19:58:10 +0000 @@ -372,34 +372,6 @@ "Parent major mode from which special major modes should inherit." (setq buffer-read-only t)) -;; Major mode meant to be the parent of programming modes. - -(defvar prog-mode-map - (let ((map (make-sparse-keymap))) - (define-key map [?\C-\M-q] 'prog-indent-sexp) - map) - "Keymap used for programming modes.") - -(defun prog-indent-sexp (&optional defun) - "Indent the expression after point. -When interactively called with prefix, indent the enclosing defun -instead." - (interactive "P") - (save-excursion - (when defun - (end-of-line) - (beginning-of-defun)) - (let ((start (point)) - (end (progn (forward-sexp 1) (point)))) - (indent-region start end nil)))) - -(define-derived-mode prog-mode fundamental-mode "Prog" - "Major mode for editing programming language source code." - (set (make-local-variable 'require-final-newline) mode-require-final-newline) - (set (make-local-variable 'parse-sexp-ignore-comments) t) - ;; Any programming language is always written left to right. - (setq bidi-paragraph-direction 'left-to-right)) - ;; Making and deleting lines. (defvar hard-newline (propertize "\n" 'hard t 'rear-nonsticky '(hard)) --=-=-=--