[Orgmode] Re: [REQUEST] orgtbl-ctrl-c-ctrl-c-hook

2010-11-17 Thread Seweryn Kokot
Carsten Dominik  gmail.com> writes:

> 
> 
> On Nov 17, 2010, at 9:19 AM, Seweryn Kokot wrote:
> 
> > Hi,
> >
> > It need to attach a function to C-c C-c keybinding when exporting a  
> > table in
> > orgtbl-mode so would be nice to have orgtbl-ctrl-c-ctrl-c-hook  
> > similar to
> > org-ctrl-c-ctrl-c-hook.
> 
> This is a reasonable request - please make me a patch.

See the following patch. It seems to work in my case, but please correct it if 
necessary because I don't know if (run-hook-with-args-until-success 'orgtbl-
ctrl-c-ctrl-c-hook) line is in the right place.

Regards,
Seweryn

--- h:/org-mode/lisp/org-table.el   2010-11-16 11:17:36.0 +0100
+++ h:/org-mode/lisp/org-table-new.el   2010-11-17 10:07:34.0 +0100
@@ -48,6 +48,15 @@
 (defvar org-export-html-table-tag) ; defined in org-exp.el
 (defvar constants-unit-system)
 
+(defvar orgtbl-ctrl-c-ctrl-c-hook nil
+  "Hook for functions attaching themselves to  `C-c C-c'.
+This can be used to add additional functionality to the C-c C-c key which
+executes context-dependent commands.
+Each function will be called with no arguments.  The function must check
+if the context is appropriate for it to act.  If yes, it should do its
+thing and then return a non-nil value.  If the context is wrong,
+just do nothing and return nil.")
+
 (defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
   "Non-nil means use the optimized table editor version for `orgtbl-mode'.
 In the optimized version, the table editor takes over all simple keys that
@@ -3729,7 +3738,8 @@
  (call-interactively 'org-table-recalculate)
(org-table-maybe-recalculate-line))
   (call-interactively 'org-table-align)
-  (orgtbl-send-table 'maybe))
+  (orgtbl-send-table 'maybe)
+  (run-hook-with-args-until-success 'orgtbl-ctrl-c-ctrl-c-hook))
  ((eq action 'recalc)
   (save-excursion
(beginning-of-line 1)

Diff finished.  Wed Nov 17 10:08:00 2010



___
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] Re: [REQUEST] orgtbl-ctrl-c-ctrl-c-hook

2010-11-17 Thread Seweryn Kokot
Carsten Dominik  gmail.com> writes:

> I am a bit confused by this patch.  You do call the hook after C-c C-c  
> has done its thing.  Which is OK, but this is not what the  
> documentation in your hook variable says.  That documentation seems to  
> have been copied from the normal ctrl-c-ctrl-c hook, and these hooks  
> are used in a different way:  They establish *alternative*  
> functionality to the normal C-c C-c actions.  So if any of the hook  
> functions returns a non-nil value, the normal C-c C-c functionality  
> will *not* be executed.
> 
> So what are your true intentions, and can you make code and  
> documentation macht up?

Thank for you help. Indeed, the previous patch was confusing. I've done a new 
patch below. Is it correct now?

regards,
Seweryn

--- h:/org-mode/lisp/org-table.el   2010-11-16 11:17:36.0 +0100
+++ h:/org-mode/lisp/org-table-new.el   2010-11-17 10:54:22.0 +0100
@@ -48,6 +48,11 @@
 (defvar org-export-html-table-tag) ; defined in org-exp.el
 (defvar constants-unit-system)
 
+(defvar orgtbl-ctrl-c-ctrl-c-hook nil
+  "Hook for functions attaching themselves to `C-c C-c'.
+This can be used to add additional functionality after the table is sent
+to the receiver position.")
+
 (defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
   "Non-nil means use the optimized table editor version for `orgtbl-mode'.
 In the optimized version, the table editor takes over all simple keys that
@@ -3729,7 +3734,8 @@
  (call-interactively 'org-table-recalculate)
(org-table-maybe-recalculate-line))
   (call-interactively 'org-table-align)
-  (orgtbl-send-table 'maybe))
+  (orgtbl-send-table 'maybe)
+  (run-hooks 'orgtbl-ctrl-c-ctrl-c-hook))
  ((eq action 'recalc)
   (save-excursion
(beginning-of-line 1)

Diff finished.  Wed Nov 17 10:54:46 2010


___
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] Re: [REQUEST] orgtbl-ctrl-c-ctrl-c-hook

2010-11-17 Thread Seweryn Kokot
Carsten Dominik  gmail.com> writes:

> Should the be run only if the sending was successful?  Or also for  
> tables
> where have no ORGTBD SEND statement?  We could make orgtbl-send-table  
> return a value indicating if sending has taken place.
> 
> We might want to call the hook orgtbl-after-send-table-hook...

Yes, in my case I need to modify the exported table only if sending has taken 
place. And agree that the "orgtbl-after-send-table-hook" name is better.

Seweryn


___
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] Re: [REQUEST] orgtbl-ctrl-c-ctrl-c-hook

2010-11-17 Thread Seweryn Kokot
Carsten Dominik  gmail.com> writes:
> 
> Should the be run only if the sending was successful?  Or also for  
> tables
> where have no ORGTBD SEND statement?  We could make orgtbl-send-table  
> return a value indicating if sending has taken place.
> 
> We might want to call the hook orgtbl-after-send-table-hook...

What about this patch?

--- h:/org-mode/lisp/org-table.el   2010-11-16 11:17:36.0 +0100
+++ h:/org-mode/lisp/org-table-new.el   2010-11-17 13:35:58.0 +0100
@@ -48,6 +48,12 @@
 (defvar org-export-html-table-tag) ; defined in org-exp.el
 (defvar constants-unit-system)
 
+(defvar orgtbl-after-send-table-hook nil
+  "Hook for functions attaching to `C-c C-c', if the table is sent.
+This can be used to add additional functionality after the table is sent
+to the receiver position, othewise, if table is not sent, the functions 
+are not run.")
+
 (defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
   "Non-nil means use the optimized table editor version for `orgtbl-mode'.
 In the optimized version, the table editor takes over all simple keys that
@@ -3726,10 +3732,11 @@
   (goto-char action)
   (org-table-maybe-eval-formula)
   (if arg
- (call-interactively 'org-table-recalculate)
-   (org-table-maybe-recalculate-line))
+ (call-interactively 'org-table-recalculate)
+   (org-table-maybe-recalculate-line))
   (call-interactively 'org-table-align)
-  (orgtbl-send-table 'maybe))
+  (when (orgtbl-send-table 'maybe)
+   (run-hooks 'orgtbl-after-send-table-hook)))
  ((eq action 'recalc)
   (save-excursion
(beginning-of-line 1)
@@ -3943,7 +3950,10 @@
  (orgtbl-send-replace-tbl name txt))
(setq ntbl (1+ ntbl)))
   (message "Table converted and installed at %d receiver location%s"
-  ntbl (if (> ntbl 1) "s" "")
+  ntbl (if (> ntbl 1) "s" ""))
+ (if (> ntbl 0)
+ t
+   nil
 
 (defun org-remove-by-index (list indices &optional i0)
   "Remove the elements in LIST with indices in INDICES.

Diff finished.  Wed Nov 17 13:38:17 2010




___
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] Re: [REQUEST] orgtbl-ctrl-c-ctrl-c-hook

2010-11-17 Thread Seweryn Kokot
Carsten Dominik  gmail.com> writes:

> 
> this is good, I have applied the patch.  The only change I made was to
> return the number of sent tables instead of t.
> 
> Thanks for the patch, and thanks for going through iterations to
> get this right.
> 

Hi Carsten,

My pleasure :-) This was my first patch, so next time it should go smoother.
Thanks for guidance.

Seweryn


___
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] Re: [REQUEST] orgtbl-ctrl-c-ctrl-c-hook

2010-11-17 Thread Carsten Dominik

Hi Seweryn,

On Nov 17, 2010, at 10:10 AM, Seweryn Kokot wrote:


Carsten Dominik  gmail.com> writes:




On Nov 17, 2010, at 9:19 AM, Seweryn Kokot wrote:


Hi,

It need to attach a function to C-c C-c keybinding when exporting a
table in
orgtbl-mode so would be nice to have orgtbl-ctrl-c-ctrl-c-hook
similar to
org-ctrl-c-ctrl-c-hook.


This is a reasonable request - please make me a patch.


See the following patch. It seems to work in my case, but please  
correct it if
necessary because I don't know if (run-hook-with-args-until-success  
'orgtbl-

ctrl-c-ctrl-c-hook) line is in the right place.

Regards,
Seweryn

--- h:/org-mode/lisp/org-table.el   2010-11-16 11:17:36.0 +0100
+++ h:/org-mode/lisp/org-table-new.el	2010-11-17 10:07:34.0  
+0100

@@ -48,6 +48,15 @@
(defvar org-export-html-table-tag) ; defined in org-exp.el
(defvar constants-unit-system)

+(defvar orgtbl-ctrl-c-ctrl-c-hook nil
+  "Hook for functions attaching themselves to  `C-c C-c'.
+This can be used to add additional functionality to the C-c C-c key  
which

+executes context-dependent commands.
+Each function will be called with no arguments.  The function must  
check
+if the context is appropriate for it to act.  If yes, it should do  
its

+thing and then return a non-nil value.  If the context is wrong,
+just do nothing and return nil.")
+
(defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
  "Non-nil means use the optimized table editor version for `orgtbl- 
mode'.
In the optimized version, the table editor takes over all simple  
keys that

@@ -3729,7 +3738,8 @@
  (call-interactively 'org-table-recalculate)
(org-table-maybe-recalculate-line))
  (call-interactively 'org-table-align)
-  (orgtbl-send-table 'maybe))
+  (orgtbl-send-table 'maybe)
+  (run-hook-with-args-until-success 'orgtbl-ctrl-c-ctrl-c-hook))
 ((eq action 'recalc)
  (save-excursion
(beginning-of-line 1)



I am a bit confused by this patch.  You do call the hook after C-c C-c  
has done its thing.  Which is OK, but this is not what the  
documentation in your hook variable says.  That documentation seems to  
have been copied from the normal ctrl-c-ctrl-c hook, and these hooks  
are used in a different way:  They establish *alternative*  
functionality to the normal C-c C-c actions.  So if any of the hook  
functions returns a non-nil value, the normal C-c C-c functionality  
will *not* be executed.


So what are your true intentions, and can you make code and  
documentation macht up?


Thanks

- Carsten




, and  finished.  Wed Nov 17 10:08:00 2010



___
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


- 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] Re: [REQUEST] orgtbl-ctrl-c-ctrl-c-hook

2010-11-17 Thread Carsten Dominik

Hi Seweryn,

this is much better.  However, I still want to clarify:

On Nov 17, 2010, at 10:58 AM, Seweryn Kokot wrote:


Carsten Dominik  gmail.com> writes:

I am a bit confused by this patch.  You do call the hook after C-c  
C-c

has done its thing.  Which is OK, but this is not what the
documentation in your hook variable says.  That documentation seems  
to

have been copied from the normal ctrl-c-ctrl-c hook, and these hooks
are used in a different way:  They establish *alternative*
functionality to the normal C-c C-c actions.  So if any of the hook
functions returns a non-nil value, the normal C-c C-c functionality
will *not* be executed.

So what are your true intentions, and can you make code and
documentation macht up?


Thank for you help. Indeed, the previous patch was confusing. I've  
done a new

patch below. Is it correct now?

regards,
Seweryn

--- h:/org-mode/lisp/org-table.el   2010-11-16 11:17:36.0 +0100
+++ h:/org-mode/lisp/org-table-new.el	2010-11-17 10:54:22.0  
+0100

@@ -48,6 +48,11 @@
(defvar org-export-html-table-tag) ; defined in org-exp.el
(defvar constants-unit-system)

+(defvar orgtbl-ctrl-c-ctrl-c-hook nil
+  "Hook for functions attaching themselves to `C-c C-c'.
+This can be used to add additional functionality after the table is  
sent

+to the receiver position.")


Should the be run only if the sending was successful?  Or also for  
tables
where have no ORGTBD SEND statement?  We could make orgtbl-send-table  
return a value indicating if sending has taken place.


We might want to call the hook orgtbl-after-send-table-hook...

- Carsten



+
(defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
  "Non-nil means use the optimized table editor version for `orgtbl- 
mode'.
In the optimized version, the table editor takes over all simple  
keys that

@@ -3729,7 +3734,8 @@
  (call-interactively 'org-table-recalculate)
(org-table-maybe-recalculate-line))
  (call-interactively 'org-table-align)
-  (orgtbl-send-table 'maybe))
+  (orgtbl-send-table 'maybe)
+  (run-hooks 'orgtbl-ctrl-c-ctrl-c-hook))
 ((eq action 'recalc)
  (save-excursion
(beginning-of-line 1)

Diff finished.  Wed Nov 17 10:54:46 2010


___
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


- 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] Re: [REQUEST] orgtbl-ctrl-c-ctrl-c-hook

2010-11-17 Thread Carsten Dominik

Hi Seweryn

this is good, I have applied the patch.  The only change I made was to
return the number of sent tables instead of t.

Thanks for the patch, and thanks for going through iterations to
get this right.

- Carsten

On Nov 17, 2010, at 1:41 PM, Seweryn Kokot wrote:


Carsten Dominik  gmail.com> writes:


Should the be run only if the sending was successful?  Or also for
tables
where have no ORGTBD SEND statement?  We could make orgtbl-send-table
return a value indicating if sending has taken place.

We might want to call the hook orgtbl-after-send-table-hook...


What about this patch?

--- h:/org-mode/lisp/org-table.el   2010-11-16 11:17:36.0 +0100
+++ h:/org-mode/lisp/org-table-new.el	2010-11-17 13:35:58.0  
+0100

@@ -48,6 +48,12 @@
(defvar org-export-html-table-tag) ; defined in org-exp.el
(defvar constants-unit-system)

+(defvar orgtbl-after-send-table-hook nil
+  "Hook for functions attaching to `C-c C-c', if the table is sent.
+This can be used to add additional functionality after the table is  
sent
+to the receiver position, othewise, if table is not sent, the  
functions

+are not run.")
+
(defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
  "Non-nil means use the optimized table editor version for `orgtbl- 
mode'.
In the optimized version, the table editor takes over all simple  
keys that

@@ -3726,10 +3732,11 @@
  (goto-char action)
  (org-table-maybe-eval-formula)
  (if arg
- (call-interactively 'org-table-recalculate)
-   (org-table-maybe-recalculate-line))
+ (call-interactively 'org-table-recalculate)
+   (org-table-maybe-recalculate-line))
  (call-interactively 'org-table-align)
-  (orgtbl-send-table 'maybe))
+  (when (orgtbl-send-table 'maybe)
+   (run-hooks 'orgtbl-after-send-table-hook)))
 ((eq action 'recalc)
  (save-excursion
(beginning-of-line 1)
@@ -3943,7 +3950,10 @@
  (orgtbl-send-replace-tbl name txt))
(setq ntbl (1+ ntbl)))
  (message "Table converted and installed at %d receiver location 
%s"

-  ntbl (if (> ntbl 1) "s" "")
+  ntbl (if (> ntbl 1) "s" ""))
+ (if (> ntbl 0)
+ t
+   nil

(defun org-remove-by-index (list indices &optional i0)
  "Remove the elements in LIST with indices in INDICES.

Diff finished.  Wed Nov 17 13:38:17 2010




___
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


- 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] Re: [REQUEST] orgtbl-ctrl-c-ctrl-c-hook

2010-11-17 Thread Carsten Dominik
If you plan to submit more patches, you need to sign the FSF papers,  
please.


Cheers.

- Carsten

On Nov 17, 2010, at 2:06 PM, Seweryn Kokot wrote:


Carsten Dominik  gmail.com> writes:



this is good, I have applied the patch.  The only change I made was  
to

return the number of sent tables instead of t.

Thanks for the patch, and thanks for going through iterations to
get this right.



Hi Carsten,

My pleasure :-) This was my first patch, so next time it should go  
smoother.

Thanks for guidance.

Seweryn


___
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


- 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