emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: insert automatically a reference to a section header and a link


From: Uwe Brauer
Subject: Re: insert automatically a reference to a section header and a link
Date: Wed, 17 Nov 2021 18:05:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

>>> "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: smime.p7s
Description: S/MIME cryptographic signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]