From mboxrd@z Thu Jan 1 00:00:00 1970 From: "numbchild@gmail.com" Subject: [feature] prepend comment char before org-babel-ref Date: Wed, 24 Jan 2018 12:24:35 +0800 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c1c1b403e8df005637e0cf2" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeCcw-0002ch-GR for emacs-orgmode@gnu.org; Tue, 23 Jan 2018 23:26:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eeCcV-0007nn-79 for emacs-orgmode@gnu.org; Tue, 23 Jan 2018 23:25:34 -0500 Received: from mail-ot0-x236.google.com ([2607:f8b0:4003:c0f::236]:32816) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eeCcU-0007mT-Sk for emacs-orgmode@gnu.org; Tue, 23 Jan 2018 23:25:07 -0500 Received: by mail-ot0-x236.google.com with SMTP id d7so2508088oti.0 for ; Tue, 23 Jan 2018 20:25:06 -0800 (PST) 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: Org-mode --94eb2c1c1b403e8df005637e0cf2 Content-Type: text/plain; charset="UTF-8" I'm currently using this advice: ```elisp ;;; prepend comment char ahead of `org-babel-ref'. ;; auto prefix with comment char when create code ref in src block with `org-store-link'. (defun org-babel-ref-prepend-comment-char (arg &optional interactive?) "Prepend comment chart in Org-mode src code block." (when (org-src-edit-buffer-p) (comment-dwim nil) (insert " "))) (advice-add 'org-store-link :before #'org-babel-ref-prepend-comment-char) ``` There is another solution but not work: ```elisp ;;; Another implement solution. (defun org-src-coderef-format (&optional element) (cond ((and element (org-element-property :label-fmt element))) ((org-src-edit-buffer-p) (org-src-do-at-code-block (org-src-coderef-format))) ((org-element-property :label-fmt (org-element-at-point))) (t org-coderef-label-format))) (defun org-src-coderef-prepend-comment-char (args) "Prepend comment chart in Org-mode src code block." (when (org-src-edit-buffer-p) (comment-dwim nil) (insert " "))) (advice-add 'org-src-coderef-format :filter-return #'org-src-coderef-prepend-comment-char) ``` I think this function should be in Org-mode itself. Because when you're editing the source code, will not want this src-coderef like `(ref:example)` be editable. It should be in comment. [stardiviner] GPG key ID: 47C32433 IRC(freeenode): stardiviner Twitter: @numbchild Key fingerprint = 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433 Blog: http://stardiviner.github.io/ --94eb2c1c1b403e8df005637e0cf2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I'm currently using this advice:
```elisp
;;= ; prepend comment char ahead of `org-babel-ref'.
;; auto prefix with= comment char when create code ref in src block with `org-store-link'.<= br>(defun org-babel-ref-prepend-comment-char (arg &optional interactive= ?)
=C2=A0 "Prepend comment chart in Org-mode src code block."<= br>=C2=A0 (when (org-src-edit-buffer-p)
=C2=A0=C2=A0=C2=A0 (comment-dwim= nil)
=C2=A0=C2=A0=C2=A0 (insert " ")))

(advice-add = 9;org-store-link :before #'org-babel-ref-prepend-comment-char)
```

There is another solution but not work:
```elisp
;;= ; Another implement solution.
(defun org-src-coderef-format (&option= al element)
=C2=A0 (cond
=C2=A0=C2=A0 ((and element (org-element-prop= erty :label-fmt element)))
=C2=A0=C2=A0 ((org-src-edit-buffer-p) (org-sr= c-do-at-code-block (org-src-coderef-format)))
=C2=A0=C2=A0 ((org-element= -property :label-fmt (org-element-at-point)))
=C2=A0=C2=A0 (t org-codere= f-label-format)))

(defun org-src-coderef-prepend-comment-char (args)=
=C2=A0 "Prepend comment chart in Org-mode src code block."=C2=A0 (when (org-src-edit-buffer-p)
=C2=A0=C2=A0=C2=A0 (comment-dwim n= il)
=C2=A0=C2=A0=C2=A0 (insert " ")))

(advice-add '= org-src-coderef-format :filter-return
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #'org-src-coderef-prepend-comment-cha= r)
```

I think this function should be in Org-m= ode itself.
Because when you're editing the source code, will not = want this src-coderef like `(ref:example)` be editable. It should be in com= ment.

=
[stardiviner]=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <Hack this world!>=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 GPG key ID: 47C32433
IRC(freeenode): stardiviner = =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Twitter:=C2=A0 @numbchild
Key fi= ngerprint =3D 9BAA 92BC CDDD B9EF 3B36=C2=A0 CB99 B8C4 B8E5 47C3 2433
Bl= og: http://star= diviner.github.io/
--94eb2c1c1b403e8df005637e0cf2--