Re: [O] [Orgmode] Deriving mode from org-mode

2011-07-17 Thread Anders Waldenborg
On Tue, Feb 22, 2011 at 12:52:03PM +0100, Bastien wrote:
  It is a personal wiki mode. It automatically narrows to current top level
  heading, adds some extra navigation functions and allows creating links to
  new pages (= top level heading) in a simple way. Hopefully I can clean it
  up a little bit soon and publish it.
 
 That'd be great, thanks!

Here it is, after a slight delay.

 anders
 aw-org-pw.el --- personal wiki major mode derived from org-mode.
;;
;; Copyright (C) 2011 Anders Waldenborg
;;
;; Author: Anders Waldenborg and...@0x63.nu
;; Keywords: outlines, calendar, wp
;; Version: 0.1
;;
;; This file NOT is part of GNU Emacs.
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or (at
;; your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see `http://www.gnu.org/licenses/'.
;;
;;
;;; Commentary:
;;
;; This implements the following features on top of org-mode making it
;; feel more like a (personal) wiki:
;;
;;  * Auto narrowing to current section (= first level heading).
;;  * Linking of all section names.
;;  * Creating of new sections when following nonexistant links.
;;  * Recording navigation history and back functionality.
;;
;;
;;; Code:


(require 'org)

(defconst aw-org-pw-frontpage-name StartPage
  Fake name created for the section before first heading)



 Random helper functions


(defun aw-truncate-list (l n)
  Destructivly truncates list l to n elements
  (let ((e (nthcdr (1- n) l)))
(when e
  (setcdr e nil)))
  l)

(defun aw-org-pw-word-at-point ()
  Return word at point, or currently marked text if mark is active
  (interactive)
  (if mark-active
  (buffer-substring-no-properties (point) (mark))
(when (looking-at \\w)
  (let ((start (save-excursion (while (not (looking-at \\b\\w)) 
(backward-char)) (point)))
(end (save-excursion (while (not (looking-at \\w\\b)) 
(forward-char)) (1+ (point)
(buffer-substring-no-properties start end)



 Section navigation


(defun aw-org-pw-section-regexp (optional pagename)
  Return a regexp matching page section (or any section if pagename is nil)
  (format ^\\* *\\(%s\\)$ (if pagename
(regexp-quote pagename)
  [^*].*)))

(defun aw-org-pw-get-section-region (name)
  Find (start . end) points of specified section
  (let ((case-fold-search t)
(search (aw-org-pw-section-regexp name)))
(save-excursion
  (save-restriction
(widen)
(goto-char (point-min))
(aw-org-pw-next-section)
(if (string-equal name aw-org-pw-frontpage-name)
(cons (point-min) (point))
  (while (not (looking-at search))
(forward-line)
(aw-org-pw-next-section)
(if (eobp)
(error Section not found)))
  (forward-line)
  (let ((start (point)))
(aw-org-pw-next-section)
(cons start (point

(defun aw-org-pw-all-sections ()
  Return a list with all section names
  (save-restriction
(save-excursion
  (widen)
  (let ((res (list aw-org-pw-frontpage-name))
(re (aw-org-pw-section-regexp)))
(goto-char (point-min))
(while (not (eobp))
  (when (looking-at re)
(setq res (cons (match-string-no-properties 1) res)))
  (forward-line))
res

(defun aw-org-pw-next-section ()
  Go to next section
  (let ((re (aw-org-pw-section-regexp)))
(while (not (or (eobp) (looking-at re)))
  (forward-line))
(point)))

(defun aw-org-pw-current-section-name ()
  Find current section name

This is usually same as the variable aw-org-pw-current-section,
but if navigation has happened by other means (e.g isearch) this
function may be needed to get the correct value.
  (save-restriction
(save-excursion
  (widen)
  (let ((re (aw-org-pw-section-regexp)))
(while (not (or (bobp) (looking-at re)))
  (forward-line -1))
(if (bobp)
aw-org-pw-frontpage-name
  (match-string-no-properties 1))



 Navigation with history


(defun aw-org-pw-back ()
  Goto previously visited section
  (interactive)
  (unless aw-org-pw-breadcrumbs-list
(error Nowhere to go I think...))
  (let ((f (pop aw-org-pw-breadcrumbs-list)))
(aw-org-pw-goto-section-raw (car f))
(setq aw-org-pw-current-section (car f))
(goto-char (+ (point-min) (cdr f)

(defun aw-org-pw-goto-section-raw (name)
  Go to 

Re: [Orgmode] Deriving mode from org-mode

2011-02-22 Thread Anders Waldenborg

On 02/15/2011 05:11 AM, Bastien wrote:

(org-mode-p) does the advertized job: checking whether we are in
org-mode major mode.  It would be confusing to also check against
org derived modes, at least with that function's name.


Agreed. Just hope it isn't used like that in other places.

[]


Fixed, I corrected this directly in `org-edit-src-code', allow source
code to be edited from org-mode derived modes.


Thanks!


Can you share what kind of derived mode you're writing?  What for?


It is a personal wiki mode. It automatically narrows to current top 
level heading, adds some extra navigation functions and allows creating 
links to new pages (= top level heading) in a simple way. Hopefully I 
can clean it up a little bit soon and publish it.


 anders

___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Deriving mode from org-mode

2011-02-22 Thread Carsten Dominik

On Feb 22, 2011, at 10:17 AM, Anders Waldenborg wrote:

 On 02/15/2011 05:11 AM, Bastien wrote:
 (org-mode-p) does the advertized job: checking whether we are in
 org-mode major mode.  It would be confusing to also check against
 org derived modes, at least with that function's name.
 
 Agreed. Just hope it isn't used like that in other places.
 
 []
 
 Fixed, I corrected this directly in `org-edit-src-code', allow source
 code to be edited from org-mode derived modes.
 
 Thanks!
 
 Can you share what kind of derived mode you're writing?  What for?
 
 It is a personal wiki mode. It automatically narrows to current top level 
 heading, adds some extra navigation functions and allows creating links to 
 new pages (= top level heading) in a simple way. Hopefully I can clean it 
 up a little bit soon and publish it.

You might also want to take a look at org-wikinodes.el in
the contrib directory.

- Carsten


___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Deriving mode from org-mode

2011-02-22 Thread Carsten Dominik

On Feb 22, 2011, at 10:21 AM, Carsten Dominik wrote:

 
 On Feb 22, 2011, at 10:17 AM, Anders Waldenborg wrote:
 
 On 02/15/2011 05:11 AM, Bastien wrote:
 (org-mode-p) does the advertized job: checking whether we are in
 org-mode major mode.  It would be confusing to also check against
 org derived modes, at least with that function's name.
 
 Agreed. Just hope it isn't used like that in other places.
 
 []
 
 Fixed, I corrected this directly in `org-edit-src-code', allow source
 code to be edited from org-mode derived modes.
 
 Thanks!
 
 Can you share what kind of derived mode you're writing?  What for?
 
 It is a personal wiki mode. It automatically narrows to current top level 
 heading, adds some extra navigation functions and allows creating links to 
 new pages (= top level heading) in a simple way. Hopefully I can clean it 
 up a little bit soon and publish it.
 
 You might also want to take a look at org-wikinodes.el in
 the contrib directory.

Sorry for following up on my own mail.  I want to add a pointer
to the documentation for org-wikinodes.el:

http://orgmode.org/worg/org-contrib/org-wikinodes.html

- Carsten
___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Deriving mode from org-mode

2011-02-22 Thread Bastien
Hi Anders,

Anders Waldenborg and...@0x63.nu writes:

 It is a personal wiki mode. It automatically narrows to current top level
 heading, adds some extra navigation functions and allows creating links to
 new pages (= top level heading) in a simple way. Hopefully I can clean it
 up a little bit soon and publish it.

That'd be great, thanks!

-- 
 Bastien

___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Deriving mode from org-mode

2011-02-22 Thread Anders Waldenborg

On 02/22/2011 10:34 AM, Carsten Dominik wrote:

Sorry for following up on my own mail.  I want to add a pointer
to the documentation for org-wikinodes.el:

http://orgmode.org/worg/org-contrib/org-wikinodes.html


Thanks.

I've already seen that - I'm not very interesed in camelcase links. 
However I was planning to look at the implementation to get hints on how 
to implement good links. I currently (ab)use radio targets, every top 
level heading is in the format * Page name, which seems to work 
quite well, but doesnt feel very elegant. My main focus this far has 
been to get narrowing (I really don't want to risk seeing anything that 
may distract me) and a back function so that I can go back to previous page.


 anders

___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


[Orgmode] Deriving mode from org-mode

2011-02-14 Thread Anders Waldenborg


Hi,

isn't creating a new major mode derived from org-mode supported?

I guess that part of the problem is that org-mode-p doesn't use 
derived-mode-p.



For example:
(define-derived-mode org-derived-mode org-mode Org-Derived)

and then create a new buffer using org-derived-mode and enter a source 
block, like this:


#+BEGIN_SRC emacs-lisp
#+END_SRC

and do org-edit-special (C-c ') in that buffer. When finishing editing 
one gets this message:

org-edit-src-exit: This is not a sub-editing buffer, something is wrong

 anders


___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Deriving mode from org-mode

2011-02-14 Thread Bastien
Hi Anders,

Anders Waldenborg and...@0x63.nu writes:

 isn't creating a new major mode derived from org-mode supported?

Yes it is...

 I guess that part of the problem is that org-mode-p doesn't use 
 derived-mode-p.

(org-mode-p) does the advertized job: checking whether we are in
org-mode major mode.  It would be confusing to also check against 
org derived modes, at least with that function's name.

 For example:
 (define-derived-mode org-derived-mode org-mode Org-Derived)

 and then create a new buffer using org-derived-mode and enter a source 
 block, like this:

 #+BEGIN_SRC emacs-lisp
 #+END_SRC

 and do org-edit-special (C-c ') in that buffer. When finishing editing 
 one gets this message:
 org-edit-src-exit: This is not a sub-editing buffer, something is
 wrong

Fixed, I corrected this directly in `org-edit-src-code', allow source
code to be edited from org-mode derived modes.

Can you share what kind of derived mode you're writing?  What for?

Thanks,

-- 
 Bastien

___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode