Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editing plain source code blocks as well #15

Open
Luis-Henriquez-Perez opened this issue Apr 16, 2020 · 5 comments
Open

editing plain source code blocks as well #15

Luis-Henriquez-Perez opened this issue Apr 16, 2020 · 5 comments

Comments

@Luis-Henriquez-Perez
Copy link

It would be nice if separedit could also edit code blocks--regular code blocks I
mean that are not in a string. org-edit-src-code is not as simple and easily
customizable as edit-indirect buffers. Also, it would be more consistent if
every "separate" edit were done using the same backend--edit-indirect.

Before I knew of this project I had been working on using edit-indirect
instead of org-edit-src-code so I have some code on this I could offer. Please
let me know what you think of this idea.

@twlz0ne
Copy link
Owner

twlz0ne commented Apr 20, 2020

Idea/code are Welcome.

Although it is not directly supported yet, but we can simply wrap a function to do it:

(defun separedit/edit-org-src-block ()
  "Edit org src code block."
  (interactive)
  (when-let* ((datum (when (org-in-src-block-p)
                       (org-element-context)))
              (content-info (org-src--contents-area datum)))
    (separedit
     (separedit-mark-region (nth 0 content-info)
                            (nth 1 content-info)
                            (org-src-get-lang-mode
                             (plist-get (cadr datum) :language))))))

@Luis-Henriquez-Perez
Copy link
Author

This looks good!

I have other ideas as well but I'll create separate issues for them.

@Luis-Henriquez-Perez
Copy link
Author

There is a bug with separedit/edit-src-block. The #+end_src ends up off. I think this is because the source block had no contents.

output-2020-04-23-14:26:48

@twlz0ne
Copy link
Owner

twlz0ne commented Apr 24, 2020

(defun separedit/edit-org-src-block ()
  "Edit org src code block."
  (interactive)
  (when-let* ((datum (when (org-in-src-block-p) (org-element-context)))
              (content-info (org-src--contents-area datum)))
    (lexical-let*
        ((ov (when (string-empty-p (nth 2 content-info))
               (make-overlay (nth 1 content-info)
                             (nth 1 content-info) nil nil t)))
         (ad (when ov
               (lambda ()
                 (with-current-buffer (overlay-buffer ov)
                   (save-excursion
                     (goto-char (overlay-end ov))
                     (delete-overlay ov)
                     (unless (= (point) (point-at-bol))
                       (insert "\n")))))))
         (buf (separedit
               (separedit-mark-region (nth 0 content-info)
                                      (nth 1 content-info)
                                      (org-src-get-lang-mode
                                       (plist-get (cadr datum) :language))))))
      (when ad
        (with-current-buffer buf
          (setq-local kill-buffer-hook (append (list ad) kill-buffer-hook)))))))

@Luis-Henriquez-Perez
Copy link
Author

I still get the same problem with the new version. When I have time I'll try my
hand at this. I've already tried to do this so I have some code.

Question: would you accept a PR to bring this into separedit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants