all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* C-x TAB indent-rigidly default set to 4 columns, not to 1
@ 2004-05-16 21:19 nospam55
  2004-05-17 12:53 ` nospam55
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: nospam55 @ 2004-05-16 21:19 UTC (permalink / raw)


Hi! The 

    (global-set-key [f1] 'indent-rigidly) ; 

works and is convenient, however I would like to make a mutation irFrequent of
indent-rigidly which defaults to indenting by 4 columns instead of 1 , and then
bind

    (global-set-key [f1] 'irFrequent) 


; the

    (defun irFrequent (interactive)
      (indent-rigidly 4)
    )

fails because indent-rigidly expects 3 args: I have to specify the region in
the func call ; the

     (defun irFrequent (a b c) (interactive "p\nr")
       (indent-rigidly b c a)
     )

seems to be behave like indent-rigidly ; the

               (defun irFrequent (a b c) (interactive "P\nr")
                  (if (not a) (setq a 4)  )
                  (indent-rigidly b c a)
               )

seems to be almost the solution: it almost works as I hoped , the problem is
that If I specify prefix arg 4 with C-u it fails, error message :

    irFrequent: Wrong type argument: number-or-marker-p, (4)

what is wrong?

    thanks for your time 

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

* Re: C-x TAB indent-rigidly default set to 4 columns, not to 1
  2004-05-16 21:19 C-x TAB indent-rigidly default set to 4 columns, not to 1 nospam55
@ 2004-05-17 12:53 ` nospam55
  2004-05-17 14:59 ` Dale Worley
  2004-05-17 20:12 ` Michael Slass
  2 siblings, 0 replies; 9+ messages in thread
From: nospam55 @ 2004-05-17 12:53 UTC (permalink / raw)


I answer (partially ) to myself: raw 'P' prefix arg management ,  the

          ;; we refer to "Prefix Command Arguments" , 
          ;;  fsf emacs lisp reference manual
             (defun irFrequent (arg b c) (interactive "P\nr")
               (if (listp arg) 
                   (setq arg (pop arg)) ; pop : new in emacs version 21
                   (if (and (stringp arg) (string= arg "-")) (setq arg -1))
                 ; (if (stringp arg) ( if (string= arg "-") (setq arg -1)  ) )
                   )
               (if (not arg) (setq arg 4)  ) ; we want 4, not 1
               (indent-rigidly b c arg)
               )


works quite well , unfortunately it still doesn't convert the classical ' C-u - '
hyphen prefix to -1 : the 

    (if (and (stringp arg) (string= arg "-")) (setq arg -1))

seems not to intercept a '-' string or char passed as arg :-(


    nospam55

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

* Re: C-x TAB indent-rigidly default set to 4 columns, not to 1
  2004-05-16 21:19 C-x TAB indent-rigidly default set to 4 columns, not to 1 nospam55
  2004-05-17 12:53 ` nospam55
@ 2004-05-17 14:59 ` Dale Worley
  2004-05-17 21:20   ` nospam55
  2004-05-17 20:12 ` Michael Slass
  2 siblings, 1 reply; 9+ messages in thread
From: Dale Worley @ 2004-05-17 14:59 UTC (permalink / raw)


nospam55 <nospa@no.yahoo.no> writes:
> seems to be behave like indent-rigidly ; the
> 
>                (defun irFrequent (a b c) (interactive "P\nr")
>                   (if (not a) (setq a 4)  )
>                   (indent-rigidly b c a)
>                )
> 
> seems to be almost the solution: it almost works as I hoped , the problem is
> that If I specify prefix arg 4 with C-u it fails, error message :
> 
>     irFrequent: Wrong type argument: number-or-marker-p, (4)
> 
> what is wrong?

The third argument to indent-rigidly must be a number.

You want something like this:

(defun irFrequent (start end arg)
  (interactive "r\nP")
   (indent-rigidly start end
                   (if arg (prefix-numeric-value arg) 4)))

It obtains the prefix argument in "raw" form.  If a prefix argument
was given by the user, arg will be non-null, and so you process it
into its numeric value and call prefix-numeric-value.  Otherwise, you
use the default 4.

I haven't checked that the value of arg when no prefix is specified is
really nil.  You can do this by writing a test function saving it in a
variable.  Or you can look at the C code that implements
'call-interactively', which IIRC explains exactly all the possible
values of the raw prefix argument.

Dale

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

* Re: C-x TAB indent-rigidly default set to 4 columns, not to 1
  2004-05-16 21:19 C-x TAB indent-rigidly default set to 4 columns, not to 1 nospam55
  2004-05-17 12:53 ` nospam55
  2004-05-17 14:59 ` Dale Worley
@ 2004-05-17 20:12 ` Michael Slass
  2004-05-18 23:40   ` nospam55
  2 siblings, 1 reply; 9+ messages in thread
From: Michael Slass @ 2004-05-17 20:12 UTC (permalink / raw)


nospam55 <nospa@no.yahoo.no> writes:

>Hi! The 
>
>    (global-set-key [f1] 'indent-rigidly) ; 
>
>works and is convenient, however I would like to make a mutation irFrequent of
>indent-rigidly which defaults to indenting by 4 columns instead of 1 , and then

You want your third argument to be the optional prefix-arg, and then
using the raw prefix arg specifier, P, in the interactive form for
that argument, you'll get a nil if it's not specified.  The
(or width 4) form will evaluate to width if width is non-nil, 4 otherwise.

Try this:

(defun irFrequent (beg end &optional width)
  "`indent-rigidly' region with 4 spaces, or prefix-arg spaces if provided"
  (interactive "r\nP")
  (indent-rigidly beg end (or width 4)))

-- 
Mike Slass

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

* Re: C-x TAB indent-rigidly default set to 4 columns, not to 1
  2004-05-17 14:59 ` Dale Worley
@ 2004-05-17 21:20   ` nospam55
  0 siblings, 0 replies; 9+ messages in thread
From: nospam55 @ 2004-05-17 21:20 UTC (permalink / raw)



    prefix-numeric-value does exactly the dirty processing I tried to write:
    the

        (global-set-key [f1] 'indent-rigidly) ; 

        ;; we refer to "Prefix Command Arguments" , 
        ;;  fsf emacs lisp reference manual
           (defun irFrequent (arg b c) (interactive "P\nr")
             (indent-rigidly b c (if arg (prefix-numeric-value arg) 4) )
             )

    works exactly as I wanted - Thank you very much ! :-)

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

* Re: C-x TAB indent-rigidly default set to 4 columns, not to 1
  2004-05-18 23:40   ` nospam55
@ 2004-05-18 22:03     ` Michael Slass
  2004-05-18 22:14     ` Michael Slass
  1 sibling, 0 replies; 9+ messages in thread
From: Michael Slass @ 2004-05-18 22:03 UTC (permalink / raw)


nospam55 <nospa@no.yahoo.no> writes:

>thanks Mike; your solution has still some problem with C-u C-u M-x irFrequent ,
>but leads to
>
>  ;; we refer to "Prefix Command Arguments" , 
>  ;;  fsf emacs lisp reference manual
>    (defun irFrequent (arg beg end) 
>      "`indent-rigidly' region with 4 spaces, or prefix-arg spaces if provided"
>      (interactive "P\nr")
>         (indent-rigidly beg end (prefix-numeric-value (or arg 4))  )    ; alternative 1/2
>      ;; (indent-rigidly beg end (if arg (prefix-numeric-value arg) 4) ) ; alternative 2/2
>      )
>
>
>which looks great and seems to work !
>

Hey, that is better.  I've read the prefix args page in the manual a
bunch of times, but can't seem to get it to stick in my skull.  Glad
you found a fix.

Alternative 1/1 looks better, I think.
-- 
Mike Slass

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

* Re: C-x TAB indent-rigidly default set to 4 columns, not to 1
  2004-05-18 23:40   ` nospam55
  2004-05-18 22:03     ` Michael Slass
@ 2004-05-18 22:14     ` Michael Slass
  2004-05-19  0:41       ` nospam55
  1 sibling, 1 reply; 9+ messages in thread
From: Michael Slass @ 2004-05-18 22:14 UTC (permalink / raw)


nospam55 <nospa@no.yahoo.no> writes:

>thanks Mike; your solution has still some problem with C-u C-u M-x irFrequent ,
>but leads to
>
>  ;; we refer to "Prefix Command Arguments" , 
>  ;;  fsf emacs lisp reference manual
>    (defun irFrequent (arg beg end) 
>      "`indent-rigidly' region with 4 spaces, or prefix-arg spaces if provided"
>      (interactive "P\nr")
>         (indent-rigidly beg end (prefix-numeric-value (or arg 4))  )    ; alternative 1/2
>      ;; (indent-rigidly beg end (if arg (prefix-numeric-value arg) 4) ) ; alternative 2/2
>      )
>
>
>which looks great and seems to work !
>

I think you might still want the number of spaces argument to be
optional:

(defun irFrequent (beg end &optional spaces)
  "`indent-rigidly' 4 spaces.
With prefix-arg, or optional arg SPACES, `indent-rigidly' by that amount
instead."
  (interactive "r\nP")
  (indent-rigidly beg end (prefix-numeric-value (or spaces 4))))

-- 
Mike Slass

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

* Re: C-x TAB indent-rigidly default set to 4 columns, not to 1
  2004-05-17 20:12 ` Michael Slass
@ 2004-05-18 23:40   ` nospam55
  2004-05-18 22:03     ` Michael Slass
  2004-05-18 22:14     ` Michael Slass
  0 siblings, 2 replies; 9+ messages in thread
From: nospam55 @ 2004-05-18 23:40 UTC (permalink / raw)



thanks Mike; your solution has still some problem with C-u C-u M-x irFrequent ,
but leads to

  ;; we refer to "Prefix Command Arguments" , 
  ;;  fsf emacs lisp reference manual
    (defun irFrequent (arg beg end) 
      "`indent-rigidly' region with 4 spaces, or prefix-arg spaces if provided"
      (interactive "P\nr")
         (indent-rigidly beg end (prefix-numeric-value (or arg 4))  )    ; alternative 1/2
      ;; (indent-rigidly beg end (if arg (prefix-numeric-value arg) 4) ) ; alternative 2/2
      )


which looks great and seems to work !

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

* Re: C-x TAB indent-rigidly default set to 4 columns, not to 1
  2004-05-18 22:14     ` Michael Slass
@ 2004-05-19  0:41       ` nospam55
  0 siblings, 0 replies; 9+ messages in thread
From: nospam55 @ 2004-05-19  0:41 UTC (permalink / raw)





> (defun irFrequent (beg end &optional spaces)

yes, I wanted from the start the possibility to 
change the 4 with kind of   c-u c-u   or   M-1 M-6 ; 
but also the func without &optional provides this sensitivity  :)

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

end of thread, other threads:[~2004-05-19  0:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-16 21:19 C-x TAB indent-rigidly default set to 4 columns, not to 1 nospam55
2004-05-17 12:53 ` nospam55
2004-05-17 14:59 ` Dale Worley
2004-05-17 21:20   ` nospam55
2004-05-17 20:12 ` Michael Slass
2004-05-18 23:40   ` nospam55
2004-05-18 22:03     ` Michael Slass
2004-05-18 22:14     ` Michael Slass
2004-05-19  0:41       ` nospam55

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.