emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* hidestarsfile: "hidestars" for file
@ 2012-02-03 16:43 Michael Brand
  2012-02-09 18:57 ` Michael Brand
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Brand @ 2012-02-03 16:43 UTC (permalink / raw)
  To: Org Mode

Hi all

Using hooks for file find and for file save I implemented
hidestarsfile: On the fly and inspired by hidestars (a cleaner outline
view: http://orgmode.org/manual/Clean-view.html )
- remove the leading stars from all headings when writing a buffer to
  the file
- reinsert the leading stars when reading a file into the buffer

Following is an example of the _file content_ first with leading stars
as usual and below without leading stars through "#+STARTUP: odd
hidestars hidestarsfile":

#+BEGIN_EXAMPLE
  #+STARTUP: odd hidestars
  [...]
  ***** TODO section
  ******* subsection
  ********* subsubsec
            - bla bla
  ***** section
        - bla bla
  ******* subsection
#+END_EXAMPLE

#+BEGIN_EXAMPLE
  #+STARTUP: odd hidestars hidestarsfile
  [...]
      * TODO section
        * subsection
          * subsubsec
            - bla bla
      * section
        - bla bla
        * subsection
#+END_EXAMPLE

The latter is convenient for better human readability when an Org
file, additionally to Emacs, is read with a file viewer or, for
smaller edits, with an editor not capable of the Org file format. To
change the format for the current file simply add or remove the
keyword hidestarsfile in the STARTUP line.

hidestarsfile is just a hack and can not become part of the Org core:
- An Org file with hidestarsfile can not contain list items with a
  star as bullet due to the syntax conflict at read time.
- An Org file with hidestarsfile can almost not be edited with an Org
  mode without added functionality of hidestarsfile as long as the
  file is not converted back.

I am still uncertain about if this could be made Org-mode-specific to
cover more use cases: When switching between Org mode and another
major mode like Fundamental mode it would remove and reinsert the
leading stars in the buffer itself, not only in the file. The current
state is that it only reinserts the leading stars in the buffer and
only removes them in the file. It does this regardless of the major
mode, assuming that not-Org-files don't contain the "^#\+STARTUP:"
hidestarsfile keywords. This is a simplification but I think it also
helps to ensure better that it is less prone to the error of loosing
track if it should now remove or reinsert and whether to mark
not-modified. The org-mode-hook is called also when following a link
and sometimes (source blocks?) more than once when just opening a
file. I guess that this tracking could be even harder for leaving Org
mode.

The text until here and the 40 lines of Emacs Lisp are on Worg:
http://orgmode.org/worg/org-hacks.html#hidestarsfile

Are there opinions about making hidestarsfile Org-mode-specific as
mentioned above?

Is there a hook for the event of leaving Org mode or could one be
added for this purpose?

Michael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: hidestarsfile: "hidestars" for file
  2012-02-03 16:43 hidestarsfile: "hidestars" for file Michael Brand
@ 2012-02-09 18:57 ` Michael Brand
  2012-02-16 17:53   ` Michael Brand
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Brand @ 2012-02-09 18:57 UTC (permalink / raw)
  To: Org Mode

Hi all

On Fri, Feb 3, 2012 at 17:43, Michael Brand <michael.ch.brand@gmail.com> wrote:
> I am still uncertain about if this could be made Org-mode-specific to
> cover more use cases: When switching between Org mode and another
> major mode like Fundamental mode [...]

Now I see that for testing how a hidestarsfile looks like in a file
viewer or simple editor, preferred over switching the major mode is:
Just stay in Org mode and with org-hide-leading-stars still enabled
from before, temporarily change only the look:

#+BEGIN_SRC emacs-lisp
  (visible-mode 1)
  (my-disable-font-lock-except-org-hide)
#+END_SRC

I have not yet much of an idea how to do this: Disable font lock for
all faces except the face org-hide. What possibilities are there?

Michael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: hidestarsfile: "hidestars" for file
  2012-02-09 18:57 ` Michael Brand
@ 2012-02-16 17:53   ` Michael Brand
  2012-02-26 15:50     ` Michael Brand
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Brand @ 2012-02-16 17:53 UTC (permalink / raw)
  To: Org Mode

Hi all

For the case that anyone should be interested in this, still only a
monolog:

On Thu, Feb 9, 2012 at 19:57, Michael Brand <michael.ch.brand@gmail.com> wrote:
> Now I see that for testing how a hidestarsfile looks like in a file
> viewer or simple editor, preferred over switching the major mode is:
> Just stay in Org mode and with org-hide-leading-stars still enabled
> from before, temporarily change only the look:
>
> #+BEGIN_SRC emacs-lisp
>  (visible-mode 1)
>  (my-disable-font-lock-except-org-hide)
> #+END_SRC
>
> I have not yet much of an idea how to do this: Disable font lock for
> all faces except the face org-hide. What possibilities are there?

After an adventurous, instructive and funny "proof of concept" to
backup, overwrite with the face "default" and restore again one of the
Org faces (extensible to all) with the help of "copy-face",
"symbol-name" and "intern" I decided to study font-lock and now am
starting to use this simple possibility to disable all faces except
org-hide:

#+BEGIN_SRC emacs-lisp
  (defun my-org-lookout-face-defaults ()
    "Reset font lock of faces back to `org-set-font-lock-defaults'.
  Derived from `font-lock-add-keywords'."
    (interactive)
    (if (eq major-mode 'org-mode)
        (progn
          (setq font-lock-keywords
                (font-lock-compile-keywords org-font-lock-keywords))
          (font-lock-fontify-buffer))
      (message "ERR: not in Org mode")
      (ding)))

  (defun my-org-lookout-face-hide ()
    "Leave `org-hide' for leading stars and disable all other faces.
  Derived from `font-lock-add-keywords' and
  `org-set-font-lock-defaults'. Does not adapt font-lock-defaults and
  sets font-lock-keywords directly"
    (interactive)
    (if (eq major-mode 'org-mode)
        (progn
          (setq font-lock-keywords
                (font-lock-compile-keywords
                 '(("^\\(\\**\\)\\(\\* \\)\\(.*\\)"
                    (1 (if org-hide-leading-stars
                           'org-hide
                         'org-default))))))
          (font-lock-fontify-buffer))
      (message "ERR: not in Org mode")
      (ding)))
#+END_SRC

Michael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: hidestarsfile: "hidestars" for file
  2012-02-16 17:53   ` Michael Brand
@ 2012-02-26 15:50     ` Michael Brand
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Brand @ 2012-02-26 15:50 UTC (permalink / raw)
  To: Peter Salazar; +Cc: Org Mode

Hi Peter

Thanks for testing hidestarsfile. I just published fileconversion
version 0.2 (generalized name and functionality) with a speed-up [1]
and many other improvements. So please check out again:
http://orgmode.org/worg/org-hacks.html#fileconversion

> [...] Even better would be if the
> stars showed up as # so they'd be readable with Markdown.

Nice idea and implemented with the new generalisation of
my-org-fileconversion-* that is now extensible.

Take care that you don't end up hooking a complete file format
conversion to and from a format by calling pandoc and Org export or
similar. ;-)

> It turns out the spinning pinwheel was due to an incompatibility
> between the new version of org-mode and a function I'm running called
> hidestarsfile, which made my .org files nice and readable in other
> text editors.
>
> Hidestarsfile worked fine with my old org-mode, but for some reason
> with the new version it causes endless pinwheeling. I removed that
> function from my .emacs file and now everything is running smoothly.

I could not reproduce this with Aquamacs 2.1 and org-version 7.8.03
(release_7.8.03-258-g263cb.dirty). What is the backtrace when you set
debug-on-quit to t and stop the pinwheel with "C-g C-g"?

Michael

[1] hidestarsfile now uses less CPU time than the rest of Org mode for
    all of some typical Org files that I profiled during find-file.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-02-26 15:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-03 16:43 hidestarsfile: "hidestars" for file Michael Brand
2012-02-09 18:57 ` Michael Brand
2012-02-16 17:53   ` Michael Brand
2012-02-26 15:50     ` Michael Brand

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).