From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id aGe7BsUo9WHHewEAgWs5BA (envelope-from ) for ; Sat, 29 Jan 2022 12:45:09 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id oHUEO8Qo9WGOCAEAG6o9tA (envelope-from ) for ; Sat, 29 Jan 2022 12:45:08 +0100 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 9613C28FE6 for ; Sat, 29 Jan 2022 12:45:08 +0100 (CET) Received: from localhost ([::1]:46632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nDmAF-0002FX-NZ for larch@yhetil.org; Sat, 29 Jan 2022 06:45:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nDm0m-0002Oi-TP for emacs-orgmode@gnu.org; Sat, 29 Jan 2022 06:35:22 -0500 Received: from [2607:f8b0:4864:20::102a] (port=50933 helo=mail-pj1-x102a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nDm0l-0000Kb-83; Sat, 29 Jan 2022 06:35:20 -0500 Received: by mail-pj1-x102a.google.com with SMTP id o11so9039995pjf.0; Sat, 29 Jan 2022 03:35:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bu1qDAKwPHfC3pe6MZElWl5pU1Rwdb6qTOFpsOYc+fM=; b=QeBr11whEFcqrSEFeOl2QmNAB4wswuFLlUZwrYxabcGm5H8OpNFdLm3bu1dBz5Va1b yCWb/xABYkf8v1x+lfN5pr8vZfIS5FmU5gG9i7tgI/M5nruWHM9EBsI/F5Tq3JG0E7uH CSiT1zIO/by1aQN9KuRc5A1WK8VQ/J45IOOPao/nMMcsM5aDfXgh4gt0yBXjlGoRCmfF lary8wxBlr8S35/ZRKoJh0LFvcB18uWTNt8rTvqTjkjbXqbZ6PzOmyJpihb1+wTGgZfw cj6f8SER+kbgP9hojjNK136uMED7rVSP1YUFU8ZpE5/qTIc5dXxTPJEr3wZoZH34WrI2 Wd/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bu1qDAKwPHfC3pe6MZElWl5pU1Rwdb6qTOFpsOYc+fM=; b=0CsgpeHFekwGgY19taIbwwzfCgJOeCOmEjefpoInyj/dr9EDBeZd/JuH8xDpFjuuci IVSXVY8Ol1MfTtrSnzEZ0RuWJvK9KWt31fHh13IhaLXYDW8rF9FHvt0vuUq3DpIqyamQ xaN1/RFFIj1jKQf1HxRIBoiAt/AUxe13xz/v0anWRgJ8Lr8TvxVL13IgoAwOLUKizXGi 74BP8xA2uCSveOQJmAbhOdYeKiAulOtNZTNNKsh5ninS0Xuma74cSyzxJAKnPkPovun0 T8Y2DBYYqoypgTyt501U9z+Q9V/bywQxIMhx+2BzExObly/OK3vLIpHzcYdXIN1txye5 WsSw== X-Gm-Message-State: AOAM532x2NX5223ewomHxJAZYAiLYjt3nEkEQVkP0PMNgOTTF2tP8Oe8 Toiz81D0Z4w2MYDmr5HePoAE3JSbe+mLWerU X-Google-Smtp-Source: ABdhPJy1K8m72Q9ZmuNJuKNmSP2d43/dPTfZdCwgrdA5u4TGFe4bKy6+Dw8mM8BoVW5XSg/xMWF17w== X-Received: by 2002:a17:902:be14:: with SMTP id r20mr12808601pls.97.1643456117254; Sat, 29 Jan 2022 03:35:17 -0800 (PST) Received: from localhost ([209.95.60.92]) by smtp.gmail.com with ESMTPSA id b5sm24140612pgl.22.2022.01.29.03.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 03:35:16 -0800 (PST) From: Ihor Radchenko To: Bastien , Kyle Meyer , Nicolas Goaziou , Karl Voit , Christian Heinrich , emacs-orgmode@gnu.org Subject: [PATCH 08/35] org-string-width: Reimplement to work with new folding Date: Sat, 29 Jan 2022 19:38:00 +0800 Message-Id: <7d926c0f36609fb71e134686d164bda85977e31e.1643454546.git.yantar92@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: <87y2cvloay.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.34.1" Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102a (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=yantar92@gmail.com; helo=mail-pj1-x102a.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ihor Radchenko Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1643456708; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=bu1qDAKwPHfC3pe6MZElWl5pU1Rwdb6qTOFpsOYc+fM=; b=uJX5IjIiaFroQ6zo764k3voZ8CzOGRk0eHlFWcQpovc31odWMryHeoVbplP+GzVx7CuTGE HrXzDewuCyTZZN4wH0cJFsoK3zWTg/M/hS5zOMZf+Svh8w49c+lL6xw514n1N3NOUloDQ+ VgDCnO1XbLq1UEv36tZsU0DINucMXee9CL4FTJttUNHralmK/5/vc3w5gAu+3G76UxJi6V cavYTNaWRvw+p1SHooX6mMvv8KBaNWfu0Xq9zXIUhPfKTmeuARdsf4Ts0SehsvXD5Lur7D vBVzffOIknAh5uHoKpxF9ihZ4wZni56Niw3plIoo5HvZemza/gySS14dswxLrw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1643456708; a=rsa-sha256; cv=none; b=Wh2Kcvsl23yLXTGeE86aUdArMVWWB5Pqy8o8exQYy8ZD6ZbNKzz4lRRGmpy0KJihzmfvL7 LMptB5uicyYf9VqdD66lLq4gqPFeQrCvOq5kDGGUQ481lL2ErGsXbHiTWoN5ZNZnLZypUe TYhp9y0ldRI7dLHAV+FVlylVLKSTop5G/9y0bMhgzp3wirkoWoCLgTGjQiAhZZIgbqipdi HWAtWuTb88AH84pUcIY9GF0lNnmO3k1bXvtJ+8mPsN/pSTyMT5l1prxmTSAmyyVfXbN4c4 BzxtsVKWu2momWkbBNDBqiqjWtnuvOVALeJhVbePn2u1adbuyKPRJKsWR9UkFg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QeBr11wh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -4.83 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QeBr11wh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 9613C28FE6 X-Spam-Score: -4.83 X-Migadu-Scanner: scn0.migadu.com X-TUID: lrGpUoO5F1bz This is a multi-part message in MIME format. --------------2.34.1 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit * lisp/org-macs.el (org--string-from-props): Removed since it is no longer needed. (org-string-width): Updated to use `window-text-pixel-size'. --- lisp/org-macs.el | 121 ++++++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 64 deletions(-) --------------2.34.1 Content-Type: text/x-patch; name="0008-org-string-width-Reimplement-to-work-with-new-foldin.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0008-org-string-width-Reimplement-to-work-with-new-foldin.patch" diff --git a/lisp/org-macs.el b/lisp/org-macs.el index d5d4c205d..8d156fa2f 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -883,71 +883,64 @@ (defun org-split-string (string &optional separators) results ;skip trailing separator (cons (substring string i) results))))))) -(defun org--string-from-props (s property beg end) - "Return the visible part of string S. -Visible part is determined according to text PROPERTY, which is -either `invisible' or `display'. BEG and END are 0-indices -delimiting S." - (let ((width 0) - (cursor beg)) - (while (setq beg (text-property-not-all beg end property nil s)) - (let* ((next (next-single-property-change beg property s end)) - (props (text-properties-at beg s)) - (spec (plist-get props property)) - (value - (pcase property - (`invisible - ;; If `invisible' property in PROPS means text is to - ;; be invisible, return 0. Otherwise return nil so - ;; as to resume search. - (and (or (eq t buffer-invisibility-spec) - (assoc-string spec buffer-invisibility-spec)) - 0)) - (`display - (pcase spec - (`nil nil) - (`(space . ,props) - (let ((width (plist-get props :width))) - (and (wholenump width) width))) - (`(image . ,_) - (and (fboundp 'image-size) - (ceiling (car (image-size spec))))) - ((pred stringp) - ;; Displayed string could contain invisible parts, - ;; but no nested display. - (org--string-from-props spec 'invisible 0 (length spec))) - (_ - ;; Un-handled `display' value. Ignore it. - ;; Consider the original string instead. - nil))) - (_ (error "Unknown property: %S" property))))) - (when value - (cl-incf width - ;; When looking for `display' parts, we still need - ;; to look for `invisible' property elsewhere. - (+ (cond ((eq property 'display) - (org--string-from-props s 'invisible cursor beg)) - ((= cursor beg) 0) - (t (string-width (substring s cursor beg)))) - value)) - (setq cursor next)) - (setq beg next))) - (+ width - ;; Look for `invisible' property in the last part of the - ;; string. See above. - (cond ((eq property 'display) - (org--string-from-props s 'invisible cursor end)) - ((= cursor end) 0) - (t (string-width (substring s cursor end))))))) - -(defun org-string-width (string) +(defun org-string-width (string &optional pixels) "Return width of STRING when displayed in the current buffer. -Unlike `string-width', this function takes into consideration -`invisible' and `display' text properties. It supports the -latter in a limited way, mostly for combinations used in Org. -Results may be off sometimes if it cannot handle a given -`display' value." - (org--string-from-props string 'display 0 (length string))) +Return width in pixels when PIXELS is non-nil." + ;; Wrap/line prefix will make `window-text-pizel-size' return too + ;; large value including the prefix. + ;; Face should be removed to make sure that all the string symbols + ;; are using default face with constant width. Constant char width + ;; is critical to get right string width from pixel width. + (remove-text-properties 0 (length string) + '(wrap-prefix t line-prefix t face t) + string) + (let (;; We need to remove the folds to make sure that folded table + ;; alignment is not messed up. + (current-invisibility-spec + (or (and (not (listp buffer-invisibility-spec)) + buffer-invisibility-spec) + (let (result) + (dolist (el buffer-invisibility-spec) + (unless (or (memq el + '(org-fold-drawer + org-fold-block + org-fold-outline)) + (and (listp el) + (memq (car el) + '(org-fold-drawer + org-fold-block + org-fold-outline)))) + (push el result))) + result))) + (current-char-property-alias-alist char-property-alias-alist)) + (with-temp-buffer + (setq-local display-line-numbers nil) + (setq-local buffer-invisibility-spec + current-invisibility-spec) + (setq-local char-property-alias-alist + current-char-property-alias-alist) + (let (pixel-width symbol-width) + (with-silent-modifications + (setf (buffer-string) string) + (setq pixel-width + (if (get-buffer-window (current-buffer)) + (car (window-text-pixel-size + nil (line-beginning-position) (point-max))) + (set-window-buffer nil (current-buffer)) + (car (window-text-pixel-size + nil (line-beginning-position) (point-max))))) + (unless pixels + (setf (buffer-string) "a") + (setq symbol-width + (if (get-buffer-window (current-buffer)) + (car (window-text-pixel-size + nil (line-beginning-position) (point-max))) + (set-window-buffer nil (current-buffer)) + (car (window-text-pixel-size + nil (line-beginning-position) (point-max))))))) + (if pixels + pixel-width + (/ pixel-width symbol-width)))))) (defun org-not-nil (v) "If V not nil, and also not the string \"nil\", then return V. --------------2.34.1--