emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Improved org-assign-fast-keys.
@ 2010-01-28 15:38 Mikael Fornius
  2010-01-28 18:28 ` Carsten Dominik
  0 siblings, 1 reply; 2+ messages in thread
From: Mikael Fornius @ 2010-01-28 15:38 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 534 bytes --]


I have 30+ TODO-keywords defined in some org-files.

When using C-c C-t to alter state I got weird keys assigned.

I suggest changing org-assign-fast-keys as attached patch describes.

I was bold enough to remove the FIXME comment already there but if one
has more than 70 keywords it can cause ugly keys again. But no one uses
more than 70 keywords?

I have tested it and, "it works for me". :-)

Anyway, Carsten, feel free to use this patch in org-mode if you like it.

Thanks for a great piece of software and community, cheers!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-assign-fast-keys patch --]
[-- Type: text/x-patch, Size: 2133 bytes --]

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2dc260d..c662d89 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2010-01-28  Mikael Fornius  <mfo@abc.se>
+
+	* org.el (org-assign-fast-keys): Prefer keys used in keyword name
+	when assigning. Begin using numerical characters when all in name
+	is used up. This is to spare alphanumeric characters for better
+	match with other keywords.
+
 2010-01-28  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org-latex.el (org-export-latex-preprocess): More consistent
diff --git a/lisp/org.el b/lisp/org.el
index cd378b4..d92e335 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4129,30 +4129,24 @@ This will extract info from a string like \"WAIT(w@/!)\"."
 	      x))
 	  list))
 
-;; FIXME: this could be done much better, using second characters etc.
 (defun org-assign-fast-keys (alist)
   "Assign fast keys to a keyword-key alist.
 Respect keys that are already there."
-  (let (new e k c c1 c2 (char ?a))
+  (let (new e (alt ?0))
     (while (setq e (pop alist))
-      (cond
-       ((equal e '(:startgroup)) (push e new))
-       ((equal e '(:endgroup)) (push e new))
-       ((equal e '(:newline)) (push e new))
-       (t
-	(setq k (car e) c2 nil)
-	(if (cdr e)
-	    (setq c (cdr e))
-	  ;; automatically assign a character.
-	  (setq c1 (string-to-char
-		    (downcase (substring
-			       k (if (= (string-to-char k) ?@) 1 0)))))
-	  (if (or (rassoc c1 new) (rassoc c1 alist))
-	      (while (or (rassoc char new) (rassoc char alist))
-		(setq char (1+ char)))
-	    (setq c2 c1))
-	  (setq c (or c2 char)))
-	(push (cons k c) new))))
+      (if (or (memq (car e) '(:newline :endgroup :startgroup))
+	      (cdr e)) ;; Key already assigned.
+	  (push e new)
+	(let ((clist (string-to-list (downcase (car e))))
+	      (used (append new alist)))
+	  (when (= (car clist) ?@)
+	    (pop clist))
+	  (while (and clist (rassoc (car clist) used))
+	    (pop clist))
+	  (unless clist
+	    (while (rassoc alt used)
+	      (incf alt)))
+	  (push (cons (car e) (or (car clist) alt)) new))))
     (nreverse new)))
 
 ;;; Some variables used in various places

[-- Attachment #3: Type: text/plain, Size: 20 bytes --]


-- 
Mikael Fornius

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

* Re: [PATCH] Improved org-assign-fast-keys.
  2010-01-28 15:38 [PATCH] Improved org-assign-fast-keys Mikael Fornius
@ 2010-01-28 18:28 ` Carsten Dominik
  0 siblings, 0 replies; 2+ messages in thread
From: Carsten Dominik @ 2010-01-28 18:28 UTC (permalink / raw)
  To: Mikael Fornius; +Cc: emacs-orgmode

Hi Mikael,

this looks very good, thanks for getting rid of the FIXME... :-)

I have applied the patch.

- Carsten

On Jan 28, 2010, at 4:38 PM, Mikael Fornius wrote:

>
> I have 30+ TODO-keywords defined in some org-files.
>
> When using C-c C-t to alter state I got weird keys assigned.
>
> I suggest changing org-assign-fast-keys as attached patch describes.
>
> I was bold enough to remove the FIXME comment already there but if one
> has more than 70 keywords it can cause ugly keys again. But no one  
> uses
> more than 70 keywords?
>
> I have tested it and, "it works for me". :-)
>
> Anyway, Carsten, feel free to use this patch in org-mode if you like  
> it.
>
> Thanks for a great piece of software and community, cheers!
>
> diff --git a/lisp/ChangeLog b/lisp/ChangeLog
> index 2dc260d..c662d89 100755
> --- a/lisp/ChangeLog
> +++ b/lisp/ChangeLog
> @@ -1,3 +1,10 @@
> +2010-01-28  Mikael Fornius  <mfo@abc.se>
> +
> +	* org.el (org-assign-fast-keys): Prefer keys used in keyword name
> +	when assigning. Begin using numerical characters when all in name
> +	is used up. This is to spare alphanumeric characters for better
> +	match with other keywords.
> +
> 2010-01-28  Carsten Dominik  <carsten.dominik@gmail.com>
>
> 	* org-latex.el (org-export-latex-preprocess): More consistent
> diff --git a/lisp/org.el b/lisp/org.el
> index cd378b4..d92e335 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -4129,30 +4129,24 @@ This will extract info from a string like  
> \"WAIT(w@/!)\"."
> 	      x))
> 	  list))
>
> -;; FIXME: this could be done much better, using second characters  
> etc.
> (defun org-assign-fast-keys (alist)
>   "Assign fast keys to a keyword-key alist.
> Respect keys that are already there."
> -  (let (new e k c c1 c2 (char ?a))
> +  (let (new e (alt ?0))
>     (while (setq e (pop alist))
> -      (cond
> -       ((equal e '(:startgroup)) (push e new))
> -       ((equal e '(:endgroup)) (push e new))
> -       ((equal e '(:newline)) (push e new))
> -       (t
> -	(setq k (car e) c2 nil)
> -	(if (cdr e)
> -	    (setq c (cdr e))
> -	  ;; automatically assign a character.
> -	  (setq c1 (string-to-char
> -		    (downcase (substring
> -			       k (if (= (string-to-char k) ?@) 1 0)))))
> -	  (if (or (rassoc c1 new) (rassoc c1 alist))
> -	      (while (or (rassoc char new) (rassoc char alist))
> -		(setq char (1+ char)))
> -	    (setq c2 c1))
> -	  (setq c (or c2 char)))
> -	(push (cons k c) new))))
> +      (if (or (memq (car e) '(:newline :endgroup :startgroup))
> +	      (cdr e)) ;; Key already assigned.
> +	  (push e new)
> +	(let ((clist (string-to-list (downcase (car e))))
> +	      (used (append new alist)))
> +	  (when (= (car clist) ?@)
> +	    (pop clist))
> +	  (while (and clist (rassoc (car clist) used))
> +	    (pop clist))
> +	  (unless clist
> +	    (while (rassoc alt used)
> +	      (incf alt)))
> +	  (push (cons (car e) (or (car clist) alt)) new))))
>     (nreverse new)))
>
> ;;; Some variables used in various places
>
> -- 
> Mikael Fornius
> _______________________________________________
> 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

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

end of thread, other threads:[~2010-01-28 23:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-28 15:38 [PATCH] Improved org-assign-fast-keys Mikael Fornius
2010-01-28 18:28 ` Carsten Dominik

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).