From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: New feature? Remove duplicate subheadings, preserving order Date: Mon, 01 Jan 2018 11:04:42 +0100 Message-ID: <87a7xxx5c5.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eVwxZ-0005QY-Mh for emacs-orgmode@gnu.org; Mon, 01 Jan 2018 05:04:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eVwxY-0008Ii-U0 for emacs-orgmode@gnu.org; Mon, 01 Jan 2018 05:04:45 -0500 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:43105) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eVwxY-0008HZ-OV for emacs-orgmode@gnu.org; Mon, 01 Jan 2018 05:04:44 -0500 In-Reply-To: (Allen Li's message of "Sun, 31 Dec 2017 18:42:59 -0800") 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" To: Allen Li Cc: emacs-orgmode@gnu.org Hello, Allen Li writes: > I wrote a command to remove duplicate subheadings, which I use to > remove duplicate captured links among other things. Would this be a > useful addition to Org mode? > > I have included it below for reference. I will clean it up a bit if > it's a worthy feature. > > (defun mir-org-uniq () > "Remove duplicate subheadings, preserving order." > (interactive) > (let ((seen (make-hash-table :test 'equal)) > (removed 0)) > (save-excursion > (org-map-entries (lambda () > (let ((heading (org-get-heading t t t t))) > (if (not (gethash heading seen)) > (puthash heading t seen) > (org-cut-subtree) > (org-backward-heading-same-level 1) > (setq removed (1+ removed))))) > (format "LEVEL=%s" (1+ (org-current-level))) > 'tree)) > (message "Removed %d duplicates" removed))) Duplicates headings are not necessarily wrong. I think this is too specific to be integrated in Org proper. Maybe we could add a check for duplicates headings in Org Lint instead, and add this to Worg, in a "tools" page. Or we could check for duplicate headings _including contents_, which are more likely to be an error. WDYT? Regards, -- Nicolas Goaziou