* bug#40338: 27.0.60; c-fill-paragraph and after-change-functions
@ 2020-03-31 1:27 Yuan Fu
2020-03-31 1:56 ` Noam Postavsky
2020-03-31 17:09 ` bug#40338: Fwd: " Yuan Fu
0 siblings, 2 replies; 4+ messages in thread
From: Yuan Fu @ 2020-03-31 1:27 UTC (permalink / raw)
To: 40338
[-- Attachment #1: Type: text/plain, Size: 876 bytes --]
Background: I use eglot with c-mode and every time I use c-fill-paragraph, eglot breaks—it reports a syntax error when there isn’t. It seems that eglot’s image of the buffer’s content (or what it thinks is in the buffer) is corrupted. I can fix this by revert-buffer. I have a feeling that this has something to do with after-change-functions because that’s the only way eglot gets updated with buffer changes. So I setup an experiment. It goes like this:
Open track.el and eval-buffer; then go to test.c and M-: (mytrack); then open the tracking buffer “trackbuf” in another window. Now if you edit in test.c, the change should be reflected in trackbuf. Now try M-q. Both buffer ends up in a corrupted state.
I tried to look at c-fill-paragraph but it’s too complicated. I hope someone with more expertise in c-mode could give some insight.
Yuan
[-- Attachment #2: track.el --]
[-- Type: application/octet-stream, Size: 511 bytes --]
(defun mytrack ()
(let ((content (buffer-string)))
(with-current-buffer (get-buffer-create "trackbuf")
(erase-buffer)
(insert content))
(add-hook 'after-change-functions #'mytrack-hook nil t)))
(defun mytrack-hook (beg end len)
(if (> len 0)
;; delete
(with-current-buffer trackbuf
(delete-region beg (+ beg len)))
;; insert
(let ((content (buffer-substring beg end)))
(with-current-buffer trackbuf
(goto-char beg)
(insert content)))))
[-- Attachment #3: test.c --]
[-- Type: application/octet-stream, Size: 696 bytes --]
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include "dep.h"
// Writes data to the given channel
// This is a blocking call i.e., the function only returns on a successful completion of send
// In case the channel is full, the function waits till the channel has space to write the new data
// Returns SUCCESS for successfully writing data to the channel,
// CLOSED_ERROR if the channel is closed, and
// GEN_ERROR on encountering any other generic error of any sort
int add(int x, int y) {
return x + y;
}
int main() {
char arr[4];
arr[0] = 'a';
arr[1] = 'b';
arr[2] = 'c';
arr[3] = 'd';
int x = 1;
int y = -1;
int z = 0;
int j = add(z, y);
return 0;
}
[-- Attachment #4: Type: text/plain, Size: 3311 bytes --]
In GNU Emacs 27.0.60 (build 1, x86_64-apple-darwin19.3.0, NS appkit-1894.30 Version 10.15.3 (Build 19D76))
of 2020-02-25 built on missSilver
Repository revision: f27187f963e9e36435b508e29256e048799e0ff2
Repository branch: emacs-27
Windowing system distributor 'Apple', version 10.3.1894
System Description: Mac OS X 10.15.4
Recent messages:
Wrote /Users/yuan/Desktop/test.c
C-= is undefined
scroll-up-command: End of buffer
Mark set [3 times]
Saving file /Users/yuan/Desktop/track.el...
Wrote /Users/yuan/Desktop/track.el
mytrack-hook
(mytrack-hook)
save-current-buffer: Args out of range: #<buffer trackbuf>, 421, 422
Undo
(mytrack-hook)
Configured using:
'configure --with-modules --with-pdumper=yes
--oldincludedir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2/'
Configured features:
RSVG GLIB NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS XIM
NS MODULES THREADS PDUMPER LCMS2
Important settings:
value of $LC_CTYPE: UTF-8
value of $LANG: en_CN.UTF-8
locale-coding-system: utf-8-unix
Major mode: C/*l
Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
abbrev-mode: t
Load-path shadows:
None found.
Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml mml-sec password-cache epa derived epg epg-config
gnus-util rmail rmail-loaddefs text-property-search seq byte-opt gv
bytecomp byte-compile cconv mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils time-date subr-x cc-mode
cc-fonts easymenu cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine
cc-vars cc-defs cl-loaddefs cl-lib tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel term/ns-win ns-win
ucs-normalize mule-util term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode
lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
timer select scroll-bar mouse jit-lock font-lock syntax facemenu
font-core term/tty-colors frame minibuffer cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads kqueue cocoa ns
lcms2 multi-tty make-network-process emacs)
Memory information:
((conses 16 70716 8607)
(symbols 48 8390 1)
(strings 32 21585 1417)
(string-bytes 1 808085)
(vectors 16 12103)
(vector-slots 8 152019 12686)
(floats 8 25 62)
(intervals 56 999 22)
(buffers 1000 16))
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#40338: 27.0.60; c-fill-paragraph and after-change-functions
2020-03-31 1:27 bug#40338: 27.0.60; c-fill-paragraph and after-change-functions Yuan Fu
@ 2020-03-31 1:56 ` Noam Postavsky
2020-03-31 15:27 ` Yuan Fu
2020-03-31 17:09 ` bug#40338: Fwd: " Yuan Fu
1 sibling, 1 reply; 4+ messages in thread
From: Noam Postavsky @ 2020-03-31 1:56 UTC (permalink / raw)
To: Yuan Fu; +Cc: 40338
Yuan Fu <casouri@gmail.com> writes:
> (defun mytrack-hook (beg end len)
> (if (> len 0)
> ;; delete
> (with-current-buffer trackbuf
> (delete-region beg (+ beg len)))
> ;; insert
> (let ((content (buffer-substring beg end)))
> (with-current-buffer trackbuf
> (goto-char beg)
> (insert content)))))
I'm not very familiar with either eglot or cc-mode, but I can say the
problem in your example lies with mytrack-hook: there can be kinds of
changes other than just pure delete or insert (replace, for example).
It can be fixed like this:
(defun mytrack-hook (beg end len)
(when (> len 0)
;; Delete old text.
(with-current-buffer "trackbuf"
(delete-region beg (+ beg len))))
;; Insert new text.
(let ((content (buffer-substring beg end)))
(with-current-buffer "trackbuf"
(goto-char beg)
(insert content))))
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#40338: 27.0.60; c-fill-paragraph and after-change-functions
2020-03-31 1:56 ` Noam Postavsky
@ 2020-03-31 15:27 ` Yuan Fu
0 siblings, 0 replies; 4+ messages in thread
From: Yuan Fu @ 2020-03-31 15:27 UTC (permalink / raw)
To: Noam Postavsky; +Cc: 40338
> On Mar 30, 2020, at 9:56 PM, Noam Postavsky <npostavs@gmail.com> wrote:
>
> Yuan Fu <casouri@gmail.com> writes:
>
>> (defun mytrack-hook (beg end len)
>> (if (> len 0)
>> ;; delete
>> (with-current-buffer trackbuf
>> (delete-region beg (+ beg len)))
>> ;; insert
>> (let ((content (buffer-substring beg end)))
>> (with-current-buffer trackbuf
>> (goto-char beg)
>> (insert content)))))
>
> I'm not very familiar with either eglot or cc-mode, but I can say the
> problem in your example lies with mytrack-hook: there can be kinds of
> changes other than just pure delete or insert (replace, for example).
> It can be fixed like this:
>
> (defun mytrack-hook (beg end len)
> (when (> len 0)
> ;; Delete old text.
> (with-current-buffer "trackbuf"
> (delete-region beg (+ beg len))))
> ;; Insert new text.
> (let ((content (buffer-substring beg end)))
> (with-current-buffer "trackbuf"
> (goto-char beg)
> (insert content))))
>
Thank you. Indeed this works. Maybe the problem is not in c-fill-paragraph.
Yuan
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#40338: Fwd: bug#40338: 27.0.60; c-fill-paragraph and after-change-functions
2020-03-31 1:27 bug#40338: 27.0.60; c-fill-paragraph and after-change-functions Yuan Fu
2020-03-31 1:56 ` Noam Postavsky
@ 2020-03-31 17:09 ` Yuan Fu
1 sibling, 0 replies; 4+ messages in thread
From: Yuan Fu @ 2020-03-31 17:09 UTC (permalink / raw)
To: 40338-done
[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]
> Begin forwarded message:
>
> From: Yuan Fu <casouri@gmail.com>
> Subject: Re: bug#40338: 27.0.60; c-fill-paragraph and after-change-functions
> Date: March 31, 2020 at 11:27:23 AM GMT-4
> To: Noam Postavsky <npostavs@gmail.com>
> Cc: 40338@debbugs.gnu.org
>
>
>
>> On Mar 30, 2020, at 9:56 PM, Noam Postavsky <npostavs@gmail.com> wrote:
>>
>> Yuan Fu <casouri@gmail.com> writes:
>>
>>> (defun mytrack-hook (beg end len)
>>> (if (> len 0)
>>> ;; delete
>>> (with-current-buffer trackbuf
>>> (delete-region beg (+ beg len)))
>>> ;; insert
>>> (let ((content (buffer-substring beg end)))
>>> (with-current-buffer trackbuf
>>> (goto-char beg)
>>> (insert content)))))
>>
>> I'm not very familiar with either eglot or cc-mode, but I can say the
>> problem in your example lies with mytrack-hook: there can be kinds of
>> changes other than just pure delete or insert (replace, for example).
>> It can be fixed like this:
>>
>> (defun mytrack-hook (beg end len)
>> (when (> len 0)
>> ;; Delete old text.
>> (with-current-buffer "trackbuf"
>> (delete-region beg (+ beg len))))
>> ;; Insert new text.
>> (let ((content (buffer-substring beg end)))
>> (with-current-buffer "trackbuf"
>> (goto-char beg)
>> (insert content))))
>>
>
> Thank you. Indeed this works. Maybe the problem is not in c-fill-paragraph.
>
> Yuan
[-- Attachment #2: Type: text/html, Size: 4570 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-03-31 17:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-31 1:27 bug#40338: 27.0.60; c-fill-paragraph and after-change-functions Yuan Fu
2020-03-31 1:56 ` Noam Postavsky
2020-03-31 15:27 ` Yuan Fu
2020-03-31 17:09 ` bug#40338: Fwd: " Yuan Fu
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.