all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Best way to get buffer changes in a program?
@ 2014-03-18  0:02 Thorsten Jolitz
  2014-03-18  6:40 ` Andreas Röhler
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Jolitz @ 2014-03-18  0:02 UTC (permalink / raw)
  To: help-gnu-emacs


Hi List, 

there are many ways to track and visualize changes in Emacs (see
e.g. http://www.emacswiki.org/emacs/TrackChanges). 

However, I would like to get non-interactively a list of lines (or
positions) in the buffer that changed after the last command - how to I
do that? Is is somehow possible to determine in a program that calls
other functions that insert text which new lines have been inserted (when
a buffer increased in size after a command was executed)?

Thanks in advance for any hints.

-- 
cheers,
Thorsten





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

* Re: Best way to get buffer changes in a program?
  2014-03-18  0:02 Best way to get buffer changes in a program? Thorsten Jolitz
@ 2014-03-18  6:40 ` Andreas Röhler
  2014-03-18 12:28   ` Thorsten Jolitz
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Röhler @ 2014-03-18  6:40 UTC (permalink / raw)
  To: help-gnu-emacs

Am 18.03.2014 01:02, schrieb Thorsten Jolitz:
>
> Hi List,
>
> there are many ways to track and visualize changes in Emacs (see
> e.g. http://www.emacswiki.org/emacs/TrackChanges).
>
> However, I would like to get non-interactively a list of lines (or
> positions) in the buffer that changed after the last command - how to I
> do that? Is is somehow possible to determine in a program that calls
> other functions that insert text which new lines have been inserted (when
> a buffer increased in size after a command was executed)?
>
> Thanks in advance for any hints.
>

You could start from ediff-regions-... running at alist of functions - all that against a list of original buffers.



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

* Re: Best way to get buffer changes in a program?
  2014-03-18  6:40 ` Andreas Röhler
@ 2014-03-18 12:28   ` Thorsten Jolitz
  2014-03-18 16:44     ` Thorsten Jolitz
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Jolitz @ 2014-03-18 12:28 UTC (permalink / raw)
  To: help-gnu-emacs

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

> Am 18.03.2014 01:02, schrieb Thorsten Jolitz:
>>
>> Hi List,
>>
>> there are many ways to track and visualize changes in Emacs (see
>> e.g. http://www.emacswiki.org/emacs/TrackChanges).
>>
>> However, I would like to get non-interactively a list of lines (or
>> positions) in the buffer that changed after the last command - how to I
>> do that? Is is somehow possible to determine in a program that calls
>> other functions that insert text which new lines have been inserted (when
>> a buffer increased in size after a command was executed)?
>>
>> Thanks in advance for any hints.
>>
>
> You could start from ediff-regions-... running at alist of functions -
> all that against a list of original buffers.

Thanks for bringing me on the right track, after quite a lot of research in
the ediff libraries I found this low-level non-interactive function that
gives me the line numbers I need:

,-------------------------------------------------------------------------
| ;; Run the diff program on FILE1 and FILE2 and put the output in
| ;; DIFF-BUFFER Return the size of DIFF-BUFFER The return code isn't used
| ;; in the program at present.
| 
| (defun ediff-make-diff2-buffer (diff-buffer file1 file2) ...)
`-------------------------------------------------------------------------

-- 
cheers,
Thorsten




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

* Re: Best way to get buffer changes in a program?
  2014-03-18 12:28   ` Thorsten Jolitz
@ 2014-03-18 16:44     ` Thorsten Jolitz
  0 siblings, 0 replies; 4+ messages in thread
From: Thorsten Jolitz @ 2014-03-18 16:44 UTC (permalink / raw)
  To: help-gnu-emacs

Thorsten Jolitz <tjolitz@gmail.com> writes:

> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
>
>> Am 18.03.2014 01:02, schrieb Thorsten Jolitz:
>>>
>>> Hi List,
>>>
>>> there are many ways to track and visualize changes in Emacs (see
>>> e.g. http://www.emacswiki.org/emacs/TrackChanges).
>>>
>>> However, I would like to get non-interactively a list of lines (or
>>> positions) in the buffer that changed after the last command - how to I
>>> do that? Is is somehow possible to determine in a program that calls
>>> other functions that insert text which new lines have been inserted
>>> (when
>>> a buffer increased in size after a command was executed)?
>>>
>>> Thanks in advance for any hints.
>>>
>>
>> You could start from ediff-regions-... running at alist of functions -
>> all that against a list of original buffers.
>
> Thanks for bringing me on the right track, after quite a lot of research in
> the ediff libraries I found this low-level non-interactive function that
> gives me the line numbers I need:
>
> ,-------------------------------------------------------------------------
> | ;; Run the diff program on FILE1 and FILE2 and put the output in
> | ;; DIFF-BUFFER Return the size of DIFF-BUFFER The return code isn't used
> | ;; in the program at present.
> | 
> | (defun ediff-make-diff2-buffer (diff-buffer file1 file2) ...)
> `-------------------------------------------------------------------------

Just for the record, although I doubt that this is a frequently
requested functionality, this is what I finally came up with to get the
line numbers of the lines that are in file A but not in file B. 

#+begin_src emacs-lisp

(defun omm-get-diff-lines (buf-or-file1 buf-or-file2 &optional exec-diff-program)
  "Get line-number of added lines in diff of file args.

BUF-OR-FILE1 should be the file (or its visiting buffer) where
new lines have been added, BUF-OR-FILE2 the smaller original
file (or its visiting buffer).

Optional string argument EXEC-DIFF-PROGRAM defaults to \"diff\"
and should be an executable shell-command."
  (let* ((file1 (cond
		 ((file-readable-p buf-or-file1)
		  buffer-or-file1)
		 ((file-readable-p
		   (buffer-file-name (get-buffer buf-or-file1)))
		  (buffer-file-name (get-buffer buf-or-file1)))
		 (t (error
		     "%s not a file (visiting buffer)"
		     buf-or-file1))))
	 (file2 (cond
		 ((file-readable-p buf-or-file2)
		  buffer-or-file2)
		 ((file-readable-p
		   (buffer-file-name (get-buffer buf-or-file2)))
		  (buffer-file-name (get-buffer buf-or-file2)))
		 (t (error
		     "%s not a file (visiting buffer)"
		     buf-or-file2))))
	 (diff-prg (or (org-string-nw-p exec-diff-program)
		       "diff"))
	 (diff-lst (split-string
		    (shell-command-to-string
		     (format "%s %s %s" diff-prg file1 file2))
		    "\\(---\\|^<.*$\\|^>.*\\|\\\n\\)")))
    (mapcar (lambda (--pair)
	      (split-string (cadr --pair) ","))
	    (mapcar (lambda (--diff)
		      (split-string --diff "a"))
		    (setq diff-lst
			  (remove-if
			   (lambda (--strg)
			     (or (not (org-string-nw-p --strg))
				 (not (member
				       "a"
				       (split-string --strg "")))))
			   diff-lst))))))
#+end_src

-- 
cheers,
Thorsten




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

end of thread, other threads:[~2014-03-18 16:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-18  0:02 Best way to get buffer changes in a program? Thorsten Jolitz
2014-03-18  6:40 ` Andreas Röhler
2014-03-18 12:28   ` Thorsten Jolitz
2014-03-18 16:44     ` Thorsten Jolitz

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.