emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] [RFC] Org Minor Mode?


From: Thorsten Jolitz
Subject: Re: [O] [RFC] Org Minor Mode?
Date: Fri, 30 May 2014 10:52:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Bastien <address@hidden> writes:

Hi Bastien,

> Thorsten Jolitz <address@hidden> writes:
>
>> This is quite low level and I haven't done anything on this level yet,
>> but it might be a way to stick with performant constant regexp strings,
>> but make them more general.
>
> That's an idea -- but the one I wanted to explore is this: instead of
> running Org functions in the current buffer (e.g., an emacs-lisp-mode
> buffer), the functions would run transparently in a temporary buffer
> before updating the current one.
>
> For example, see this code in `org-open-at-point':
>
> ;; Exception n°2: links in comments.
> ((eq type 'comment)
>  (let ((string-rear (replace-regexp-in-string
>                    "^[ \t]*# [ \t]*" ""
>                    (buffer-substring (point) (line-beginning-position))))
>        (string-front (buffer-substring (point) (line-end-position))))
>    (with-temp-buffer
>      (let ((org-inhibit-startup t)) (org-mode))
>      (insert value)
>      (goto-char (point-min))
>      (when (and (search-forward string-rear nil t)
>               (search-forward string-front (line-end-position) t))
>        (goto-char (match-beginning 0))
>        (org-open-at-point)
>        (when (string= string-rear "") (forward-char))))))
>
> Obviously, this is a bit fragile and just "good enough" for this
> defun, but we could generalize it and make it more robust.

oh, I see, this must be a very recent addition, did not have this
section in my version (-> must update). 

There was a recent discussion on emacs-devel about adding a generic
`inverse-comment' function to core emacs, this would be a nice use case
(I would need that badly for outorg too, would enable it to deal with
special multi-line comments like those in C or Java). Unfortunately they
got lost in discussing how to deal with 'inline' comments, e.g. those
after a line.

If the devel's could be convinced to drop these special-case
requirements and add a robust generic core function to emacs that
inverts outcommented lines (single and multi), it would be very easy to
implement this idea in a major-mode agnostic way. Would be even better
if the function returned start and end point of the inverted region so
one could act on it somehow afterwards. 

There have been proposols and even implementations, but no conclusion
yet, maybe its worth to enter that discussion.  

This could be a solution - let many of the high-level commands check if
- org-minor-mode is active 
- they are in a comment
and if so use a temp buffer to act on the uncommented text. 

One problem is that more and more Org functions seems to get redefined
in terms of the new parser functionality, and obviously then can't be
used anymore outside org-mode. 

I realized this when looking at `org-open-at-point', e.g. this snippet:

#+begin_src emacs-lisp
  (...)    
  (let* ((context (org-element-context)) type)
    ;; On an unsupported type, check if point is contained within
    ;; a support one.
    (while (and (not (memq (setq type (org-element-type context))
                           '(headline inlinetask link footnote-definition
                                      footnote-reference timestamp)))
                (setq context (org-element-property :parent context))))
  (...)
#+end_src


Maybe this renders the whole idea of using Org functions outside of
org-mode as useless? For this snippet to work, I assume the whole
buffer must have been parsed successfully and thus must be in valid
Org syntax?

> To illustrate this way of approaching the problem of "using Org in
> non-Org buffers", consider `org-move-item-up': in an elisp comment,
> we would copy the comment paragraph at point in `with-temp-buffer',
> uncomment the buffer, call `org-move-item-up', then comment out the
> content and send it back to the original buffer as a replacement.
>
> I've not studied this idea thoroughly, and this may feels clumsy
> first, but if it spares us with the need to generalize org-mode to
> the point that org-mode is not really a separate mode anymore, it
> might be worst digging into this direction.
>
> Hope this is clearer now!

Yes, thanks! I think I get your idea of rather do some more
conditional action in some high-level user commands and keep the
frequently called low-level functions as performant as possible. 

-- 
cheers,
Thorsten




reply via email to

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