From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id mKlrNBk4EWH6BQEAgWs5BA (envelope-from ) for ; Mon, 09 Aug 2021 16:13:45 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 2GcrMBk4EWFOOgAAbx9fmQ (envelope-from ) for ; Mon, 09 Aug 2021 14:13:45 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B32901DC07 for ; Mon, 9 Aug 2021 16:13:44 +0200 (CEST) Received: from localhost ([::1]:44546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mD62A-0000zK-Kw for larch@yhetil.org; Mon, 09 Aug 2021 10:13:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mD5h9-0003d0-Ol for emacs-orgmode@gnu.org; Mon, 09 Aug 2021 09:51:59 -0400 Received: from box.hyperreal.enterprises ([2a01:7e00::f03c:91ff:fe8c:3957]:56307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mD5h4-0004rJ-2g for emacs-orgmode@gnu.org; Mon, 09 Aug 2021 09:51:59 -0400 Received: from authenticated-user (box.hyperreal.enterprises [85.159.211.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by box.hyperreal.enterprises (Postfix) with ESMTPSA id 8C7C9438E7 for ; Mon, 9 Aug 2021 14:51:51 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hyperreal.enterprises; s=mail; t=1628517111; bh=2A4+YHsVTSVwLygaEGN++K8g5zciCbhzIX3kSx574rU=; h=References:From:To:Subject:In-reply-to:Date:From; b=UZfKBg7wv0BabGScDKLfXGN0VNLAUnaOMAF8PqrBsF2AT6Lb2ciHkctvEJPZcubfb ddDllty/ge3u1dbnvzCJzEuDTYMrtKAyFkKkmBJjfJ1VLtam9lVHQdGfiMxG9fprnE HOtecN8ZrC2eZX3G7BFb6jsIPBNWDIsUoaLAHJhApARtxNHctnzLOR1QrWXsBxjApr Y+HByNEH0gPDoXNvpzUbOvg5RYIvV98+4KCd07/L3OpNDYog4hAW06JIJEl4AcC2OM oYtGydYrQWvycdApTMwFDqmycrr7O6CMVl/yiXEnBEEfWS87/ZGUpzRydMLWw3cl4J tXGmmspjuJDJQ== References: <87v94ewyvw.fsf@Proteus> To: emacs-orgmode@gnu.org Subject: Re: [patch] priorities range reversed In-reply-to: <87v94ewyvw.fsf@Proteus> Date: Mon, 09 Aug 2021 14:51:51 +0100 Message-ID: <87sfziwwso.fsf@Proteus> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a01:7e00::f03c:91ff:fe8c:3957; envelope-from=joseph.corneli.orgmode@hyperreal.enterprises; helo=box.hyperreal.enterprises X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_XBL=0.375, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" Reply-to: Joe Corneli From: Joe Corneli via "General discussions about Org-mode." X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1628518425; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=xhYP+TbOGYv/Qv5NjgAHHGMYsHPNQNMHKq8foBQIlWQ=; b=W25NBkkZVXz8GIrCzirYm5jI7/Xh/ayQrKNLc0QJGlHDywNgIjM2/feEYDBlX/aPJpgGEF cmZmQQoad8gTr9nsV3dsElZduurAjrr/8878Zg0ELogQ9N+Tbie9yvt3GsevPpAFSR+CbS z271/MA0fhml3TvLS0oluzn/iFpqJVdqhqXYoBOdhFnRQrg1YsgM6KdWT7IpzkChVKqrO8 bNkZWtllJHtFHhtKM44OCrfTnzswzCJVw8p2rFeItnfG7U4wEg9W8jykKRK1i0ECK0yWrG Mx+jatQplAh8+znCpel8s2YhB74xiWdA7tTa2sKhgP2+VfjZZPu35sBk0HYCxw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1628518425; a=rsa-sha256; cv=none; b=imMbSSEQVXCrM06/1CrXD929d3u73dARJgQlLULWm4OAI/t+0dQUurdDiey4yNOs7oIuK2 aPiEJNr3mL6QyOSgC5zXjf+kyQGWsGYWEAJAO10npPyePDYEQnhyRR3+O1SA0whcmTnfwF 5p3Okv6am3dQYy0gJuImY7PO513ziaxh+17zmVWP8N9YOJU5xq/Vf3QGprJSJGr/mBBBET 85SDBlXW5f9G4jvWoGeO+BSIBRXqtiBUkGMbRVKJxILjap/af6iUmXrjSxMDxl4zKlrCMm NL0XsHRwzdtcxH5cF3SXo0qNcOrr9/ayFEN0P//uqS8l64sP8t0X0wOgH1cVZA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=hyperreal.enterprises header.s=mail header.b=UZfKBg7w; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -2.41 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=hyperreal.enterprises header.s=mail header.b=UZfKBg7w; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: B32901DC07 X-Spam-Score: -2.41 X-Migadu-Scanner: scn0.migadu.com X-TUID: JJyudc9CwhyJ --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Actually, there some bigger problems with the function as well... =E2=80=94 It didn=E2=80=99t update the priority cookie properly when one ha= d been set before * [#1] Exercise: update to [#2] =E2=80=94 After fixing that, I noticed that the included save-excursion doe= sn=E2=80=99t work (https://emacs.stackexchange.com/questions/7574/why-save-excursion-doesnt= -save-point-position) So, here=E2=80=99s a more comprehensive patch, including the previous chang= es (in order to support numeric priorities) and then adjusting the update/insert logic so that it makes more sense. I did not adjust the indentation, so that you can more clearly see which lines were changed. Inline comments in the patch explain what=E2=80=99s go= ing on. --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=priorities_rearranged.patch Content-Transfer-Encoding: quoted-printable diff --git a/lisp/org.el b/lisp/org.el index ce68f4692..69e333c84 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -11305,8 +11305,9 @@ or a character." (user-error "Priority commands are disabled")) (setq action (or action 'set)) (let ((nump (< org-priority-lowest 65)) + (saved-position (point)) current new news have remove) - (save-excursion + (org-back-to-heading t) (when (looking-at org-priority-regexp) (let ((ms (match-string 2))) @@ -11337,7 +11338,7 @@ or a character." (=3D (upcase org-priority-lowest) org-priority-lowest)) (setq new (upcase new))) (cond ((equal new ?\s) (setq remove t)) - ((or (< (upcase new) org-priority-highest) (> (upcase new) org-priority-= lowest)) + ((or (> (upcase new) org-priority-highest) (< (upcase new) org-priority-= lowest)) (user-error (if nump "Priority must be between `%s' and `%s'" @@ -11364,8 +11365,8 @@ or a character." org-priority-default (1+ org-priority-default)))))) (t (user-error "Invalid action"))) - (when (or (< (upcase new) org-priority-highest) - (> (upcase new) org-priority-lowest)) + (when (or (> (upcase new) org-priority-highest) + (< (upcase new) org-priority-lowest)) (if (and (memq action '(up down)) (not have) (not (eq last-command this-command))) ;; `new' is from default priority @@ -11377,12 +11378,26 @@ or a character." ;; Numerical priorities are limited to 64, beyond that number, ;; assume the priority cookie is a character. (setq news (if (> new 64) (format "%c" new) (format "%s" new))) + ;; Actually setting the priority isn=E2=80=99t so straightforward + ;; There are several cases (if have + ;; =E2=91=A0 have and remove (if remove (replace-match "" t t nil 1) - (replace-match news t t nil 2)) + ;; =E2=91=A1 have and not remove, i.e., update + (let ((case-fold-search nil)) (looking-at org-priority-regexp)) + (if (match-end 2) + (progn + (goto-char (match-end 2)) + (delete-region (match-beginning 2) (match-end 2)) + (insert news)) + (goto-char (match-end 1)) + (insert "[#" news "] ")) + ) + ;; =E2=91=A2 don=E2=80=99t have and remove =E2=80=94 nonsense (if remove (user-error "No priority cookie found in line") + ;; =E2=91=A3 don=E2=80=99t have and not remove, i.e., insert (let ((case-fold-search nil)) (looking-at org-todo-line-regexp)) (if (match-end 2) (progn @@ -11390,7 +11405,8 @@ or a character." (insert " [#" news "]")) (goto-char (match-beginning 3)) (insert "[#" news "] ")))) - (org-align-tags)) + (org-align-tags) + (goto-char saved-position) (if remove (message "Priority removed") (message "Priority of current item set to %s" news))))) --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=priorities_rearranged.patch Content-Transfer-Encoding: quoted-printable diff --git a/lisp/org.el b/lisp/org.el index ce68f4692..69e333c84 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -11305,8 +11305,9 @@ or a character." (user-error "Priority commands are disabled")) (setq action (or action 'set)) (let ((nump (< org-priority-lowest 65)) + (saved-position (point)) current new news have remove) - (save-excursion + (org-back-to-heading t) (when (looking-at org-priority-regexp) (let ((ms (match-string 2))) @@ -11337,7 +11338,7 @@ or a character." (=3D (upcase org-priority-lowest) org-priority-lowest)) (setq new (upcase new))) (cond ((equal new ?\s) (setq remove t)) - ((or (< (upcase new) org-priority-highest) (> (upcase new) org-priority-= lowest)) + ((or (> (upcase new) org-priority-highest) (< (upcase new) org-priority-= lowest)) (user-error (if nump "Priority must be between `%s' and `%s'" @@ -11364,8 +11365,8 @@ or a character." org-priority-default (1+ org-priority-default)))))) (t (user-error "Invalid action"))) - (when (or (< (upcase new) org-priority-highest) - (> (upcase new) org-priority-lowest)) + (when (or (> (upcase new) org-priority-highest) + (< (upcase new) org-priority-lowest)) (if (and (memq action '(up down)) (not have) (not (eq last-command this-command))) ;; `new' is from default priority @@ -11377,12 +11378,26 @@ or a character." ;; Numerical priorities are limited to 64, beyond that number, ;; assume the priority cookie is a character. (setq news (if (> new 64) (format "%c" new) (format "%s" new))) + ;; Actually setting the priority isn=E2=80=99t so straightforward + ;; There are several cases (if have + ;; =E2=91=A0 have and remove (if remove (replace-match "" t t nil 1) - (replace-match news t t nil 2)) + ;; =E2=91=A1 have and not remove, i.e., update + (let ((case-fold-search nil)) (looking-at org-priority-regexp)) + (if (match-end 2) + (progn + (goto-char (match-end 2)) + (delete-region (match-beginning 2) (match-end 2)) + (insert news)) + (goto-char (match-end 1)) + (insert "[#" news "] ")) + ) + ;; =E2=91=A2 don=E2=80=99t have and remove =E2=80=94 nonsense (if remove (user-error "No priority cookie found in line") + ;; =E2=91=A3 don=E2=80=99t have and not remove, i.e., insert (let ((case-fold-search nil)) (looking-at org-todo-line-regexp)) (if (match-end 2) (progn @@ -11390,7 +11405,8 @@ or a character." (insert " [#" news "]")) (goto-char (match-beginning 3)) (insert "[#" news "] ")))) - (org-align-tags)) + (org-align-tags) + (goto-char saved-position) (if remove (message "Priority removed") (message "Priority of current item set to %s" news))))) --=-=-= Content-Type: text/plain -- Dr Joseph A. Corneli (https://github.com/holtzermann17) HYPERREAL ENTERPRISES LTD is a private company limited by shares, incorporated 25th, June 2019 as Company Number 634284 on the Register of Companies for Scotland (https://beta.companieshouse.gov.uk/company/SC634284). --=-=-=--