From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id sNeCEwBuuGPN+wAAbAwnHQ (envelope-from ) for ; Fri, 06 Jan 2023 19:52:48 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id oNOREwBuuGPCTQEA9RJhRA (envelope-from ) for ; Fri, 06 Jan 2023 19:52:48 +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 C15693C4A0 for ; Fri, 6 Jan 2023 19:52:47 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pDrp1-00086L-7C; Fri, 06 Jan 2023 13:52:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pDroz-00086D-MJ for emacs-orgmode@gnu.org; Fri, 06 Jan 2023 13:52:05 -0500 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pDrox-0004Bt-Nr for emacs-orgmode@gnu.org; Fri, 06 Jan 2023 13:52:05 -0500 Received: by mail-oi1-x22c.google.com with SMTP id r11so1761030oie.13 for ; Fri, 06 Jan 2023 10:52:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=umFbrS9zeu+GvdfOzjz22bgS5pDE+mndgprnr6TvXDM=; b=SO2CRC08A0mkvQeRe8z4u4FgxVifJBPzwZhDebWNmRBhlpEAhb8/57kNmLRHbKq88e cJ82w/w81rxkwVwxOsmnlEo2g5TFGCUe4HprdNQo+3/Vss4sKYDxH476qYiKDzmy8fx+ +Kg8YcbKKOOYzXhW+7dD9hCboqp0crPBK8aOwrO8r99n1lCMytffiihhwPZ/M5fk7d+W ao2dgvg0Uy4PA3E5qYymMyesquX62i1I37lrl1eGgkKFNdARmGfrW/E4O7PMaa6d+dU3 DkCx9yZTNUStwzRN8RnxeeOOnguyJNpdayxXvI6+RI2PC0m8vRNM1r/qmjbY+9+lgpIZ O5KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=umFbrS9zeu+GvdfOzjz22bgS5pDE+mndgprnr6TvXDM=; b=dMVn49uB6jeQ491FHPeZeaXSKdHPTj83NPkOWcQM5T7jFkOV+mPhvECMntwrSRZoAB fGlCbgWddNEuNXDKPYFa29HbVvtZ1ztJIpQ8B3xicgArvdgqbjZNtBvWLdGGnR/+I8Be GuMXdLRU+YUAciaRydAukdGcToP2S5zNe1Dp1LCoPeERoMpEO6futT8U4ZXOCIysWW8e VW11IhFC5Ocme15gfMTEumWzhWDA3ww0bDBFyJCLtRIPJTXA0YLZ85IZCmNfRtDvifxD HQCZj3gI+kuf1Z+a0GA3hgWg6fbZ44VJGxeqSBZac0ZADO5WKrjdbCkvk0epKsVQ+RwB CoPw== X-Gm-Message-State: AFqh2kqn1LXBx14OBgMb6+ImF5G+DtA9tbg+KmE3GKhAHq1HhTYfh4Z9 EB7m/6VyuW77bFo4Ch7zxu3leVOyIZTDBg== X-Google-Smtp-Source: AMrXdXswcdCWDHrOqdOHeLz3Jd8nSIawNo+Ja6Ai43B1PEtlFxnXJptdIoqTOJ8MUjYLQ6QaDCsVew== X-Received: by 2002:a05:6808:2226:b0:364:2adb:2680 with SMTP id bd38-20020a056808222600b003642adb2680mr977887oib.5.1673031121969; Fri, 06 Jan 2023 10:52:01 -0800 (PST) Received: from smtpclient.apple ([2804:431:c7f4:88a8:2165:4bfd:605f:38af]) by smtp.gmail.com with ESMTPSA id 21-20020aca2115000000b00354d8589a15sm685866oiz.45.2023.01.06.10.52.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jan 2023 10:52:01 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: [FR] Please add writing to existing heading in org-bibtex From: Sterling Hooten In-Reply-To: <87cz8424b4.fsf@localhost> Date: Fri, 6 Jan 2023 15:51:58 -0300 Cc: emacs-orgmode@gnu.org Content-Transfer-Encoding: quoted-printable Message-Id: <0FD9DD13-EA96-440E-B873-571DA364B274@gmail.com> References: <76ED509D-E464-4B3E-B751-B233340B2E94@gmail.com> <87cz8424b4.fsf@localhost> To: Ihor Radchenko X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::22c; envelope-from=hooten@gmail.com; helo=mail-oi1-x22c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.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_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1673031167; 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=umFbrS9zeu+GvdfOzjz22bgS5pDE+mndgprnr6TvXDM=; b=jbdKHt0hGZm44nPj1h8liSzRBvqLsQmMlqsp77wPunog3PKYrNcMryZWT0fp4CUrjgF9zn C1NafjGj45U6mu8M2MqKqtJo/u+rdt1ShvPzTsAbiqAKOYYscMeMgHHCKemACVNdi/7dUd TsWs6jBaNpu9jrVG2go2E6A66M2HVLzoZGA8Gps+JKspJYEcA/NfU88SzbcWsoNdm7g+8d +k+mg891sv04ut4Xr7kOdUnSpZqZwWFVfVzJOA4aBH/Q48GHE5oA3nAwp3U2R7DVk1pebZ /TZla4QLzx0MO9546KPVZW7czGXwZ2omShle5yok+8gDrCc1bVOjhadJu+8mdw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SO2CRC08; 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"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1673031167; a=rsa-sha256; cv=none; b=LMlToN88iJeNNgVkD0vxz6WnAYhLvUcSIg/eWNTa/ShyswKJq2pf5iVVZrKj/V7WbyKzeO bZeDHYttYb3BTWnEaYIJ0RmCzpLZCF4+CUnznouoTFWSZgRN6jnS3DCxt5UuLltnmcFzdd uOjTUFzMTCSKp8HzI8y5vydgg/biJe+YSC1b/1O9PxXWWJrXMIsi0U9phnJFoh8jgA8E/4 YWqQTWO2Kd4z6A0xglIwnA7FHz/SVey2Oo1E2Iys/0Vxxbpqb6bPMn23e8W9oCUFBxcxh/ s7J9P6CNSnbdlqw7jxfY6lOmqv3o+Mf35eAW3s0LcrLHBCPWhp7EizUQxZFAiA== X-Spam-Score: -5.68 X-Migadu-Queue-Id: C15693C4A0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SO2CRC08; 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"; dmarc=pass (policy=none) header.from=gmail.com X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -5.68 X-TUID: 776hJHL4/cwo Thanks for the instructions, this is my first patch. I think calling `nonew=E2=80=99 invalidates the argument `no-indent=E2=80= =99 as `org-bibtex-put=E2=80=99 eventually=20 calls `org-entry-put=E2=80=99 which uses `org-indent-line=E2=80=99. = I=E2=80=99m not sure what=E2=80=99s the best way to handle that. diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index d4e9b4368..8eab4cae2 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -513,6 +513,10 @@ use =3Dattachment:=3D style links instead of the = standard =3Dfile:=3D link type. *** New function ~org-get-title~ to get =3D#+TITLE:=3D property from = buffers =20 A function to collect the document title from the org-mode buffer. +*** ~org-bibtex-write~ can now write to heading at point with optional = interactive argument + +Previously, a new heading was created. Now with argument =3Dnonew=3D = the +bibtex data will be added to properties of heading at point. =20 *** ~org-fold-show-entry~ does not fold drawers by default anymore =20 diff --git a/lisp/ol-bibtex.el b/lisp/ol-bibtex.el index 313b1cde8..91aa4c36e 100644 --- a/lisp/ol-bibtex.el +++ b/lisp/ol-bibtex.el @@ -718,29 +718,33 @@ Return the number of saved entries." (interactive "fFile: ") (org-bibtex-read-buffer (find-file-noselect file 'nowarn 'rawfile))) =20 -(defun org-bibtex-write (&optional noindent) +(defun org-bibtex-write (&optional nonew noindent) "Insert a heading built from the first element of = `org-bibtex-entries'. + +With prefix argument NONEW modify properties of heading at point. When optional argument NOINDENT is non-nil, do not indent the = properties drawer." - (interactive) + (interactive "P") (unless org-bibtex-entries (error "No entries in `org-bibtex-entries'")) (let* ((entry (pop org-bibtex-entries)) (org-special-properties nil) ; avoids errors with = `org-entry-put' (val (lambda (field) (cdr (assoc field entry)))) - (togtag (lambda (tag) (org-toggle-tag tag 'on)))) - (org-insert-heading) - (insert (funcall org-bibtex-headline-format-function entry)) - (insert "\n:PROPERTIES:\n") - (org-bibtex-put "TITLE" (funcall val :title) 'insert) + (togtag (lambda (tag) (org-toggle-tag tag 'on))) + (insert-raw (not nonew))) + (unless nonew + (org-insert-heading) + (insert (funcall org-bibtex-headline-format-function entry)) + (insert "\n:PROPERTIES:\n")) + (org-bibtex-put "TITLE" (funcall val :title) insert-raw) (org-bibtex-put org-bibtex-type-property-name (downcase (funcall val :type)) - 'insert) + insert-raw) (dolist (pair entry) (pcase (car pair) (:title nil) (:type nil) - (:key (org-bibtex-put org-bibtex-key-property (cdr pair) = 'insert)) + (:key (org-bibtex-put org-bibtex-key-property (cdr pair) = insert-raw)) (:keywords (if org-bibtex-tags-are-keywords (dolist (kw (split-string (cdr pair) ", *")) (funcall @@ -748,9 +752,9 @@ drawer." (replace-regexp-in-string "[^[:alnum:]_@#%]" "" (replace-regexp-in-string "[ \t]+" "_" kw)))) - (org-bibtex-put (car pair) (cdr pair) 'insert))) - (_ (org-bibtex-put (car pair) (cdr pair) 'insert)))) - (insert ":END:\n") + (org-bibtex-put (car pair) (cdr pair) insert-raw))) + (_ (org-bibtex-put (car pair) (cdr pair) insert-raw)))) + (unless nonew (insert ":END:\n")) (mapc togtag org-bibtex-tags) (unless noindent (org-indent-region @@ -771,7 +775,7 @@ drawer." (interactive "fFile: ") (let ((pos (point))) (dotimes (_ (org-bibtex-read-file file)) - (save-excursion (org-bibtex-write 'noindent)) + (save-excursion (org-bibtex-write nil 'noindent)) (re-search-forward org-property-end-re) (insert "\n")) (org-indent-region pos (point)))) > On 2022-12-27, at 13:34, Ihor Radchenko wrote: >=20 > Sterling Hooten writes: >=20 >> The default behavior of org-bibtex-write is to insert a new >> heading with the bibliographic data in the properties. But an >> alternative workflow would just update the properties of the heading = at >> point, rather than creating a new one. The below patch is a simple >> implementation I=E2=80=99ve been using for a month. Would it be = possible to >> integrate this upstream? >=20 > Yes. It will make sense. >=20 >> -(defun org-bibtex-write () >> - "Insert a heading built from the first element of = `org-bibtex-entries'." >> +(defun org-bibtex-write (&optional no-new) >> + "Insert a heading built from the first element of = `org-bibtex-entries'. With non-nil optional NO-NEW write to heading at = point instead of creating new." >=20 > Please put the second sentence on a separate line. By convention, = first > line is a short description of the command and should not exceed 80 > symbols. See > = https://www.gnu.org/software/emacs/manual/html_node/elisp/Documentation-Ti= ps.html >=20 > Also, it will be a good idea to write heading at point when the = command > is called with prefix argument (C-u). >=20 >> + ;; SWH 2022-11-22 changes to allow for writing heading at point = instead of inserting new. >=20 > Please prepare a proper patch with CHANGELOG entry. > This comment is not how we make changes in Org. > See https://orgmode.org/worg/org-contribute.html#first-patch >=20 >> (interactive) >=20 > You can change the interactive form to allow prefix argument. > See = https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Interactiv= e.html >=20 > --=20 > Ihor Radchenko // yantar92, > Org mode contributor, > Learn more about Org mode at . > Support Org development at , > or support my work at