Loading ...
Sorry, an error occurred while loading the content.
 

[jasspa] numbers <-> bullets

Expand Messages
  • Detlef Groth
    Thomas was wishing a better numbering macro, here it is: ; change-numbers-1 is performed within the next thirty lines were no other numbers should be present
    Message 1 of 3 , Oct 11, 1999
      Thomas was wishing a better numbering macro, here it is:
      ; change-numbers-1 is performed within the next thirty lines were no other numbers should be present at the begiing of a line. This macro can be modified for other bullets or numbers. Go over your first line and press your shortcut. Be aware that '.' is a regular expression, so:

      1) test
      1) Me
      2) and
      3) press
      4) 1 key

      can be translatet to:


      1. test
      2. Me
      3. and
      4. press
      5. 1 key
      by:

      define-macro change-numbers-1
      ; set-variable $debug 1 ; for debugging; this works not correct in my release
      set-alpha-mark "P"
      -30 replace-string "^1." "*"
      -30 replace-string "^2." "*"
      -30 replace-string "^3." "*"
      -30 replace-string "^4." "*"
      -30 replace-string "^5." "*"
      -30 replace-string "^6." "*"
      -30 replace-string "^7." "*"
      -30 replace-string "^8." "*"
      -30 replace-string "^9." "*"
      goto-alpha-mark "P"
      1 replace-string "^*" "1."
      1 replace-string "^*" "2."
      1 replace-string "^*" "3."
      1 replace-string "^*" "4."
      1 replace-string "^*" "5."
      1 replace-string "^*" "6."
      1 replace-string "^*" "7."
      1 replace-string "^*" "8."
      1 replace-string "^*" "9."
      goto-alpha-mark "P"
      !emacro

      This next one works with the aid of a new buffer <tmp>, you have to mark your list and to press your shortcut. This avoids the 30 lines restriction of 'change-numbers-1'.

      define-macro change-numbers-2
      ; set-variable $debug 1
      set-variable $buffer-fname #l0
      kill-region
      next-window-find-file "tmp" ; which is the usual buffer to perform such tasks ?
      yank
      beginning-of-buffer
      set-alpha-mark "P"
      replace-string "^1." "* "
      replace-string "^2." "* "
      replace-string "^3." "* "
      replace-string "^4." "* "
      replace-string "^5." "* "
      replace-string "^6." "* "
      replace-string "^7." "* "
      replace-string "^8." "* "
      replace-string "^9." "* "
      goto-alpha-mark "P"
      1 replace-string "^* " "1."
      1 replace-string "^* " "2."
      1 replace-string "^* " "3."
      1 replace-string "^* " "4."
      1 replace-string "^* " "5."
      1 replace-string "^* " "6."
      1 replace-string "^* " "7."
      1 replace-string "^* " "8."
      1 replace-string "^* " "9."
      goto-alpha-mark "P"
      beginning-of-buffer
      set-mark
      end-of-buffer
      kill-region
      delete-window
      find-buffer #l0
      yank
      !emacro

      the next two numbers are similar two the first one, go over the first number or bullet and press your shortcut.

      define-macro change-numbers-to-bullets
      ; set-variable $debug 1
      set-alpha-mark "P"
      -30 replace-string "^1." "* "
      -30 replace-string "^2." "* "
      -30 replace-string "^3." "* "
      -30 replace-string "^4." "* "
      -30 replace-string "^5." "* "
      -30 replace-string "^6." "* "
      -30 replace-string "^7." "* "
      -30 replace-string "^8." "* "
      -30 replace-string "^9." "* "
      goto-alpha-mark "P"
      !emacro

      * test
      * Me
      * and
      * press
      * 1 key

      define-macro change-bullets-to-numbers
      ; set-variable $debug 1
      set-alpha-mark "P"
      1 replace-string "^* " "1. "
      1 replace-string "^* " "2. "
      1 replace-string "^* " "3. "
      1 replace-string "^* " "4. "
      1 replace-string "^* " "5. "
      1 replace-string "^* " "6. "
      1 replace-string "^* " "7. "
      1 replace-string "^* " "8. "
      1 replace-string "^* " "9. "
      goto-alpha-mark "P"
      !emacro

      1. test
      2. Me
      3. and
      4. press
      5. 1 key

      Happy Number- and Bulleting !

      Any comments and improvements are welcome !
      best regards,
      Detlef
    • Thomas Hundt
      Detlef s got some good ideas here. I was messing around, trying to extend the concept, when I discovered the following weird behavior. - When you use the
      Message 2 of 3 , Oct 11, 1999
        Detlef's got some good ideas here. I was messing around, trying to extend the concept, when I discovered the following weird behavior.

        - When you use the regexp [0-9]+ in &xequal, it doesn't work at all.
        - When you use [0-9]*, it works like [0-9]+, not matching the empty string but matching a string of digits.
        - When you use these in query-replace-string, they work "correctly," i.e., '+' matches one or more of a char, '*' matches empty strings and any number of a char.

        Here's my example. (The commented-out regexp is supposed to match lines like
        " 13. Reinstall Windows again". The one left in matches lines like "123" only.)

        define-macro renumber
        set-alpha-mark "z"
        backward-line
        ; !if &xsequal @wl " *[0-9]+\..*" ; <--- what I want to do
        !if &xsequal @wl "[0-9]*" ; <-- works like [0-9]+
        set-variable #l0 &add 0 @wl
        ml-write &spr "* found number %d" #l0
        !endif
        goto-alpha-mark "z"
        !emacro
        !force global-bind-key renumber "C-x n"


        Any ideas?

        -Th


        p.s. While we're discussing regexps, why are the \h, \l etc. functions not supported? These would be useful. My (admittedly limited) Unix in a Nutshell book documents these as being part of GNU regexp (they make letters/words uppercase/lowercase).
      • Steven Phillips,,,
        ... This is a user error. As with most systems there are 2 types of regex , the complex gnu regex used by search and replace which is what you think &xseq
        Message 3 of 3 , Oct 12, 1999
          > - When you use the regexp [0-9]+ in &xequal, it doesn't work at all.
          > - When you use [0-9]*, it works like [0-9]+, not matching the empty string but matching a string of digits.
          > - When you use these in query-replace-string, they work "correctly," i.e., '+' matches one or more of a char, '*' matches empty strings and any number of a char.
          >

          This is a user error. As with most systems there are 2 types of 'regex', the
          complex gnu regex used by search and replace which is what you think &xseq is,
          and the file-system regex where '*' is any number of any character (i.e. ".*"
          in gnu regex) and '?' is any char. Which is why [0-9]* appears to work and
          [0-9]+ doesn't.

          Having said that, when I implemented the &xse regexcmp function I did not have
          access to a simple interface to a gnu-regex style engine. I now do, so I'm
          tempted to move everything over to gnu-regex. This means that variables like
          $spell-word, $buffer-names, $command-names etc will be gnu-regex compliant.
          Can anyone see any reason why I shouldn't?

          > p.s. While we're discussing regexps, why are the \h, \l etc. functions not
          > supported? These would be useful. My (admittedly limited) Unix in a Nutshell
          > book documents these as being part of GNU regexp (they make letters/words
          > uppercase/lowercase).

          I'm afraid they are not gnu Emacs regex compliant, only \b (word boundary) and
          \w (word char) are strictly gnu, there are also "\s " and \s- for a white
          space and \sw for a word char. I also added the posix style character classes,
          i.e. [[:upper:]] or [^[:upper:][:lower:]] (horrible I know but they are the
          standard.

          We could add the \h & \l (what others are missing??), after all, this is not
          gnu Emacs. But I am concerned that they will conflict with existing \?
          characters, such as \n or \t etc. So which ones are missing? And does anyone
          object to adding them?

          Steve
        Your message has been successfully submitted and would be delivered to recipients shortly.