From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: [RFC] Org Minor Mode? Date: Fri, 30 May 2014 10:52:49 +0200 Message-ID: <87a99zlkbi.fsf@gmail.com> References: <87ha61f4rk.fsf@gmail.com> <8738hlkn64.fsf@gmail.com> <87zjj9g87k.fsf@gmail.com> <877g5znrgl.fsf@bzg.ath.cx> <87y4xnzif9.fsf@gmail.com> <8738ft379k.fsf@bzg.ath.cx> <878uplim22.fsf@gmail.com> <87y4xl1mh5.fsf@bzg.ath.cx> <87zji0xysn.fsf@gmail.com> <87y4xks9a7.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqIYn-0003Jg-4G for emacs-orgmode@gnu.org; Fri, 30 May 2014 04:53:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WqIYh-0006k7-74 for emacs-orgmode@gnu.org; Fri, 30 May 2014 04:53:09 -0400 Received: from plane.gmane.org ([80.91.229.3]:39732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqIYg-0006jr-Tk for emacs-orgmode@gnu.org; Fri, 30 May 2014 04:53:03 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WqIYf-0006Qj-VS for emacs-orgmode@gnu.org; Fri, 30 May 2014 10:53:01 +0200 Received: from g231234225.adsl.alicedsl.de ([92.231.234.225]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 30 May 2014 10:53:01 +0200 Received: from tjolitz by g231234225.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 30 May 2014 10:53:01 +0200 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Bastien writes: Hi Bastien, > Thorsten Jolitz 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