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

Re: [jasspa] Re: Diff file hook mode (first try)

Expand Messages
  • Jon Green
    ... Hi Pedro, Below is the final version. This fixes the item-list (f6/esc-f6) when running in a normal diff mode (rather than with the patch options). I would
    Message 1 of 6 , Oct 20, 2009
    • 0 Attachment
      azynheira wrote:
      > Hi All,
      > This got just fantastic :-)
      >
      > Thanks a lot,
      > Pedro

      Hi Pedro,

      Below is the final version. This fixes the item-list (f6/esc-f6) when running in a normal diff mode (rather than with the patch options).

      I would also suggest that the M-x diff command in tools.emf should have wrapping disabled by changing the ipipe parameter.

      cd /home/jon/.jasspa/
      gdiff --context --minimal --ignore-space-change --recursive "/home/jon/.jasspa/tools.emf~" "/home/jon/.jasspa/tools.emf"

      *** /home/jon/.jasspa/tools.emf~ 2009-10-20 14:56:33.500554000 +0100
      --- /home/jon/.jasspa/tools.emf 2009-10-20 14:56:38.626295000 +0100
      ***************
      *** 120,126 ****
      set-variable #l1 &rep #l1 "/" "\\"
      set-variable #l1 &xrep #l1 "\\\\$" ""
      !endif
      ! 4 ipipe-shell-command &spr "%s%s \"%s\" \"%s\"" %diff-com &cond &band @# 2 " -r" "" #l0 #l1 "*diff*"
      !force popup-window "*diff*"
      !emacro
      define-macro diff-changes
      --- 120,126 ----
      set-variable #l1 &rep #l1 "/" "\\"
      set-variable #l1 &xrep #l1 "\\\\$" ""
      !endif
      ! 0x204 ipipe-shell-command &spr "%s%s \"%s\" \"%s\"" %diff-com &cond &band @# 2 " -r" "" #l0 #l1 "*diff*"
      !force popup-window "*diff*"
      !emacro
      define-macro diff-changes
      [EXIT 1]

      We will also need to change "me.emf" to add:

      -1 add-file-hook "^diff " fhook-diff

      for the time being this can be performed in <user.emf>.

      It is noted that the item list will not be quite right when there is a space in the directory or file name. I am not sure how to get around this at the moment but will have to
      think about it.

      Anyway nice idea and definitely something that I will be using.

      Thanks
      Jon.

      >>> FILE START hkdiff.emf
      ; -!- emf -!-
      ; This is part of the JASSPA MicroEmacs macro files
      ; Copyright (C) 2000-2009 JASSPA (www.jasspa.com)
      ; See the file me.emf for copying and conditions.
      ;
      ; Created: Wed Aug 23 2000
      ; Synopsis: Hilighting for diff files
      ; Authors: Jon Green + Pedro Gomes
      ;
      ; Notes:
      ; This has been extrapolated from the tools.emf file that originally
      ; handled the diff utility and associated hilighting.
      ;
      ; 2009-10-20 Pedro Gomes - Extensions for patch files
      ; - Handle patch files i.e. % gdiff -Naur me090909 me091011 > patch_file.patch
      ; - Extentions for next/previous difference and previous/next file.
      ; - Patch files detected with: -1 add-file-hook "^diff " fhook-diff
      ;
      define-macro fhook-diff
      ; Set up the buffer modes
      @# buffer-init "diff"
      -1 buffer-mode "time"
      !if &band .hilight.flags 0x02
      set-variable $buffer-hilight .hilight.diff
      !endif
      buffer-init-hooks
      !emacro

      ; Setup the buffer
      set-variable .fhook-diff.name "Differences File"
      set-variable .fhook-diff.setup ® "/history/fhook/diff" "Ughpo"
      set-variable .fhook-diff.setup-mask "aeghmpo1"
      set-variable .fhook-diff.command-0 "|btho||diff-next-change|C-down|\HNext change||"
      set-variable .fhook-diff.command-1 "|btho||diff-previous-change|C-up|\HPrevious change||"
      set-variable .fhook-diff.command-2 "|btho||diff-next-file|C-right|Next file||"
      set-variable .fhook-diff.command-3 "|btho||diff-previous-file|C-left|Previous file||"
      ; Setup item-list
      set-variable .fhook-diff.item-list-s1 "^diff\\(\\s+-[^\\s]*\\)*\\s*\\([^\\s]*\\)"
      set-variable .fhook-diff.item-list-r1 "File \ecB\\2\ecA"
      set-variable .fhook-diff.item-list-s2 "^@@\\s+\\(.*\\)\\s+@@$"
      set-variable .fhook-diff.item-list-r2 "Diff \ecB\\1\ecA"
      set-variable .fhook-diff.item-list-s3 "^---\\s+\\([0-9]+,[0-9]+\\)\\s+---"
      set-variable .fhook-diff.item-list-r3 "Diff \ecB\\1\ecA"
      set-variable .fhook-diff.item-list-s4 "^Only[^:]*:\\s*\\(.*\\)\\s*$"
      set-variable .fhook-diff.item-list-r4 "Add/Del \ecB\\1\ecA"

      !if ¬ &exi .hilight.diff
      set-variable .hilight.diff &pinc .hilight.next 1
      !endif

      !if &band .hilight.flags 0x02
      0 hilight .hilight.diff 0 $global-scheme
      ; Gnu diff utility, uses --context
      hilight .hilight.diff 0x102 "!" .scheme.no1
      hilight .hilight.diff 0x102 "+" .scheme.no1
      hilight .hilight.diff 0x102 "-" .scheme.no1
      ; Regular diff utility. May be a bit too colored !!
      hilight .hilight.diff 0x102 "<" .scheme.no2
      hilight .hilight.diff 0x102 ">" .scheme.prepro
      ; Patch files GNU diff -Naur old new > file.patch
      hilight .hilight.diff 0x102 "diff" .scheme.function
      hilight .hilight.diff 0x102 "@@" .scheme.keyword
      ; Common
      hilight .hilight.diff 0x102 "*\\*\\*\\*" .scheme.keyword
      hilight .hilight.diff 0x102 "*\\*\\*" .scheme.no2
      hilight .hilight.diff 0x102 "--- " .scheme.prepro
      hilight .hilight.diff 0x102 "Only" .scheme.comment
      hilight .hilight.diff 0x102 "Files" .scheme.comment
      !endif
      ; Find the next file
      0 define-macro diff-next-file
      !if &les @# 0
      !if &equ $window-line 1
      end-of-buffer
      !endif
      !elif &seq @wc ""
      beginning-of-buffer
      !endif
      !force search-forward "^diff "
      !if ¬ $status
      ml-write "[No more files]"
      !bell
      !abort
      !endif
      recenter
      !emacro
      ; Find the previous file
      0 define-macro diff-previous-file
      !if &les @# 0
      !if &equ $window-line 1
      end-of-buffer
      !endif
      !elif &seq @wc ""
      beginning-of-buffer
      !endif
      !force search-backward "^diff "
      !if ¬ $status
      ml-write "[No more files]"
      !bell
      !abort
      !endif
      recenter
      !emacro
      ; Find the next change
      0 define-macro diff-next-change
      !if &les @# 0
      !if &equ $window-line 1
      end-of-buffer
      !endif
      !elif &seq @wc ""
      beginning-of-buffer
      !endif
      !force search-forward "^\\(@@.*@@\\)\\|\\(--- [0-9]*,[0-9]* ---\\)"
      !if ¬ $status
      ml-write "[No more differences]"
      !bell
      !abort
      !endif
      recenter
      !emacro
      ; Find the previous change
      0 define-macro diff-previous-change
      !if &les @# 0
      !if &equ $window-line 1
      end-of-buffer
      !endif
      !elif &seq @wc ""
      beginning-of-buffer
      !endif
      !force search-backward "^\\(@@.*@@\\)\\|\\(--- [0-9]*,[0-9]* ---\\)"
      !if ¬ $status
      ml-write "[No more differences]"
      !bell
      !abort
      !endif
      recenter
      !emacro

      buffer-init-fhook "diff"
      <<< FILE END hkdiff.emf
    • Jon Green
      ... A small correction to the buffer modes. I needed to clean out the original manual buffer setting and use the more conventional buffer setup. This one is a
      Message 2 of 6 , Oct 20, 2009
      • 0 Attachment
        Jon Green wrote:
        > azynheira wrote:
        >> Hi All,
        >> This got just fantastic :-)
        >>
        >> Thanks a lot,
        >> Pedro
        >
        > Hi Pedro,
        >
        > Below is the final version. This fixes the item-list (f6/esc-f6) when running in a normal diff mode (rather than with the patch options).
        >
        > I would also suggest that the M-x diff command in tools.emf should have wrapping disabled by changing the ipipe parameter.
        >
        > cd /home/jon/.jasspa/
        > gdiff --context --minimal --ignore-space-change --recursive "/home/jon/.jasspa/tools.emf~" "/home/jon/.jasspa/tools.emf"
        >
        > *** /home/jon/.jasspa/tools.emf~ 2009-10-20 14:56:33.500554000 +0100
        > --- /home/jon/.jasspa/tools.emf 2009-10-20 14:56:38.626295000 +0100
        > ***************
        > *** 120,126 ****
        > set-variable #l1 &rep #l1 "/" "\\"
        > set-variable #l1 &xrep #l1 "\\\\$" ""
        > !endif
        > ! 4 ipipe-shell-command &spr "%s%s \"%s\" \"%s\"" %diff-com &cond &band @# 2 " -r" "" #l0 #l1 "*diff*"
        > !force popup-window "*diff*"
        > !emacro
        > define-macro diff-changes
        > --- 120,126 ----
        > set-variable #l1 &rep #l1 "/" "\\"
        > set-variable #l1 &xrep #l1 "\\\\$" ""
        > !endif
        > ! 0x204 ipipe-shell-command &spr "%s%s \"%s\" \"%s\"" %diff-com &cond &band @# 2 " -r" "" #l0 #l1 "*diff*"
        > !force popup-window "*diff*"
        > !emacro
        > define-macro diff-changes
        > [EXIT 1]
        >
        > We will also need to change "me.emf" to add:
        >
        > -1 add-file-hook "^diff " fhook-diff
        >
        > for the time being this can be performed in <user.emf>.
        >
        > It is noted that the item list will not be quite right when there is a space in the directory or file name. I am not sure how to get around this at the moment but will have to
        > think about it.
        >
        > Anyway nice idea and definitely something that I will be using.
        >
        > Thanks
        > Jon.
        >

        A small correction to the buffer modes.
        I needed to clean out the original manual buffer setting and use the more conventional buffer setup.
        This one is a little cleaner than the last with respect to the buffer configuration.

        Jon.

        >>> START FILE hkdiff.emf
        ; -!- emf -!-
        ; This is part of the JASSPA MicroEmacs macro files
        ; Copyright (C) 2000-2009 JASSPA (www.jasspa.com)
        ; See the file me.emf for copying and conditions.
        ;
        ; Created: Wed Aug 23 2000
        ; Synopsis: Hilighting for diff files
        ; Authors: Jon Green + Pedro Gomes
        ;
        ; Notes:
        ; This has been extrapolated from the tools.emf file that originally
        ; handled the diff utility and associated hilighting.
        ;
        ; 2009-10-20 Pedro Gomes - Extensions for patch files
        ; - Handle patch files i.e. % gdiff -Naur me090909 me091011 > patch_file.patch
        ; - Extentions for next/previous difference and previous/next file.
        ; - Patch files detected with: -1 add-file-hook "^diff " fhook-diff
        ;
        define-macro fhook-diff
        ; Set up the buffer modes
        @# buffer-init "diff"
        buffer-init-hooks
        !emacro

        ; Setup the buffer
        set-variable .fhook-diff.name "Differences File"
        set-variable .fhook-diff.setup ® "/history/fhook/diff" "UXghpo"
        set-variable .fhook-diff.setup-mask "aeghmpo"
        set-variable .fhook-diff.command-0 "|btho||diff-next-change|C-down|\HNext change||"
        set-variable .fhook-diff.command-1 "|btho||diff-previous-change|C-up|\HPrevious change||"
        set-variable .fhook-diff.command-2 "|btho||diff-next-file|C-right|Next file||"
        set-variable .fhook-diff.command-3 "|btho||diff-previous-file|C-left|Previous file||"
        ; Setup item-list
        set-variable .fhook-diff.item-list-s1 "^diff\\(\\s+-[^\\s]*\\)*\\s*\\([^\\s]*\\)"
        set-variable .fhook-diff.item-list-r1 "File \ecB\\2\ecA"
        set-variable .fhook-diff.item-list-s2 "^@@\\s+\\(.*\\)\\s+@@"
        set-variable .fhook-diff.item-list-r2 "Diff \ecB\\1\ecA"
        set-variable .fhook-diff.item-list-s3 "^---\\s+\\([0-9]+,[0-9]+\\)\\s+---"
        set-variable .fhook-diff.item-list-r3 "Diff \ecB\\1\ecA"
        set-variable .fhook-diff.item-list-s4 "^Only[^:]*:\\s*\\(.*\\)\\s*$"
        set-variable .fhook-diff.item-list-r4 "Add/Del \ecB\\1\ecA"

        !if ¬ &exi .hilight.diff
        set-variable .hilight.diff &pinc .hilight.next 1
        !endif

        !if &and &sin "h" .fhook-diff.setup &band .hilight.flags 0x02
        0 hilight .hilight.diff 0 $global-scheme
        ; Gnu diff utility, uses --context
        hilight .hilight.diff 0x102 "!" .scheme.no1
        hilight .hilight.diff 0x102 "+" .scheme.no1
        hilight .hilight.diff 0x102 "-" .scheme.no1
        ; Regular diff utility. May be a bit too colored !!
        hilight .hilight.diff 0x102 "<" .scheme.no2
        hilight .hilight.diff 0x102 ">" .scheme.prepro
        ; Patch files GNU diff -Naur old new > file.patch
        hilight .hilight.diff 0x102 "diff" .scheme.function
        hilight .hilight.diff 0x102 "@@" .scheme.keyword
        ; Common
        hilight .hilight.diff 0x102 "*\\*\\*\\*" .scheme.keyword
        hilight .hilight.diff 0x102 "*\\*\\*" .scheme.no2
        hilight .hilight.diff 0x102 "--- " .scheme.prepro
        hilight .hilight.diff 0x102 "Only" .scheme.comment
        hilight .hilight.diff 0x102 "Files" .scheme.comment
        !endif

        ; Find the next file
        0 define-macro diff-next-file
        !if &les @# 0
        !if &equ $window-line 1
        end-of-buffer
        !endif
        !elif &seq @wc ""
        beginning-of-buffer
        !endif
        !force search-forward "^diff "
        !if ¬ $status
        ml-write "[No more files]"
        !bell
        !abort
        !endif
        recenter
        !emacro
        ; Find the previous file
        0 define-macro diff-previous-file
        !if &les @# 0
        !if &equ $window-line 1
        end-of-buffer
        !endif
        !elif &seq @wc ""
        beginning-of-buffer
        !endif
        !force search-backward "^diff "
        !if ¬ $status
        ml-write "[No more files]"
        !bell
        !abort
        !endif
        recenter
        !emacro
        ; Find the next change
        0 define-macro diff-next-change
        !if &les @# 0
        !if &equ $window-line 1
        end-of-buffer
        !endif
        !elif &seq @wc ""
        beginning-of-buffer
        !endif
        !force search-forward "^\\(@@.*@@\\)\\|\\(--- [0-9]*,[0-9]* ---\\)"
        !if ¬ $status
        ml-write "[No more differences]"
        !bell
        !abort
        !endif
        recenter
        !emacro
        ; Find the previous change
        0 define-macro diff-previous-change
        !if &les @# 0
        !if &equ $window-line 1
        end-of-buffer
        !endif
        !elif &seq @wc ""
        beginning-of-buffer
        !endif
        !force search-backward "^\\(@@.*@@\\)\\|\\(--- [0-9]*,[0-9]* ---\\)"
        !if ¬ $status
        ml-write "[No more differences]"
        !bell
        !abort
        !endif
        recenter
        !emacro

        buffer-init-fhook "diff"
        <<< END FILE hkdiff.emf
      Your message has been successfully submitted and would be delivered to recipients shortly.