emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Uwe Brauer <oub@mat.ucm.es>
To: emacs-orgmode@gnu.org
Subject: Re: insert automatically a reference to a section header and a link
Date: Wed, 17 Nov 2021 18:05:37 +0100	[thread overview]
Message-ID: <87a6i2k90e.fsf@mat.ucm.es> (raw)
In-Reply-To: m135nukaom.fsf@nobis-it.eu

[-- Attachment #1: Type: text/plain, Size: 4135 bytes --]

>>> "SN" == Stefan Nobis <stefan-ml@snobis.de> writes:
> Uwe Brauer <oub@mat.ucm.es> writes:
>> I am not following you. You insert a header as in 

>> * Intro

>> Now you want to refer to it with a link

>> As we have seen in section ...

>> So what precisely are you typing?

> I type "As we have seen in section [[*Intro]]" (literally, I tend to
> not use any keybindings or function to insert the link). This (the
> "*Intro" inside double square brackets) is called an internal link to
> headlines and they are a default feature of Org:

Yes, but, what do you do, if you have a 10 header and each has 20
subheaders. How do you remember all these names?
Besides your approach is not automatic.

>     https://orgmode.org/manual/Internal-Links.html#Internal-Links


> If you need internal links to headings more often and do not want to
> type the whole heading text manually, you can use functions like this
> (inspired by `worf-goto' and `counsel-outline'; if you do not use
> ivy/swiper/counsel, the code should at least give the basic idea):

> #+begin_src emacs-lisp
> (defun sn/org-insert-internal-link ()
>   "Use ivy to insert a link to a heading in the current `org-mode' document."
>   (interactive)
>   (let ((settings (cdr (assq major-mode counsel-outline-settings))))
>     (ivy-read "Heading: " (counsel-outline-candidates settings)
>               :action 'sn/org-insert-internal-link-action)))

> (defun sn/org-insert-internal-link-action (x)
>   "Insert link for `sn/worf-insert-internal-link'"
>   (save-excursion
>     (goto-char (cdr x))
>     (call-interactively 'org-store-link))
>   (org-insert-last-stored-link 1)
>   (delete-char -1))
> #+end_src

Thanks but this did not work! 


I copied,  In a separate file:
#+begin_src 
(require 'counsel)
(require 'worf)

(defun sn/org-insert-internal-link ()
  "Use ivy to insert a link to a heading in the current `org-mode' document."
  (interactive)
  (let ((settings (cdr (assq major-mode counsel-outline-settings))))
    (ivy-read "Heading: " (counsel-outline-candidates settings)
              :action 'sn/org-insert-internal-link-action)))

(defun sn/org-insert-internal-link-action (x)
  "Insert link for `sn/worf-insert-internal-link'"
  (save-excursion
    (goto-char (cdr x))
    (call-interactively 'org-store-link))
  (org-insert-last-stored-link 1)
  (delete-char -1))
#+end_src

When I loaded the file I obtained:

ivy-configure: Keyword argument :init-fn not one of (:initial-input :height :occur :update-fn :unwind-fn :index-fn :sort-fn :format-fn :display-transformer-fn :more-chars :grep-p :exit-codes)

When I tried to install worf, I obtained 
#+begin_src 
Compiling file /home/oub/.emacs.d/elpa/worf-20211014.1207/elpa.el at Wed Nov 17 17:59:27 2021
Entering directory ‘/home/oub/.emacs.d/elpa/worf-20211014.1207/’

Compiling file /home/oub/.emacs.d/elpa/worf-20211014.1207/worf.el at Wed Nov 17 17:59:27 2021
worf.el:143:1: Error: Keyword argument :init-fn not one of (:initial-input :height :occur :update-fn :unwind-fn :index-fn :sort-fn :format-fn :display-transformer-fn :more-chars :grep-p :exit-codes)
#+end_src

When I called your first function I obtained
#+begin_src 
Debugger entered--Lisp error: (void-variable counsel-outline-settings)
  (assq major-mode counsel-outline-settings)
  (cdr (assq major-mode counsel-outline-settings))
  (let ((settings (cdr (assq major-mode counsel-outline-settings))))
  (ivy-read "Heading: " (counsel-outline-candidates settings) :action
  'sn/org-insert-internal-link-action))  
  sn/org-insert-internal-link() 
  funcall-interactively(sn/org-insert-internal-link)
  call-interactively(sn/org-insert-internal-link record nil)
  command-execute(sn/org-insert-internal-link record)
  execute-extended-command(nil "sn/org-insert-internal-link" "sn/or")
  funcall-interactively(execute-extended-command nil "sn/org-insert-internal-link" "sn/or")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

#+end_src

So something is not right here!

Uwe 

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

  reply	other threads:[~2021-11-17 17:18 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-17  7:36 insert automatically a reference to a section header and a link Uwe Brauer
2021-11-17  8:28 ` Uwe Brauer
2021-11-17 10:04 ` Eric S Fraga
2021-11-17 13:58   ` Uwe Brauer
2021-11-17 14:06     ` John Kitchin
2021-11-17 14:15       ` Uwe Brauer
2021-11-17 14:59         ` Stefan Nobis
2021-11-17 15:42           ` Juan Manuel Macías
2021-11-17 16:08             ` Uwe Brauer
2021-11-17 15:55           ` Uwe Brauer
2021-11-17 16:08             ` Eric S Fraga
2021-11-17 16:44               ` Uwe Brauer
2021-11-17 16:29             ` Stefan Nobis
2021-11-17 17:05               ` Uwe Brauer [this message]
2021-11-17 19:10                 ` Stefan Nobis
2021-11-23 15:20                 ` Bruce D'Arcus
2021-11-17 18:17               ` Juan Manuel Macías
2021-11-17 19:00                 ` Stefan Nobis
2021-11-17 14:58     ` Eric S Fraga
2021-11-17 16:00       ` Uwe Brauer
2021-11-17 16:31         ` Eric S Fraga
2021-11-17 17:06           ` Uwe Brauer
2021-11-17 16:49 ` [Problems with org-ref-helm-insert-ref-link and org-id-get-create] (was: insert automatically a reference to a section header and a link) Uwe Brauer
2021-11-17 17:57   ` John Kitchin
2021-11-17 18:58     ` [Problems with org-ref-helm-insert-ref-link and org-id-get-create] Uwe Brauer
2021-11-17 19:58       ` John Kitchin
2021-11-17 20:16         ` Uwe Brauer
2021-11-17 21:41         ` Uwe Brauer
2021-11-17 21:54           ` John Kitchin
2021-11-18  7:44             ` Uwe Brauer
2021-11-18  8:06               ` Uwe Brauer
2021-11-18 12:48               ` John Kitchin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a6i2k90e.fsf@mat.ucm.es \
    --to=oub@mat.ucm.es \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).