From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [ANN] Improved Flyspell check Date: Wed, 06 Nov 2013 11:00:00 -0700 Message-ID: <87li111kdb.fsf@gmail.com> References: <87li154k6d.fsf@gmail.com> <87habt4b3r.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve7PP-0004yQ-2v for emacs-orgmode@gnu.org; Wed, 06 Nov 2013 13:00:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ve7PG-000726-7Y for emacs-orgmode@gnu.org; Wed, 06 Nov 2013 13:00:51 -0500 Received: from mail-pb0-x231.google.com ([2607:f8b0:400e:c01::231]:53648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve7PF-00071s-NX for emacs-orgmode@gnu.org; Wed, 06 Nov 2013 13:00:42 -0500 Received: by mail-pb0-f49.google.com with SMTP id um15so1616611pbc.36 for ; Wed, 06 Nov 2013 10:00:40 -0800 (PST) In-Reply-To: <87habt4b3r.fsf@gmail.com> (Nicolas Goaziou's message of "Sun, 03 Nov 2013 19:02:48 +0100") 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: Nicolas Goaziou Cc: Org Mode List I've been using this since it was sent, and I haven't noticed any bad behavior. Cheers, Nicolas Goaziou writes: > Nicolas Goaziou writes: > > Updated patch. > > > -- > Nicolas Goaziou > > From 13f68648a0ff468385668f6b141748607d3f8103 Mon Sep 17 00:00:00 2001 > From: Nicolas Goaziou > Date: Sun, 3 Nov 2013 15:15:07 +0100 > Subject: [PATCH] Improve Flyspell check > > * lisp/org.el (org-mode-flyspell-verify): Rewrite function using > "org-element.el". In particular, it doesn't rely on fontification > anymore. > (org-remove-flyspell-overlays-in): Remove function. > (org-do-emphasis-faces, org-activate-plain-links) > (org-fontify-meta-lines-and-blocks-1, org-activate-footnote-links) > (org-activate-target-links, org-activate-tags, org-activate-code) > (org-activate-angle-links): Don't call > `org-remove-flyspell-overlays-in'. > * contrib/lisp/org-wikinodes.el (org-wikinodes-activate-links): Don't > call `org-remove-flyspell-overlays-in'. > --- > contrib/lisp/org-wikinodes.el | 5 -- > lisp/org.el | 109 ++++++++++++++++++++++++++---------------- > 2 files changed, 68 insertions(+), 46 deletions(-) > > diff --git a/contrib/lisp/org-wikinodes.el b/contrib/lisp/org-wikinodes.el > index 4efc373..c6f2006 100644 > --- a/contrib/lisp/org-wikinodes.el > +++ b/contrib/lisp/org-wikinodes.el > @@ -79,15 +79,10 @@ to `directory'." > (if (re-search-forward org-wikinodes-camel-regexp limit t) > (if (equal (char-after (point-at-bol)) ?*) > (progn > - ;; in heading - deactivate flyspell > - (org-remove-flyspell-overlays-in (match-beginning 0) > - (match-end 0)) > (add-text-properties (match-beginning 0) (match-end 0) > '(org-no-flyspell t)) > t) > ;; this is a wiki link > - (org-remove-flyspell-overlays-in (match-beginning 0) > - (match-end 0)) > (add-text-properties (match-beginning 0) (match-end 0) > (list 'mouse-face 'highlight > 'face 'org-link > diff --git a/lisp/org.el b/lisp/org.el > index 2382a9c..452babb 100644 > --- a/lisp/org.el > +++ b/lisp/org.el > @@ -5459,8 +5459,6 @@ The following commands are available: > (abbrev-table-put org-mode-abbrev-table > :parents (list text-mode-abbrev-table))) > > -(put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify) > - > (defsubst org-fix-ellipsis-at-bol () > (save-excursion (goto-char (window-start)) (recenter 0))) > > @@ -5685,9 +5683,6 @@ The time stamps may be either active or inactive.") > (font-lock-prepend-text-property (match-beginning 2) (match-end 2) > 'face > (nth 1 a)) > - (and (nth 2 a) > - (org-remove-flyspell-overlays-in > - (match-beginning 0) (match-end 0))) > (add-text-properties (match-beginning 2) (match-end 2) > '(font-lock-multiline t org-emphasis t)) > (when org-hide-emphasis-markers > @@ -5753,7 +5748,6 @@ prompted for." > (let (f hl) > (when (and (re-search-forward (concat org-plain-link-re) limit t) > (not (org-in-src-block-p))) > - (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0)) > (setq f (get-text-property (match-beginning 0) 'face)) > (setq hl (org-match-string-no-properties 0)) > (if (or (eq f 'org-tag) > @@ -5770,7 +5764,6 @@ prompted for." > (defun org-activate-code (limit) > (if (re-search-forward "^[ \t]*\\(:\\(?: .*\\|$\\)\n?\\)" limit t) > (progn > - (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0)) > (remove-text-properties (match-beginning 0) (match-end 0) > '(display t invisible t intangible t)) > t))) > @@ -5812,7 +5805,6 @@ by a #." > (cond > ((member dc1 '("+html:" "+ascii:" "+latex:")) > ;; a single line of backend-specific content > - (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0)) > (remove-text-properties (match-beginning 0) (match-end 0) > '(display t invisible t intangible t)) > (add-text-properties (match-beginning 1) (match-end 3) > @@ -5901,7 +5893,6 @@ by a #." > (if (and (re-search-forward org-angle-link-re limit t) > (not (org-in-src-block-p))) > (progn > - (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0)) > (add-text-properties (match-beginning 0) (match-end 0) > (list 'mouse-face 'highlight > 'keymap org-mouse-map)) > @@ -5913,7 +5904,6 @@ by a #." > (let ((fn (org-footnote-next-reference-or-definition limit))) > (when fn > (let ((beg (nth 1 fn)) (end (nth 2 fn))) > - (org-remove-flyspell-overlays-in beg end) > (add-text-properties beg end > (list 'mouse-face 'highlight > 'keymap org-mouse-map > @@ -5941,7 +5931,6 @@ by a #." > 'htmlize-link `(:uri ,hl)))) > ;; We need to remove the invisible property here. Table narrowing > ;; may have made some of this invisible. > - (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0)) > (remove-text-properties (match-beginning 0) (match-end 0) > '(invisible nil)) > (if (match-end 3) > @@ -5965,7 +5954,6 @@ by a #." > (if (and (re-search-forward org-tsr-regexp-both limit t) > (not (equal (char-before (match-beginning 0)) 91))) > (progn > - (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0)) > (add-text-properties (match-beginning 0) (match-end 0) > (list 'mouse-face 'highlight > 'keymap org-mouse-map)) > @@ -5992,7 +5980,6 @@ by a #." > (let ((case-fold-search t)) > (if (re-search-forward org-target-link-regexp limit t) > (progn > - (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0)) > (add-text-properties (match-beginning 0) (match-end 0) > (list 'mouse-face 'highlight > 'keymap org-mouse-map > @@ -6110,7 +6097,6 @@ between words." > (defun org-activate-tags (limit) > (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \r\n]") limit t) > (progn > - (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1)) > (add-text-properties (match-beginning 1) (match-end 1) > (list 'mouse-face 'highlight > 'keymap org-mouse-map)) > @@ -23861,34 +23847,75 @@ To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]." > > ;;; Fixes and Hacks for problems with other packages > > -;; Make flyspell not check words in links, to not mess up our keymap > -(defvar org-element-affiliated-keywords) ; From org-element.el > -(defvar org-element-block-name-alist) ; From org-element.el > (defun org-mode-flyspell-verify () > - "Don't let flyspell put overlays at active buttons, or on > - {todo,all-time,additional-option-like}-keywords." > - (require 'org-element) ; For `org-element-affiliated-keywords' > - (let ((pos (max (1- (point)) (point-min))) > - (word (thing-at-point 'word))) > - (and (not (get-text-property pos 'keymap)) > - (not (get-text-property pos 'org-no-flyspell)) > - (not (member word org-todo-keywords-1)) > - (not (member word org-all-time-keywords)) > - (not (member word org-options-keywords)) > - (not (member word (mapcar 'car org-startup-options))) > - (not (member-ignore-case word org-element-affiliated-keywords)) > - (not (member-ignore-case word (org-get-export-keywords))) > - (not (member-ignore-case > - word (mapcar 'car org-element-block-name-alist))) > - (not (member-ignore-case word '("BEGIN" "END" "ATTR"))) > - (not (org-in-src-block-p))))) > - > -(defun org-remove-flyspell-overlays-in (beg end) > - "Remove flyspell overlays in region." > - (and (org-bound-and-true-p flyspell-mode) > - (fboundp 'flyspell-delete-region-overlays) > - (flyspell-delete-region-overlays beg end)) > - (add-text-properties beg end '(org-no-flyspell t))) > + "Function used for `flyspell-generic-check-word-predicate'." > + (if (org-at-heading-p) > + ;; At a headline or an inlinetask, check title only. This is > + ;; faster than relying on `org-element-at-point'. > + (and (save-excursion (beginning-of-line) > + (and (let ((case-fold-search t)) > + (not (looking-at "\\*+ END[ \t]*$"))) > + (looking-at org-complex-heading-regexp))) > + (match-beginning 4) > + (>= (point) (match-beginning 4)) > + (or (not (match-beginning 5)) > + (< (point) (match-beginning 5)))) > + (let* ((element (org-element-at-point)) > + (post-affiliated (org-element-property :post-affiliated element)) > + (object-check > + (function > + ;; Non-nil if checks can be done for object at point. > + (lambda () > + (let ((object (save-excursion > + (when (org-looking-at-p "\\>") (backward-char)) > + (org-element-context element)))) > + (case (org-element-type object) > + ;; Prevent checks in links due to keybinding conflict > + ;; with Flyspell. > + ((code entity export-snippet inline-babel-call > + inline-src-block line-break latex-fragment link macro > + statistics-cookie target timestamp verbatim) > + nil) > + (footnote-reference > + ;; Only in inline footnotes, within the definition. > + (and (eq (org-element-property :type object) 'inline) > + (< (save-excursion > + (goto-char (org-element-property :begin object)) > + (search-forward ":" nil t 2)) > + (point)))) > + (otherwise t))))))) > + (if (and post-affiliated (< (point) post-affiliated)) > + (and (save-excursion > + (beginning-of-line) > + (let ((case-fold-search t)) (looking-at "[ \t]*#\\+CAPTION:"))) > + (> (point) (match-end 0)) > + (funcall object-check)) > + (case (org-element-type element) > + ((comment quote-section) t) > + (comment-block > + ;; Allow checks between block markers, not on them. > + (and (> (line-beginning-position) > + (org-element-property :post-affiliated element)) > + (save-excursion > + (end-of-line) > + (skip-chars-forward " \r\t\n") > + (< (point) (org-element-property :end element))))) > + ;; Arbitrary list of keywords where checks are meaningful. > + ;; Make sure point is on the value part of the element. > + (keyword > + (and (member (org-element-property :key element) > + '("DESCRIPTION" "TITLE")) > + (< (save-excursion > + (beginning-of-line) (search-forward ":") (point)) > + (point)))) > + ;; Check is globally allowed in paragraphs verse blocks and > + ;; table rows (after affiliated keywords) but some objects > + ;; must not be affected. > + ((paragraph table-row verse-block) > + (and (>= (point) (org-element-property :contents-begin element)) > + (< (point) (org-element-property :contents-end element)) > + (funcall object-check)))))))) > +(put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify) > > ;; Make `bookmark-jump' shows the jump location if it was hidden. > (eval-after-load "bookmark" -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D