From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?= Subject: Issues w/ hacking Org font-lock for variable pitch prose Date: Tue, 01 Dec 2015 00:27:49 +0200 Message-ID: <87oaebm8be.fsf@gkayaalp.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55673) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3Whz-0000Bx-77 for emacs-orgmode@gnu.org; Mon, 30 Nov 2015 17:14:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a3Whv-0005pR-6G for emacs-orgmode@gnu.org; Mon, 30 Nov 2015 17:14:07 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:45368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3Whv-0005oy-16 for emacs-orgmode@gnu.org; Mon, 30 Nov 2015 17:14:03 -0500 Received: from xenophon (unknown [88.228.250.237]) by mail.messagingengine.com (Postfix) with ESMTPA id BCEB0680087 for ; Mon, 30 Nov 2015 17:13:58 -0500 (EST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org-mode mailing list Hello, /I=E2=80=99ll first explain the situation and append the code to the messag= e./ Go to code: [ M-x re-search-forward RET ^CODE RET ] I read in Org mode a lot, and I dislike reading prose in monospace fonts. So I have turned on =E2=80=98variable-pitch-mode=E2=80=99 for Or= g mode. But because some stuff has to stay in stoichedon, so I set some faces to be monospace: I have also add a keyword to font-lock keywords as part of the Org hook, so that I can have a face attached to initial whitespace and lists (-, and 1., 2. etc). I set this face to monospace too, so that I have nice aligned left line, while the actual prose stays in variable pitch. I just updated today, from the default Org mode of Emacs 24.5 to the latest release (8.3.2, from git). The problems are as follows: 1. My code is buggy, and I can=E2=80=99t understand why. With previous Org= some font-lock actions were happening only after I hit enter at the end of a line, and if I have less than 3 newlines at the end of the file sometimes font-locking of headings didn=E2=80=99t work. For example, i= f I=E2=80=99m writing a paragraph, I write it in a single physical line, and I use word wrapping. If that paragraph happended to contain an inline footnote, which I use very often, that note is not highlighted until I insert a line-feed. And with the new version, while the problem persists, when I hit enter, thus inserting a newline at the end of a line, Emacs hangs up, and sometimes I see this error: org-element--current-element: Wrong type argument: integer-or-marker-p, nil ;; See end of message for the backtrace=E2=80=A6 ;; [ M-x re-search-forward RET ^BACK RET ] But if I go to the next line and =E2=80=98open-line=E2=80=99, everything i= s O.K. Maybe my keyword regex has a mistake? 2. In the new version of org mode, =E2=80=98org-block-background=E2=80=99 = face is gone, and I can=E2=80=99t set the face for block to use a monospace font. The= re is the org-block face, which doesn=E2=80=99t affect the contents of org bl= ocks, e.g. src block. Basically, the text between the org-block delimiters don=E2=80=99t get a face, so I can=E2=80=99t set the font for them. Any wo= rkarounds? 3. I do not know how to hook in properly to the org font-lock mechanism. I read the code a bit, and apparently org builds the font-lock keywords list local to the buffer when it is booting up as its major mode. I know barely anything about font-lock, but from this fact I deduce that I have to push in my keywords in a hook after it=E2=80=99s initialisation, = but I do not know if I do it properly. I=E2=80=99ve written a wall of text, I=E2=80=99m sorry. I hope there=E2= =80=99ll be someone to help me out though, because the solution is beyond my comprehension of Org and Emacs Lisp. Thanks in advance. CODE ;; =E2=80=98gk-font=E2=80=99 merely returns a font from a plist with the gi= ven keyword. (defvar gk-org-hide-leading-stuff-in-headers nil) (defface gk-org-initial-space-and-list-stuff-face `((t . (:family ,(gk-font :mono)))) "Face for initial space and list item bullets. This face is used to keep them in monospace even when variable-pitch mode is used in the org buffer.") (defvar gk-org-font-lock-keywords `(;; Initial space is monospace ("^\s*\\([0-9-]+[) ] ?\\(\\[[X ]\\]\\)?\\)?" (0 (put-text-property (match-beginning 0) (match-end 0) 'face 'gk-org-initial-space-and-list-stuff-face))) ;; Hide leading stars and space in headings. ("^\\*+ " (0 (when gk-org-hide-leading-stuff-in-headers (put-text-property (match-beginning 0) (match-end 0) 'display '(space . (width 0)))))))) (defvar gk-org-mono-faces '(org-table org-code org-special-keyword org-verbatim org-meta-line org-block org-block-begin-line org-block-end-line)) (defun gk-org-visuals-hook () "Set up how an Org buffer look." (when (window-system) ;; Variable pitch in general, monospace in tables. (variable-pitch-mode 1) (set-face-attribute 'variable-pitch nil :font (gk-font :serif) :height gk-font-org-variable-pitch-height) (set-face-attribute 'org-todo nil :font (gk-font :sans)) (mapc (lambda (x) (set-face-attribute x nil :font (gk-font :mono))) gk-org-mono-faces) (set-face-attribute 'org-footnote nil :underline nil) (dolist (face org-level-faces) (set-face-attribute face nil :family (gk-font :sans))) (font-lock-add-keywords nil gk-org-font-lock-keywords))) (add-hook 'org-mode-hook 'gk-org-visuals-hook) ;;; Code block ends here BACKTRACE ;;; Some non-printables are replaced with dots, because Gnus wanted so. ;;; If necessary, I can send in the full traceback. Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil) org-element-item-parser(41809 ((41306 0 "- " nil nil nil 41341) (41341 0 = "- " nil nil nil 41486) (41367 2 "- " nil nil nil 41486) (41403 4 "- " nil = nil nil 41446) (41446 4 "- " nil nil nil 41486) (41486 0 "- " nil nil nil 4= 1655) (41511 2 "- " nil nil nil 41633) (41556 4 "- " nil nil nil 41633) (41= 611 6 "- " nil nil nil 41633) (41633 2 "- " nil nil nil 41655) (41655 0 "- = " nil nil nil 41809) (41705 2 "- " nil nil nil 41809) (41767 4 "- " nil nil= nil 41809)) t) org-element--current-element(41809 element item ((41306 0 "- " nil nil ni= l 41341) (41341 0 "- " nil nil nil 41486) (41367 2 "- " nil nil nil 41486) = (41403 4 "- " nil nil nil 41446) (41446 4 "- " nil nil nil 41486) (41486 0 = "- " nil nil nil 41655) (41511 2 "- " nil nil nil 41633) (41556 4 "- " nil = nil nil 41633) (41611 6 "- " nil nil nil 41633) (41633 2 "- " nil nil nil 4= 1655) (41655 0 "- " nil nil nil 41809) (41705 2 "- " nil nil nil 41809) (41= 767 4 "- " nil nil nil 41809))) byte-code("\212\214~\210b\210 \205.\n\205.\306\307!\204.=0B\205.\310\31= 1\".\312\f.1.;\2031.\313\314.1.#\2028.\315.A@.1\"*.2\311\211.3\311.4\f\204m= .\316.5\317 \211.6.7\320.6P.8\321 ,\203c.\322.4\311y\210\323\311w\210\324 \= 210\202[..2U\203\237.\325\326.9\203\231.\327\f.1.;\203\216.\313\314.1.#\20= 2\225.\315.A@.1\"*\202\232.\f\"\210\202[.\330\316.5\317 \211.6.7\320.6P+.2\= 316#\203\306.\311y\210\323\311w\210\324 \210\322.4\202[.\fdU\203\322.S\20= 2\323..:\331\f.1.;\203\351.\313\314.1.#\202\360.\315.A@.1\"*\206\366.2b\21= 0\332.:.1.;\203\f.\313\314.1.#\202.\315.A@.1\"*\211.;X\205A.;b\205A.\327.:= .1.;\2036.\313\314.1.#\202=3D.\315.A@.1\"*\211.:)\204\370.:\203Z.m\203T.:.\= 202Z.:.`.3*\332..1.;\203n.\313\314.1.#\202u.\315.A@.1\"*\206\220.\212\316.5= \317 \211.6.7\320.6P.8\333 \210,`).<.;.9\203\305.`U\203\251.\325\326.<\"\2= 10\202\305.=3D\211.=3D\205\274.\334 \206\274.\335.=3D\336 \")\203\305.\325\= 337\311\"\210.\204.\340.;\305.4\341.<.1.;\203\343.\313\314.1.#\202\352.\315= .A@.1\"*$\211.\327.<.>.1\211.;\203.\342.\311.1.>$\202..A\343.A@.1.>#\240\21= 0.+\210\344.!\210\332..1.;\203-.\313\314.1.#\2024.\315.A@.1\"*.\211.:\204E.= ;\205M.\345\202M.@9\205M.@).?\211.@X\203\336.d.@U\204\336.@b\210.?\311.A.?= .A\203\253.\346.?\347\"\203{.\350\202\330.\346.?\351\"\203\207.\352\202\330= .\346.?\353\"\203\223.\354\202\330.\346.?\350\"\203\237.\322\202\330.\346.?= \355\"\205\330.\356\202\330.\346.?\352\"\203\267.\352\202\330.\346.?\354\"\= 203\303.\354\202\330.\346.?\322\"\203\317.\353\202\330.\346.?\356\"\205\330= .\356*.4\202\366.?.B>\204\356.\325\326.\"\210\202\366.\331..1.;\203.\313\31= 4.1.#\202.\315.A@.1\"*\357..1.;\203.\313\314.1.#\202#.\315.A@.1\"*.C.D.9\2= 04a.D\205\355.C\205\355.DW\204M.DU\205\355.?\360>?\205\355.CV\204a.CU\2= 05\355.dU\205\355.3\206h.Db\210\311.3.?\316.A.?.A\203\265.\346.?\347\"\203= \205.\350\202\342.\346.?\351\"\203\221.\352\202\342.\346.?\353\"\203\235.\3= 54\202\342.\346.?\350\"\203\251.\322\202\342.\346.?\355\"\205\342.\356\202\= 342.\346.?\352\"\203\301.\352\202\342.\346.?\354\"\203\315.\354\202\342.\34= 6.?\322\"\203\331.\353\202\342.\346.?\356\"\205\342.\356*.4.<.C\211.;*\204\= 366.\325\326.\"\210*\311.\202\225." [pos org-element-use-cache org-element-= -cache orgstruct-mode cached element derived-mode-p org-mode org-element--c= ache-find nil :begin get-text-property 0 plist-get t org-get-limited-outlin= e-regexp "^" outline-previous-heading planning " . \n" beginning-of-line th= row exit :parent re-search-backward :contents-begin :end outline-next-headi= ng input-pending-p time-less-p current-time interrupt org-element--current-= element :structure org-add-props plist-put org-element--cache-put plain-tex= t eql headline section plain-list item property-drawer node-property table = table-row :contents-end (plain-list table) property ...] 9) org-element--parse-to(41648) org-element-at-point() org-return() call-interactively(org-return nil nil) command-execute(org-return) --=20 =C4=B0. G=C3=B6ktu=C4=9F Kayaalp. http://gkayaalp.com/