Package: emacs;
Reported by: arthur.miller <at> live.com
Date: Fri, 17 Sep 2021 17:07:02 UTC
Severity: normal
Tags: moreinfo
Found in version 28.0.50
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 50646 in the body.
You can then email your comments to 50646 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
View this report as an mbox folder, status mbox, maintainer mbox
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Fri, 17 Sep 2021 17:07:02 GMT) Full text and rfc822 format available.arthur.miller <at> live.com
:bug-gnu-emacs <at> gnu.org
.
(Fri, 17 Sep 2021 17:07:02 GMT) Full text and rfc822 format available.Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: arthur.miller <at> live.com To: bug-gnu-emacs <at> gnu.org Subject: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Fri, 17 Sep 2021 19:06:04 +0200
[help-mode.el (text/plain, attachment)]
[Message part 2 (text/plain, inline)]
Bug No 1: To reproduce this bug: 1. run Emacs -Q -l /path/to/attached/help-mode.el 2. type C-x f 3. in minibuffer type: when RET The help-mode buffer that opens should show help for 'when' form, but it shows the source code for the 'pop' macro which precedes the 'when' in subr.el. You can swtich to *Messages* buffer, I have output the position and current-word at that position. Position is correct, it is the position before opening parenthesis for '(defmacro when ...'. But current-word shows 'x', which seems to be somethign from the pop macro that precedes the 'when'. You can also clicn on "subr.el' in help-mode buffer and open the source code, and then M-: (point) RET to confirm that the position is correct. The docs for 'narrow-to-defun' says the "current-defun" is one that contains the point or follows the point. However, I am getting back the one that precedes the point. Maybe it is bug elsewhere since current-word also shows 'x', which I think is wrong, but maybe I am wrong :). I am not sure what is going on here, but there seems to be a bug somewhere, in some rare case, and I think 'narrow-to-defun' is a good place to start. I haven't found any other symbol but 'when' that results in wrong form narrowed, but maybe there is one. Forward-char does not fix it, but forward-word seems to go far enough into the enclosing 'when' form so that narrow-to-defun return correct code. I have another consideration here: this is probably the same problem, but I am not sure. To reproduce, follow step 1. and 2. from the prevous. For the 3. type directory-files RET. This should insert source code for directory-files from the dired.c. And it does, but with a slight twist: it return just the body, not the function declaration and the docs. I don't think it's a big deal, since both are returned anyway, and I think I can fix it to return everything, but as a note how it works. I am not sure if it's meant to work so or not on c-sources. Notice also that the link to open the source file says "C source code" not the name of the file, as it says for .el files. The header is produced by 'help-function-def--button-function' which I have adapted in 'help--function-source' (above help-make-xref) to return the source code. I can send a patch to return the name of the file instead of the string "C source code". In GNU Emacs 28.0.50 (build 2, x86_64-pc-linux-gnu, cairo version 1.17.4) of 2021-09-15 built on pascal Repository revision: b189b6f2564f903cf271a46910ad7a5df9da6918 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12013000 System Description: Arch Linux Configured using: 'configure --with-modules --with-cairo --without-compress-install --with-x-toolkit=no --with-gnutls --without-gconf --without-xwidgets --without-toolkit-scroll-bars --without-xaw3d --without-gsettings --with-mailutils --with-native-compilation 'CFLAGS=-O2 -march=native -mtune=native'' Configured features: ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM HARFBUZZ JPEG JSON LCMS2 LIBOTF LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY INOTIFY OLDXMENU PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF X11 XDBE XIM XPM ZLIB Important settings: value of $LANG: sv_SE.UTF-8 locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t 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 indent-tabs-mode: t transient-mark-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug comp comp-cstr warnings rx cl-extra message rmc puny dired dired-loaddefs rfc822 mml mml-sec epa epg rfc6068 epg-config gnus-util rmail rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs password-cache json map text-property-search time-date subr-x 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 help-mode derived cl-loaddefs cl-lib iso-transl tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win term/common-win x-dnd 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 easymenu timer select scroll-bar mouse jit-lock font-lock syntax 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 button loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote threads dbusbind inotify lcms2 dynamic-setting font-render-setting cairo x multi-tty make-network-process native-compile emacs) Memory information: ((conses 16 90686 9107) (symbols 48 7862 1) (strings 32 21940 1868) (string-bytes 1 742230) (vectors 16 16860) (vector-slots 8 320588 16808) (floats 8 31 37) (intervals 56 240 0) (buffers 992 11))
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sat, 18 Sep 2021 14:10:01 GMT) Full text and rfc822 format available.Message #8 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Lars Ingebrigtsen <larsi <at> gnus.org> To: arthur.miller <at> live.com Cc: 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sat, 18 Sep 2021 16:09:00 +0200
arthur.miller <at> live.com writes: > To reproduce this bug: > > 1. run Emacs -Q -l /path/to/attached/help-mode.el > 2. type C-x f > 3. in minibuffer type: when RET > > The help-mode buffer that opens should show help for 'when' form, but it > shows the source code for the 'pop' macro which precedes the 'when' in > subr.el. I didn't try to reproduce this, because the attached .el file is almost 1K lines long. Do you have a simpler way to reproduce the issue you're seeing? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no
Lars Ingebrigtsen <larsi <at> gnus.org>
to control <at> debbugs.gnu.org
.
(Sat, 18 Sep 2021 14:10:02 GMT) Full text and rfc822 format available.bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sat, 18 Sep 2021 17:28:02 GMT) Full text and rfc822 format available.Message #13 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Arthur Miller <arthur.miller <at> live.com> To: Lars Ingebrigtsen <larsi <at> gnus.org> Cc: 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sat, 18 Sep 2021 19:27:22 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes: > arthur.miller <at> live.com writes: > >> To reproduce this bug: >> >> 1. run Emacs -Q -l /path/to/attached/help-mode.el >> 2. type C-x f >> 3. in minibuffer type: when RET >> >> The help-mode buffer that opens should show help for 'when' form, but it >> shows the source code for the 'pop' macro which precedes the 'when' in >> subr.el. > > I didn't try to reproduce this, because the attached .el file is almost > 1K lines long. Ok, didn't know it sloc size mattered. It is just patched help-mode.el from Emacs source. > Do you have a simpler way to reproduce the issue you're seeing? No I don't have any other way. You can try to eval the src region below; that's the patched part of help-mode.el and follow step 2 and 3. #+begin_src emacs-lisp (defcustom help-mode-inline-source t "Display inlined source code for SYMBOL in `help-mode' buffer. When enabled the source code of a symbol will be displayed inlined in the help buffer, if the source code for the symbol is available." :type 'boolean :group 'help) (defun help--function-source (fun file &optional type) "Fnd and return string to be inserted in help-mode buffer for the source code of the symbol. Used internally for `help-make-refs'." (let ((src "Source code not available.") (mode (if (eq file 'C-source) 'c-mode 'emacs-lisp-mode))) (if (eq mode 'c-mode) (setq file (help-C-file-name (indirect-function fun) 'fun)) (setq file (or file (find-lisp-object-file-name fun type)))) (when file (require 'find-func) ;; Don't use find-function-noselect because it follows ;; aliases (which fails for built-in functions). (with-temp-buffer (insert-file-contents-literally (expand-file-name file source-directory)) (let* ((location (find-function-search-for-symbol fun type file)) (position (cdr location)) (mode (if (equal (file-name-sans-extension file) ".c") 'c-mode 'emacs-lisp-mode))) (if position (progn (run-hooks 'find-function-after-hook) ;; Widen the buffer if necessary to go to this position. (when (or (< position (point-min)) (> position (point-max))) (widen)) (goto-char position) (message "pos: %s word: %s" position (current-word)) ;; narrow-to-defun sometimes return defun preceding the ;; point instead of one following the point as ;; advertised in docs. Forward-char didn't fix it, but ;; forward word seems to work. ;; (forward-char) ;; (forward-word) (narrow-to-defun t) (delay-mode-hooks (funcall mode)) (if (fboundp 'font-lock-ensure) (font-lock-ensure) (with-no-warnings (font-lock-fontify-buffer))) (setq src (buffer-string))))))) src)) (defun help-setup-xref (item interactive-p) "Invoked from commands using the \"*Help*\" buffer to install some xref info. ITEM is a (FUNCTION . ARGS) pair appropriate for recreating the help buffer after following a reference. INTERACTIVE-P is non-nil if the calling command was invoked interactively. In this case the stack of items for help buffer \"back\" buttons is cleared. This should be called very early, before the output buffer is cleared, because we want to record the \"previous\" position of point so we can restore it properly when going back." (with-current-buffer (help-buffer) (when help-xref-stack-item (push (cons (point) help-xref-stack-item) help-xref-stack) (setq help-xref-forward-stack nil)) (when interactive-p (let ((tail (nthcdr 10 help-xref-stack))) ;; Truncate the stack. (if tail (setcdr tail nil)))) (setq help-xref-stack-item item))) (defvar help-xref-following nil "Non-nil when following a help cross-reference.") ;;;###autoload (defun help-buffer () "Return the name of a buffer for inserting help. If `help-xref-following' is non-nil, this is the name of the current buffer. Signal an error if this buffer is not derived from `help-mode'. Otherwise, return \"*Help*\", creating a buffer with that name if it does not already exist." (buffer-name ;for with-output-to-temp-buffer (if (not help-xref-following) (get-buffer-create "*Help*") (unless (derived-mode-p 'help-mode) (error "Current buffer is not in Help mode")) (current-buffer)))) (defvar describe-symbol-backends `((nil ,#'fboundp ,(lambda (s _b _f) (describe-function s))) (nil ,(lambda (symbol) (or (and (boundp symbol) (not (keywordp symbol))) (get symbol 'variable-documentation))) ,#'describe-variable) ("face" ,#'facep ,(lambda (s _b _f) (describe-face s)))) "List of providers of information about symbols. Each element has the form (NAME TESTFUN DESCFUN) where: NAME is a string naming a category of object, such as \"type\" or \"face\". TESTFUN is a predicate which takes a symbol and returns non-nil if the symbol is such an object. DESCFUN is a function which takes three arguments (a symbol, a buffer, and a frame), inserts the description of that symbol in the current buffer and returns that text as well.") (defun help--function-source (fun file &optional type) "Fnd and return string to be inserted in help-mode buffer for the source code of the symbol. Used internally for `help-make-refs'." (let ((src "Source code not available.") (mode (if (eq file 'C-source) 'c-mode 'emacs-lisp-mode))) (if (eq mode 'c-mode) (setq file (help-C-file-name (indirect-function fun) 'fun)) (setq file (or file (find-lisp-object-file-name fun type)))) (when file (require 'find-func) ;; Don't use find-function-noselect because it follows ;; aliases (which fails for built-in functions). (with-temp-buffer (insert-file-contents-literally (expand-file-name file source-directory)) (let* ((location (find-function-search-for-symbol fun type file)) (position (cdr location)) (mode (if (equal (file-name-sans-extension file) ".c") 'c-mode 'emacs-lisp-mode))) (if position (progn (run-hooks 'find-function-after-hook) ;; Widen the buffer if necessary to go to this position. (when (or (< position (point-min)) (> position (point-max))) (widen)) (goto-char position) (message "pos: %s word: %s" position (current-word)) ;; narrow-to-defun sometimes return defun preceding the ;; point instead of one following the point as ;; advertised in docs. Forward-char didn't fix it, but ;; forward word seems to work. ;; (forward-char) ;; (forward-word) (narrow-to-defun t) (delay-mode-hooks (funcall mode)) (if (fboundp 'font-lock-ensure) (font-lock-ensure) (with-no-warnings (font-lock-fontify-buffer))) (setq src (buffer-string))))))) src)) ;;;###autoload (defun help-make-xrefs (&optional buffer) "Parse and hyperlink documentation cross-references in the given BUFFER. Find cross-reference information in a buffer and activate such cross references for selection with `help-follow-symbol'. Cross-references have the canonical form `...' and the type of reference may be disambiguated by the preceding word(s) used in `help-xref-symbol-regexp'. Faces only get cross-referenced if preceded or followed by the word `face'. Variables without variable documentation do not get cross-referenced, unless preceded by the word `variable' or `option'. If the variable `help-xref-mule-regexp' is non-nil, find also cross-reference information related to multilingual environment \(e.g., coding-systems). This variable is also used to disambiguate the type of reference as the same way as `help-xref-symbol-regexp'. A special reference `back' is made to return back through a stack of help buffers. Variable `help-back-label' specifies the text for that." (interactive "b") (with-current-buffer (or buffer (current-buffer)) (save-excursion (goto-char (point-min)) ;; Skip the first bit, which has already been buttonized. (forward-paragraph) (let ((old-modified (buffer-modified-p))) (let ((stab (syntax-table)) (case-fold-search t) (inhibit-read-only t)) (set-syntax-table help-mode-syntax-table) ;; The following should probably be abstracted out. (unwind-protect (progn ;; Info references (save-excursion (while (re-search-forward help-xref-info-regexp nil t) (let ((data (match-string 2))) (save-match-data (unless (string-match "^([^)]+)" data) (setq data (concat "(emacs)" data))) (setq data ;; possible newlines if para filled (replace-regexp-in-string "[ \t\n]+" " " data t t))) (help-xref-button 2 'help-info data)))) ;; Customization groups. (save-excursion (while (re-search-forward help-xref-customization-group-regexp nil t) (help-xref-button 1 'help-customization-group (intern (match-string 1))))) ;; URLs (save-excursion (while (re-search-forward help-xref-url-regexp nil t) (let ((data (match-string 1))) (help-xref-button 1 'help-url data)))) ;; Mule related keywords. Do this before trying ;; `help-xref-symbol-regexp' because some of Mule ;; keywords have variable or function definitions. (if help-xref-mule-regexp (save-excursion (while (re-search-forward help-xref-mule-regexp nil t) (let* ((data (match-string 7)) (sym (intern-soft data))) (cond ((match-string 3) ; coding system (and sym (coding-system-p sym) (help-xref-button 6 'help-coding-system sym))) ((match-string 4) ; input method (and (assoc data input-method-alist) (help-xref-button 7 'help-input-method data))) ((or (match-string 5) (match-string 6)) ; charset (and sym (charsetp sym) (help-xref-button 7 'help-character-set sym))) ((assoc data input-method-alist) (help-xref-button 7 'help-input-method data)) ((and sym (coding-system-p sym)) (help-xref-button 7 'help-coding-system sym)) ((and sym (charsetp sym)) (help-xref-button 7 'help-character-set sym))))))) ;; Quoted symbols (save-excursion (while (re-search-forward help-xref-symbol-regexp nil t) (let* ((data (match-string 8)) (sym (intern-soft data))) (if sym (cond ((match-string 3) ; `variable' &c (and (or (boundp sym) ; `variable' doesn't ensure ; it's actually bound (get sym 'variable-documentation)) (help-xref-button 8 'help-variable sym))) ((match-string 4) ; `function' &c (and (fboundp sym) ; similarly (help-xref-button 8 'help-function sym))) ((match-string 5) ; `face' (and (facep sym) (help-xref-button 8 'help-face sym))) ((match-string 6)) ; nothing for `symbol' ((match-string 7) (help-xref-button 8 'help-function-def sym)) ((cl-some (lambda (x) (funcall (nth 1 x) sym)) describe-symbol-backends) (help-xref-button 8 'help-symbol sym))))))) ;; An obvious case of a key substitution: (save-excursion (while (re-search-forward ;; Assume command name is only word and symbol ;; characters to get things like `use M-x foo->bar'. ;; Command required to end with word constituent ;; to avoid `.' at end of a sentence. "\\<M-x\\s-+\\(\\sw\\(\\sw\\|\\s_\\)*\\sw\\)" nil t) (let ((sym (intern-soft (match-string 1)))) (if (fboundp sym) (help-xref-button 1 'help-function sym))))) ;; Look for commands in whole keymap substitutions: (save-excursion ;; Make sure to find the first keymap. (goto-char (point-min)) ;; Find a header and the column at which the command ;; name will be found. ;; If the keymap substitution isn't the last thing in ;; the doc string, and if there is anything on the same ;; line after it, this code won't recognize the end of it. (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n" nil t) (let ((col (- (match-end 1) (match-beginning 1)))) (while (and (not (eobp)) ;; Stop at a pair of blank lines. (not (looking-at-p "\n\\s-*\n"))) ;; Skip a single blank line. (and (eolp) (forward-line)) (end-of-line) (skip-chars-backward "^ \t\n") (if (and (>= (current-column) col) (looking-at "\\(\\sw\\|\\s_\\)+$")) (let ((sym (intern-soft (match-string 0)))) (if (fboundp sym) (help-xref-button 0 'help-function sym)))) (forward-line))))) (set-syntax-table stab))) ;; Delete extraneous newlines at the end of the docstring (goto-char (point-max)) (while (and (not (bobp)) (bolp)) (delete-char -1)) (insert "\n") ;; get source string if needed and available (when help-mode-inline-source (insert "\nSource Code: \n") (let ((file (plist-get help-mode--current-data :file)) (fun (plist-get help-mode--current-data :symbol))) (insert (help--function-source fun file))) (insert "\n")) (when (or help-xref-stack help-xref-forward-stack) (insert "\n")) ;; Make a back-reference in this buffer if appropriate. (when help-xref-stack (help-insert-xref-button help-back-label 'help-back (current-buffer))) ;; Make a forward-reference in this buffer if appropriate. (when help-xref-forward-stack (when help-xref-stack (insert "\t")) (help-insert-xref-button help-forward-label 'help-forward (current-buffer))) (when (or help-xref-stack help-xref-forward-stack) (insert "\n"))) (set-buffer-modified-p old-modified))))) #+end_src
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sat, 18 Sep 2021 18:36:01 GMT) Full text and rfc822 format available.Message #16 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Arthur Miller <arthur.miller <at> live.com> To: Lars Ingebrigtsen <larsi <at> gnus.org> Cc: 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sat, 18 Sep 2021 20:34:51 +0200
Arthur Miller <arthur.miller <at> live.com> writes: > Lars Ingebrigtsen <larsi <at> gnus.org> writes: > >> arthur.miller <at> live.com writes: >> >>> To reproduce this bug: >>> >>> 1. run Emacs -Q -l /path/to/attached/help-mode.el >>> 2. type C-x f >>> 3. in minibuffer type: when RET >>> >>> The help-mode buffer that opens should show help for 'when' form, but it >>> shows the source code for the 'pop' macro which precedes the 'when' in >>> subr.el. >> >> I didn't try to reproduce this, because the attached .el file is almost >> 1K lines long. > > Ok, didn't know it sloc size mattered. It is just patched help-mode.el from > Emacs source. > >> Do you have a simpler way to reproduce the issue you're seeing? > > No I don't have any other way. You can try to eval the src region below; that's > the patched part of help-mode.el and follow step 2 and 3. That still looks really big. I am sorry I don't have any other way; I would have to write a separate program in that case :). I guess it is not so important either. I have only found problem with 'when', no other symbols have resulted in same, and nobody else has ever complained about this, so maybe it is so rare case that you can just dismiss and close the buffer. It is not a showstopper for me; I am just moving point one word forward so it works in 'when' case too; if I am even gonna use narrow-to-defun. > #+begin_src emacs-lisp > (defcustom help-mode-inline-source t > "Display inlined source code for SYMBOL in `help-mode' buffer. > > When enabled the source code of a symbol will be displayed inlined in > the help buffer, if the source code for the symbol is available." > :type 'boolean > :group 'help) > > (defun help--function-source (fun file &optional type) > "Fnd and return string to be inserted in help-mode buffer for the > source code of the symbol. > > Used internally for `help-make-refs'." > (let ((src "Source code not available.") > (mode (if (eq file 'C-source) 'c-mode 'emacs-lisp-mode))) > (if (eq mode 'c-mode) > (setq file (help-C-file-name (indirect-function fun) 'fun)) > (setq file (or file (find-lisp-object-file-name fun type)))) > (when file > (require 'find-func) > ;; Don't use find-function-noselect because it follows > ;; aliases (which fails for built-in functions). > (with-temp-buffer > (insert-file-contents-literally (expand-file-name file source-directory)) > (let* ((location (find-function-search-for-symbol fun type file)) > (position (cdr location)) > (mode (if (equal (file-name-sans-extension file) ".c") 'c-mode 'emacs-lisp-mode))) > (if position > (progn > (run-hooks 'find-function-after-hook) > ;; Widen the buffer if necessary to go to this position. > (when (or (< position (point-min)) > (> position (point-max))) > (widen)) > (goto-char position) > (message "pos: %s word: %s" position (current-word)) > ;; narrow-to-defun sometimes return defun preceding the > ;; point instead of one following the point as > ;; advertised in docs. Forward-char didn't fix it, but > ;; forward word seems to work. > ;; (forward-char) > ;; (forward-word) > (narrow-to-defun t) > (delay-mode-hooks (funcall mode)) > (if (fboundp 'font-lock-ensure) > (font-lock-ensure) > (with-no-warnings > (font-lock-fontify-buffer))) > (setq src (buffer-string))))))) > src)) > > (defun help-setup-xref (item interactive-p) > "Invoked from commands using the \"*Help*\" buffer to install some xref info. > > ITEM is a (FUNCTION . ARGS) pair appropriate for recreating the help > buffer after following a reference. INTERACTIVE-P is non-nil if the > calling command was invoked interactively. In this case the stack of > items for help buffer \"back\" buttons is cleared. > > This should be called very early, before the output buffer is cleared, > because we want to record the \"previous\" position of point so we can > restore it properly when going back." > (with-current-buffer (help-buffer) > (when help-xref-stack-item > (push (cons (point) help-xref-stack-item) help-xref-stack) > (setq help-xref-forward-stack nil)) > (when interactive-p > (let ((tail (nthcdr 10 help-xref-stack))) > ;; Truncate the stack. > (if tail (setcdr tail nil)))) > (setq help-xref-stack-item item))) > > (defvar help-xref-following nil > "Non-nil when following a help cross-reference.") > > ;;;###autoload > (defun help-buffer () > "Return the name of a buffer for inserting help. > If `help-xref-following' is non-nil, this is the name of the > current buffer. Signal an error if this buffer is not derived > from `help-mode'. > Otherwise, return \"*Help*\", creating a buffer with that name if > it does not already exist." > (buffer-name ;for with-output-to-temp-buffer > (if (not help-xref-following) > (get-buffer-create "*Help*") > (unless (derived-mode-p 'help-mode) > (error "Current buffer is not in Help mode")) > (current-buffer)))) > > (defvar describe-symbol-backends > `((nil ,#'fboundp ,(lambda (s _b _f) (describe-function s))) > (nil > ,(lambda (symbol) > (or (and (boundp symbol) (not (keywordp symbol))) > (get symbol 'variable-documentation))) > ,#'describe-variable) > ("face" ,#'facep ,(lambda (s _b _f) (describe-face s)))) > "List of providers of information about symbols. > Each element has the form (NAME TESTFUN DESCFUN) where: > NAME is a string naming a category of object, such as \"type\" or \"face\". > TESTFUN is a predicate which takes a symbol and returns non-nil if the > symbol is such an object. > DESCFUN is a function which takes three arguments (a symbol, a buffer, > and a frame), inserts the description of that symbol in the current buffer > and returns that text as well.") > > (defun help--function-source (fun file &optional type) > "Fnd and return string to be inserted in help-mode buffer for the > source code of the symbol. > > Used internally for `help-make-refs'." > (let ((src "Source code not available.") > (mode (if (eq file 'C-source) 'c-mode 'emacs-lisp-mode))) > (if (eq mode 'c-mode) > (setq file (help-C-file-name (indirect-function fun) 'fun)) > (setq file (or file (find-lisp-object-file-name fun type)))) > (when file > (require 'find-func) > ;; Don't use find-function-noselect because it follows > ;; aliases (which fails for built-in functions). > (with-temp-buffer > (insert-file-contents-literally (expand-file-name file source-directory)) > (let* ((location (find-function-search-for-symbol fun type file)) > (position (cdr location)) > (mode (if (equal (file-name-sans-extension file) ".c") 'c-mode 'emacs-lisp-mode))) > (if position > (progn > (run-hooks 'find-function-after-hook) > ;; Widen the buffer if necessary to go to this position. > (when (or (< position (point-min)) > (> position (point-max))) > (widen)) > (goto-char position) > (message "pos: %s word: %s" position (current-word)) > ;; narrow-to-defun sometimes return defun preceding the > ;; point instead of one following the point as > ;; advertised in docs. Forward-char didn't fix it, but > ;; forward word seems to work. > ;; (forward-char) > ;; (forward-word) > (narrow-to-defun t) > (delay-mode-hooks (funcall mode)) > (if (fboundp 'font-lock-ensure) > (font-lock-ensure) > (with-no-warnings > (font-lock-fontify-buffer))) > (setq src (buffer-string))))))) > src)) > > ;;;###autoload > (defun help-make-xrefs (&optional buffer) > "Parse and hyperlink documentation cross-references in the given BUFFER. > > Find cross-reference information in a buffer and activate such cross > references for selection with `help-follow-symbol'. Cross-references have > the canonical form `...' and the type of reference may be > disambiguated by the preceding word(s) used in > `help-xref-symbol-regexp'. Faces only get cross-referenced if > preceded or followed by the word `face'. Variables without > variable documentation do not get cross-referenced, unless > preceded by the word `variable' or `option'. > > If the variable `help-xref-mule-regexp' is non-nil, find also > cross-reference information related to multilingual environment > \(e.g., coding-systems). This variable is also used to disambiguate > the type of reference as the same way as `help-xref-symbol-regexp'. > > A special reference `back' is made to return back through a stack of > help buffers. Variable `help-back-label' specifies the text for > that." > (interactive "b") > (with-current-buffer (or buffer (current-buffer)) > (save-excursion > (goto-char (point-min)) > ;; Skip the first bit, which has already been buttonized. > (forward-paragraph) > (let ((old-modified (buffer-modified-p))) > (let ((stab (syntax-table)) > (case-fold-search t) > (inhibit-read-only t)) > (set-syntax-table help-mode-syntax-table) > ;; The following should probably be abstracted out. > (unwind-protect > (progn > ;; Info references > (save-excursion > (while (re-search-forward help-xref-info-regexp nil t) > (let ((data (match-string 2))) > (save-match-data > (unless (string-match "^([^)]+)" data) > (setq data (concat "(emacs)" data))) > (setq data ;; possible newlines if para filled > (replace-regexp-in-string "[ \t\n]+" " " data t t))) > (help-xref-button 2 'help-info data)))) > ;; Customization groups. > (save-excursion > (while (re-search-forward > help-xref-customization-group-regexp nil t) > (help-xref-button 1 'help-customization-group > (intern (match-string 1))))) > ;; URLs > (save-excursion > (while (re-search-forward help-xref-url-regexp nil t) > (let ((data (match-string 1))) > (help-xref-button 1 'help-url data)))) > ;; Mule related keywords. Do this before trying > ;; `help-xref-symbol-regexp' because some of Mule > ;; keywords have variable or function definitions. > (if help-xref-mule-regexp > (save-excursion > (while (re-search-forward help-xref-mule-regexp nil t) > (let* ((data (match-string 7)) > (sym (intern-soft data))) > (cond > ((match-string 3) ; coding system > (and sym (coding-system-p sym) > (help-xref-button 6 'help-coding-system sym))) > ((match-string 4) ; input method > (and (assoc data input-method-alist) > (help-xref-button 7 'help-input-method data))) > ((or (match-string 5) (match-string 6)) ; charset > (and sym (charsetp sym) > (help-xref-button 7 'help-character-set sym))) > ((assoc data input-method-alist) > (help-xref-button 7 'help-input-method data)) > ((and sym (coding-system-p sym)) > (help-xref-button 7 'help-coding-system sym)) > ((and sym (charsetp sym)) > (help-xref-button 7 'help-character-set sym))))))) > ;; Quoted symbols > (save-excursion > (while (re-search-forward help-xref-symbol-regexp nil t) > (let* ((data (match-string 8)) > (sym (intern-soft data))) > (if sym > (cond > ((match-string 3) ; `variable' &c > (and (or (boundp sym) ; `variable' doesn't ensure > ; it's actually bound > (get sym 'variable-documentation)) > (help-xref-button 8 'help-variable sym))) > ((match-string 4) ; `function' &c > (and (fboundp sym) ; similarly > (help-xref-button 8 'help-function sym))) > ((match-string 5) ; `face' > (and (facep sym) > (help-xref-button 8 'help-face sym))) > ((match-string 6)) ; nothing for `symbol' > ((match-string 7) > (help-xref-button 8 'help-function-def sym)) > ((cl-some (lambda (x) (funcall (nth 1 x) sym)) > describe-symbol-backends) > (help-xref-button 8 'help-symbol sym))))))) > ;; An obvious case of a key substitution: > (save-excursion > (while (re-search-forward > ;; Assume command name is only word and symbol > ;; characters to get things like `use M-x foo->bar'. > ;; Command required to end with word constituent > ;; to avoid `.' at end of a sentence. > "\\<M-x\\s-+\\(\\sw\\(\\sw\\|\\s_\\)*\\sw\\)" nil t) > (let ((sym (intern-soft (match-string 1)))) > (if (fboundp sym) > (help-xref-button 1 'help-function sym))))) > ;; Look for commands in whole keymap substitutions: > (save-excursion > ;; Make sure to find the first keymap. > (goto-char (point-min)) > ;; Find a header and the column at which the command > ;; name will be found. > > ;; If the keymap substitution isn't the last thing in > ;; the doc string, and if there is anything on the same > ;; line after it, this code won't recognize the end of it. > (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n" > nil t) > (let ((col (- (match-end 1) (match-beginning 1)))) > (while > (and (not (eobp)) > ;; Stop at a pair of blank lines. > (not (looking-at-p "\n\\s-*\n"))) > ;; Skip a single blank line. > (and (eolp) (forward-line)) > (end-of-line) > (skip-chars-backward "^ \t\n") > (if (and (>= (current-column) col) > (looking-at "\\(\\sw\\|\\s_\\)+$")) > (let ((sym (intern-soft (match-string 0)))) > (if (fboundp sym) > (help-xref-button 0 'help-function sym)))) > (forward-line))))) > (set-syntax-table stab))) > ;; Delete extraneous newlines at the end of the docstring > (goto-char (point-max)) > (while (and (not (bobp)) (bolp)) > (delete-char -1)) > (insert "\n") > ;; get source string if needed and available > (when help-mode-inline-source > (insert "\nSource Code: \n") > (let ((file (plist-get help-mode--current-data :file)) > (fun (plist-get help-mode--current-data :symbol))) > (insert (help--function-source fun file))) > (insert "\n")) > (when (or help-xref-stack help-xref-forward-stack) > (insert "\n")) > ;; Make a back-reference in this buffer if appropriate. > (when help-xref-stack > (help-insert-xref-button help-back-label 'help-back > (current-buffer))) > ;; Make a forward-reference in this buffer if appropriate. > (when help-xref-forward-stack > (when help-xref-stack > (insert "\t")) > (help-insert-xref-button help-forward-label 'help-forward > (current-buffer))) > (when (or help-xref-stack help-xref-forward-stack) > (insert "\n"))) > (set-buffer-modified-p old-modified))))) > #+end_src
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 03:42:02 GMT) Full text and rfc822 format available.Message #19 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Phil Sainty <psainty <at> orcon.net.nz> To: arthur.miller <at> live.com Cc: 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 15:41:03 +1200
On 2021-09-18 05:06, arthur.miller <at> live.com wrote: > 1. run Emacs -Q -l /path/to/attached/help-mode.el > 2. type C-x f C-h f > 3. in minibuffer type: when RET > > The help-mode buffer that opens should show help for 'when' form, but > it > shows the source code for the 'pop' macro which precedes the 'when' in > subr.el. > The docs for 'narrow-to-defun' says the "current-defun" is one that > contains the point or follows the point. I can reproduce the issue using your code, but I'm not sure whether the reason for it is a misunderstanding of what 'point' is, some vagueness in the 'narrow-to-defun' docstring, or an actual regression. To eliminate the first: "Like other positions, point designates a place between two characters (or before the first character, or after the last character), rather than a particular character. Usually terminals display the cursor over the character that immediately follows point; point is actually before the character on which the cursor sits." -- quoted from (info "(elisp)Point") 'narrow-to-defun' says "The current defun is the one that contains point or follows point." and if you place the cursor over the opening "(" of "(defmacro when" then that defmacro form "follows point", and indeed narrow-to-defun works as intended. The issue is what happens when point is somewhere earlier than that position, but still *after* the previous form. In that instance narrow-to-defun narrows to the previous form, which is surely what is happening in your code. If so, all you need for reproducing this is to experiment with narrow-to-defun at the various positions between two forms. That is a consequence of 'beginning-of-defun' jumping to the beginning of the previous defun in that situation (which to me seems like a reasonable behaviour for that function); but for 'narrow-to-defun' the effect does seem contrary to its docstring. I think we just want to change the docstring of 'narrow-to-defun' -- the last relevant commit looks like: commit 050cc68b402f5998193a6026d0eeeecb9d2cb9c4 Author: Lennart Borgman <lennart.borgman <at> gmail.com> Date: Wed Apr 11 04:12:20 2012 +0200 `narrow-to-defun' fixup * emacs-lisp/lisp.el (narrow-to-defun): `beginning-of-defun' goes to previous function when point is on the first character of a function. Take care of that in `narrow-to-defun'. Fixes: debbugs:6157 https://debbugs.gnu.org/cgi/bugreport.cgi?bug=6157 -Phil
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 06:38:02 GMT) Full text and rfc822 format available.Message #22 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Arthur Miller <arthur.miller <at> live.com> To: Phil Sainty <psainty <at> orcon.net.nz> Cc: 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 08:36:54 +0200
Phil Sainty <psainty <at> orcon.net.nz> writes: > On 2021-09-18 05:06, arthur.miller <at> live.com wrote: >> 1. run Emacs -Q -l /path/to/attached/help-mode.el >> 2. type C-x f > > C-h f > >> 3. in minibuffer type: when RET >> The help-mode buffer that opens should show help for 'when' form, but it >> shows the source code for the 'pop' macro which precedes the 'when' in >> subr.el. > >> The docs for 'narrow-to-defun' says the "current-defun" is one that >> contains the point or follows the point. > > I can reproduce the issue using your code, but I'm not sure whether the > reason for it is a misunderstanding of what 'point' is, some vagueness > in the 'narrow-to-defun' docstring, or an actual regression. > > To eliminate the first: > > "Like other positions, point designates a place between two characters > (or before the first character, or after the last character), rather > than a particular character. Usually terminals display the cursor over > the character that immediately follows point; point is actually before > the character on which the cursor sits." > > -- quoted from (info "(elisp)Point") Yes, I am aware that point is between two characters. I also use the bar for the cursor, and it is displayed before the first character; I think. > 'narrow-to-defun' says "The current defun is the one that contains point > or follows point." and if you place the cursor over the opening "(" of > "(defmacro when" then that defmacro form "follows point", and indeed > narrow-to-defun works as intended. Than it is probably my understanding of "follows" the point. In my understanding it was the "one that comes after" the point :). Notice that I tried to move the point one character forward (or I think even two, but I don't remember any more), but it didn't helped. When I moved few characters, like with forward-word helps, which is also what you say. > The issue is what happens when point is somewhere earlier than that > position, but still *after* the previous form. In that instance > narrow-to-defun narrows to the previous form, which is surely what is > happening in your code. > > If so, all you need for reproducing this is to experiment with > narrow-to-defun at the various positions between two forms. > > That is a consequence of 'beginning-of-defun' jumping to the beginning > of the previous defun in that situation That sounds like a plausible explanation. I haven't looked into the code for narrow-to-defun. My question is though, why it happens only with 'when'? I haven't found any other form to show same behaviour. There probably are some, I just haven't found them by manually testing. > reasonable behaviour for that function); but for 'narrow-to-defun' > the effect does seem contrary to its docstring. > > I think we just want to change the docstring of 'narrow-to-defun' -- > the last relevant commit looks like: > > > commit 050cc68b402f5998193a6026d0eeeecb9d2cb9c4 > Author: Lennart Borgman <lennart.borgman <at> gmail.com> > Date: Wed Apr 11 04:12:20 2012 +0200 > > `narrow-to-defun' fixup > > * emacs-lisp/lisp.el (narrow-to-defun): `beginning-of-defun' goes > to previous function when point is on the first character of a > function. Take care of that in `narrow-to-defun'. > > Fixes: debbugs:6157 > > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=6157 > Anyway, thank you for the explanation and for the time and for the updated docs.
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 08:34:02 GMT) Full text and rfc822 format available.Message #25 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Arthur Miller <arthur.miller <at> live.com> To: Phil Sainty <psainty <at> orcon.net.nz> Cc: 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 10:33:40 +0200
Phil Sainty <psainty <at> orcon.net.nz> writes: > On 2021-09-18 05:06, arthur.miller <at> live.com wrote: >> 1. run Emacs -Q -l /path/to/attached/help-mode.el >> 2. type C-x f > > C-h f > >> 3. in minibuffer type: when RET >> The help-mode buffer that opens should show help for 'when' form, but it >> shows the source code for the 'pop' macro which precedes the 'when' in >> subr.el. > >> The docs for 'narrow-to-defun' says the "current-defun" is one that >> contains the point or follows the point. > > I can reproduce the issue using your code, but I'm not sure whether the > reason for it is a misunderstanding of what 'point' is, some vagueness > in the 'narrow-to-defun' docstring, or an actual regression. > > To eliminate the first: > > "Like other positions, point designates a place between two characters > (or before the first character, or after the last character), rather > than a particular character. Usually terminals display the cursor over > the character that immediately follows point; point is actually before > the character on which the cursor sits." > > -- quoted from (info "(elisp)Point") > > > 'narrow-to-defun' says "The current defun is the one that contains point > or follows point." and if you place the cursor over the opening "(" of > "(defmacro when" then that defmacro form "follows point", and indeed > narrow-to-defun works as intended. > > The issue is what happens when point is somewhere earlier than that > position, but still *after* the previous form. In that instance > narrow-to-defun narrows to the previous form, which is surely what is > happening in your code. > > If so, all you need for reproducing this is to experiment with > narrow-to-defun at the various positions between two forms. > > That is a consequence of 'beginning-of-defun' jumping to the beginning > of the previous defun in that situation (which to me seems like a > reasonable behaviour for that function); but for 'narrow-to-defun' > the effect does seem contrary to its docstring. > > I think we just want to change the docstring of 'narrow-to-defun' -- > the last relevant commit looks like: > > > commit 050cc68b402f5998193a6026d0eeeecb9d2cb9c4 > Author: Lennart Borgman <lennart.borgman <at> gmail.com> > Date: Wed Apr 11 04:12:20 2012 +0200 > > `narrow-to-defun' fixup > > * emacs-lisp/lisp.el (narrow-to-defun): `beginning-of-defun' goes > to previous function when point is on the first character of a > function. Take care of that in `narrow-to-defun'. > > Fixes: debbugs:6157 > > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=6157 > > > -Phil I have found what was the problem, but I don't know if it is a bug or not: (with-temp-buffer (insert-file-contents-literally (expand-file-name file source-directory)) It is the utf-8. When I use `insert-file-contents' instead, it works as intended. I guess insert-file-contents-literally does not preserve same coding as what I have in the temp-buffer by deafault, so things get messed-up. I don't know if I explain it well, but that seems to be the problem. I don't know if that is a bug, or just me not being used to how encodings in Emacs work. Probably not a bug. I appologize for the inconvenience.
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 08:36:02 GMT) Full text and rfc822 format available.Message #28 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Arthur Miller <arthur.miller <at> live.com> To: Lars Ingebrigtsen <larsi <at> gnus.org> Cc: 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 10:34:58 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes: > arthur.miller <at> live.com writes: > >> To reproduce this bug: >> >> 1. run Emacs -Q -l /path/to/attached/help-mode.el >> 2. type C-x f >> 3. in minibuffer type: when RET >> >> The help-mode buffer that opens should show help for 'when' form, but it >> shows the source code for the 'pop' macro which precedes the 'when' in >> subr.el. > > I didn't try to reproduce this, because the attached .el file is almost > 1K lines long. > > Do you have a simpler way to reproduce the issue you're seeing? Hi Lars, plz, see my answer to Phil. Problem seems to be due to encoding; I have used insert-file-contents-literally. I don't know if it is a bug, probably not. I appologize for the noise.
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 10:05:02 GMT) Full text and rfc822 format available.Message #31 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Phil Sainty <psainty <at> orcon.net.nz> To: Arthur Miller <arthur.miller <at> live.com> Cc: 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 22:04:13 +1200
On 2021-09-19 20:33, Arthur Miller wrote: > (with-temp-buffer > (insert-file-contents-literally (expand-file-name file > source-directory)) > > It is the utf-8. When I use `insert-file-contents' instead, it works as > intended. > > I guess insert-file-contents-literally does not preserve same coding as > what I > have in the temp-buffer by deafault, so things get messed-up. I don't > know if I > explain it well, but that seems to be the problem. Yes, all of the following things from `insert-file-contents' are NOT done by `insert-file-contents-literally': "This function does code conversion according to the value of ‘coding-system-for-read’ or ‘file-coding-system-alist’, and sets the variable ‘last-coding-system-used’ to the coding system actually used. In addition, this function decodes the inserted text from known formats by calling ‘format-decode’, which see. I don't believe you would typically use *-literally unless you specifically wanted to avoid all of those things (or some of the things, and were happy to take care of the others in your own code). I do also think that the docstring for `insert-file-contents-literally' can be made clearer, firstly just with a newline so that the context for the final sentence does not begin in the middle of a paragraph, and secondly so that when users are reading this for the first time it's more obvious (before reaching that final sentence) that the list of "modifications" are things which do NOT happen if you use this function. How does this look? (defun insert-file-contents-literally (filename &optional visit beg end replace) "Like `insert-file-contents', but only reads in the file literally. See `insert-file-contents' for an explanation of the parameters. -A buffer may be modified in several ways after reading into the buffer, -due to Emacs features such as format decoding, character code -conversion, `find-file-hook', automatic uncompression, etc. + +In other circumstances a buffer may be modified in several ways after +reading into the buffer, due to Emacs features such as format decoding, +character code conversion, `find-file-hook', automatic uncompression, etc. This function ensures that none of these modifications will take place." (let ((format-alist nil)
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 10:57:01 GMT) Full text and rfc822 format available.Message #34 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Phil Sainty <psainty <at> orcon.net.nz> To: Arthur Miller <arthur.miller <at> live.com> Cc: 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 22:56:03 +1200
On 2021-09-19 18:36, Arthur Miller wrote: > My question is though, why it happens only with 'when'? I haven't > found any other form to show same behaviour. There probably are > some, I just haven't found them by manually testing. Now that you've narrowed this down to a code conversion issue, that part was simple to debug (by comparing the buffer in its literal and non-literal forms), and the reason is that subr.el contains multi-byte characters. This included a documentation bug, as the docstring for `setq-local' had this paragraph in the source: The second VALUE is not computed until after the first VARIABLE is set, and so on; each VALUE can use the new value of variables set earlier in the ‘setq-local’. The return value of the ‘setq-local’ form is the value of the last VALUE. Note the incorrect unicode quote characters. I've just pushed a fix for that, but there's also a more intentional INVERTED EXCLAMATION MARK unicode character in one of the comments, though, and I've left this alone. ;; ¡Beware! when I tried to edebug this code, Emacs got into a weird state ;; where all the keys were unbound (i.e. it somehow got triggered ;; within read-key, apparently). I had to kill it. In short, you don't want to be making assumptions about the encoding of elisp files. Tangentially, the commit message related to those quote characters says "expand the doc string by taking some text from `setq'", so I believe those fancy unicode quote characters were accidentally copied and pasted from a *Help* buffer rendering of the `setq' docstring. I think it's a good idea to set `text-quoting-style' to 'grave to ensure that can never happen. -Phil
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 12:03:02 GMT) Full text and rfc822 format available.Message #37 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Phil Sainty <psainty <at> orcon.net.nz> Cc: 50646 <at> debbugs.gnu.org, arthur.miller <at> live.com Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 15:01:38 +0300
> Date: Sun, 19 Sep 2021 22:04:13 +1200 > From: Phil Sainty <psainty <at> orcon.net.nz> > Cc: 50646 <at> debbugs.gnu.org > > (defun insert-file-contents-literally (filename &optional visit beg end > replace) > "Like `insert-file-contents', but only reads in the file literally. > See `insert-file-contents' for an explanation of the parameters. > -A buffer may be modified in several ways after reading into the buffer, > -due to Emacs features such as format decoding, character code > -conversion, `find-file-hook', automatic uncompression, etc. > + > +In other circumstances a buffer may be modified in several ways after > +reading into the buffer, due to Emacs features such as format decoding, > +character code conversion, `find-file-hook', automatic uncompression, > etc. What "other circumstances"? This phrase only makes sense when "some circumstances" were described before it.
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 12:07:01 GMT) Full text and rfc822 format available.Message #40 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Phil Sainty <psainty <at> orcon.net.nz> To: Eli Zaretskii <eliz <at> gnu.org> Cc: 50646 <at> debbugs.gnu.org, arthur.miller <at> live.com Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Mon, 20 Sep 2021 00:06:26 +1200
On 2021-09-20 00:01, Eli Zaretskii wrote: > What "other circumstances"? This phrase only makes sense when > "some circumstances" were described before it. Circumstances other than `insert-file-contents-literally' was the intended meaning, but evidentially that phrasing can also be confusing.
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 12:18:02 GMT) Full text and rfc822 format available.Message #43 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Phil Sainty <psainty <at> orcon.net.nz> Cc: 50646 <at> debbugs.gnu.org, arthur.miller <at> live.com Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 15:17:28 +0300
> Date: Mon, 20 Sep 2021 00:06:26 +1200 > From: Phil Sainty <psainty <at> orcon.net.nz> > Cc: arthur.miller <at> live.com, 50646 <at> debbugs.gnu.org > > On 2021-09-20 00:01, Eli Zaretskii wrote: > > What "other circumstances"? This phrase only makes sense when > > "some circumstances" were described before it. > > Circumstances other than `insert-file-contents-literally' was > the intended meaning, but evidentially that phrasing can also be > confusing. Then I suggest to mention insert-file-contents and other functions (if any) that do this explicitly. Something like This is contrary to other functions, like `insert-file-contents', which may modify a buffer in several ways after ...
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 12:54:01 GMT) Full text and rfc822 format available.Message #46 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Phil Sainty <psainty <at> orcon.net.nz> To: Eli Zaretskii <eliz <at> gnu.org> Cc: 50646 <at> debbugs.gnu.org, arthur.miller <at> live.com Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Mon, 20 Sep 2021 00:53:48 +1200
On 2021-09-20 00:17, Eli Zaretskii wrote: > Then I suggest to mention insert-file-contents and other functions > (if any) that do this explicitly. Sounds sensible. The pre-existing mention of `find-file-hook' means (AFAIK) that we're already talking about more than just the two 'insert-file-contents*' functions. The set of notable functions that I know of are: - find-file - find-file-literally - insert-file-contents - insert-file-contents-literally - insert-file - insert-file-literally The latter two are for interactive usage only (but analogous to the insert-file-contents* functions, so maybe their docstrings should be looked at too, for consistency). For the `insert-file-contents-literally' docstring perhaps we just need to add an explicit mention of `find-file'? > Something like > This is contrary to other functions, like `insert-file-contents', > which may modify a buffer in several ways after ... I now have this: "Like `insert-file-contents', but only reads in the file literally. See `insert-file-contents' for an explanation of the parameters. Insert after point the contents of file FILENAME as a sequence of ASCII characters with no special encoding or conversion. This is contrary to other functions, like `insert-file-contents' and `find-file', which may modify a buffer in several ways after reading into the buffer, due to Emacs features such as format decoding, character code conversion, `find-file-hook', automatic uncompression, etc. Using `insert-file-contents-literally' ensures that none of these modifications will take place." I took "as a sequence of ASCII characters with no special encoding or conversion" from (info "(emacs) Visiting") but I see that wording used by `insert-file-literally' is "Insert contents of file FILENAME into buffer after point with no conversion", and I figure the two should probably use the same wording? Is there a preference? -Phil
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 13:44:02 GMT) Full text and rfc822 format available.Message #49 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Phil Sainty <psainty <at> orcon.net.nz> Cc: 50646 <at> debbugs.gnu.org, arthur.miller <at> live.com Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 16:43:23 +0300
> Date: Mon, 20 Sep 2021 00:53:48 +1200 > From: Phil Sainty <psainty <at> orcon.net.nz> > Cc: arthur.miller <at> live.com, 50646 <at> debbugs.gnu.org > > I now have this: > > "Like `insert-file-contents', but only reads in the file literally. > See `insert-file-contents' for an explanation of the parameters. > > Insert after point the contents of file FILENAME as a sequence of > ASCII characters with no special encoding or conversion. > > This is contrary to other functions, like `insert-file-contents' and > `find-file', which may modify a buffer in several ways after reading > into the buffer, due to Emacs features such as format decoding, > character code conversion, `find-file-hook', automatic uncompression, > etc. > > Using `insert-file-contents-literally' ensures that none of these > modifications will take place." > > > > I took "as a sequence of ASCII characters with no special encoding or > conversion" from (info "(emacs) Visiting") but I see that wording used > by `insert-file-literally' is "Insert contents of file FILENAME into > buffer after point with no conversion", and I figure the two should > probably use the same wording? Is there a preference? The "ASCII characters" part is wrong. I suggest "sequence of uninterpreted bytes" instead.
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 14:22:01 GMT) Full text and rfc822 format available.Message #52 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Phil Sainty <psainty <at> orcon.net.nz> To: Eli Zaretskii <eliz <at> gnu.org> Cc: 50646 <at> debbugs.gnu.org, arthur.miller <at> live.com Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Mon, 20 Sep 2021 02:21:41 +1200
On 2021-09-20 01:43, Eli Zaretskii wrote: >> I took "as a sequence of ASCII characters with no special encoding >> or conversion" from (info "(emacs) Visiting") > > The "ASCII characters" part is wrong. I suggest "sequence of > uninterpreted bytes" instead. Shall I update (emacs)Visiting to also use the same wording?
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 15:23:02 GMT) Full text and rfc822 format available.Message #55 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Phil Sainty <psainty <at> orcon.net.nz> Cc: 50646 <at> debbugs.gnu.org, arthur.miller <at> live.com Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 18:22:16 +0300
> Date: Mon, 20 Sep 2021 02:21:41 +1200 > From: Phil Sainty <psainty <at> orcon.net.nz> > Cc: arthur.miller <at> live.com, 50646 <at> debbugs.gnu.org > > > The "ASCII characters" part is wrong. I suggest "sequence of > > uninterpreted bytes" instead. > > Shall I update (emacs)Visiting to also use the same wording? Yes, please. With a cross-reference to "International Chars", where we hopefully explain what are "raw bytes". Thanks.
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 15:26:01 GMT) Full text and rfc822 format available.Message #58 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Drew Adams <drew.adams <at> oracle.com> To: Eli Zaretskii <eliz <at> gnu.org>, Phil Sainty <psainty <at> orcon.net.nz> Cc: "50646 <at> debbugs.gnu.org" <50646 <at> debbugs.gnu.org>, "arthur.miller <at> live.com" <arthur.miller <at> live.com> Subject: RE: [External] : bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 15:25:06 +0000
> Something like > > This is contrary to other functions, like `insert-file-contents', > which may modify a buffer in several ways after ... [very minor nit]: Use "such as", not "like", here. "Such as" explicitly includes `insert-file-contents' among the "other functions". "Like" does not necessarily include it. But in practice, many, maybe most, people don't and won't make/understand/notice the difference. https://www.grammarbank.com/such-as-vs-like.html https://grammar.yourdictionary.com/vs/how-such-as-vs-like-are-different-and-which-to-choose.html https://www.quickanddirtytips.com/education/grammar/like-versus-such-as
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 19:58:02 GMT) Full text and rfc822 format available.Message #61 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Arthur Miller <arthur.miller <at> live.com> To: Phil Sainty <psainty <at> orcon.net.nz> Cc: 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 21:57:27 +0200
Phil Sainty <psainty <at> orcon.net.nz> writes: > On 2021-09-19 20:33, Arthur Miller wrote: >> (with-temp-buffer >> (insert-file-contents-literally (expand-file-name file source-directory)) >> It is the utf-8. When I use `insert-file-contents' instead, it works as >> intended. >> I guess insert-file-contents-literally does not preserve same coding as what I >> have in the temp-buffer by deafault, so things get messed-up. I don't know if >> I >> explain it well, but that seems to be the problem. > > Yes, all of the following things from `insert-file-contents' are NOT done > by `insert-file-contents-literally': > > "This function does code conversion according to the value of > ‘coding-system-for-read’ or ‘file-coding-system-alist’, and sets the > variable ‘last-coding-system-used’ to the coding system actually used. > > In addition, this function decodes the inserted text from known formats > by calling ‘format-decode’, which see. > > I don't believe you would typically use *-literally unless you specifically > wanted to avoid all of those things (or some of the things, and were happy > to take care of the others in your own code). > > I do also think that the docstring for `insert-file-contents-literally' can > be made clearer, firstly just with a newline so that the context for the > final sentence does not begin in the middle of a paragraph, and secondly > so that when users are reading this for the first time it's more obvious > (before reaching that final sentence) that the list of "modifications" are > things which do NOT happen if you use this function. > > How does this look? > > (defun insert-file-contents-literally (filename &optional visit beg end > replace) > "Like `insert-file-contents', but only reads in the file literally. > See `insert-file-contents' for an explanation of the parameters. > -A buffer may be modified in several ways after reading into the buffer, > -due to Emacs features such as format decoding, character code > -conversion, `find-file-hook', automatic uncompression, etc. > + > +In other circumstances a buffer may be modified in several ways after > +reading into the buffer, due to Emacs features such as format decoding, > +character code conversion, `find-file-hook', automatic uncompression, etc. > > This function ensures that none of these modifications will take place." > (let ((format-alist nil) Yes I am quite aware of the difference contents-literally and not. That is why I use it. Actually today when I opened the file to continue the work on my patch, I saw I used literally and it struck me immidiately what is going on :). I don't know why I didn't see it the other day. I worked with the C sources, and there I wanted "literal" version (I still have it in the submitted patch). I didn't have time to look through the subr.el today, and I am really not familiar with it so it is really good if you took the time to look through offending characters and fixed the bug! Thank you for your kind advices and work, it was very nice that you look through the bug and tried to help me and fixed it.
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Sun, 19 Sep 2021 20:03:01 GMT) Full text and rfc822 format available.Message #64 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Arthur Miller <arthur.miller <at> live.com> To: Phil Sainty <psainty <at> orcon.net.nz> Cc: 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Sun, 19 Sep 2021 22:02:44 +0200
Phil Sainty <psainty <at> orcon.net.nz> writes: > On 2021-09-19 18:36, Arthur Miller wrote: >> My question is though, why it happens only with 'when'? I haven't >> found any other form to show same behaviour. There probably are >> some, I just haven't found them by manually testing. > > Now that you've narrowed this down to a code conversion issue, that > part was simple to debug (by comparing the buffer in its literal and > non-literal forms), and the reason is that subr.el contains multi-byte > characters. This included a documentation bug, as the docstring for > `setq-local' had this paragraph in the source: > > The second VALUE is not computed until after the first VARIABLE > is set, and so on; each VALUE can use the new value of variables > set earlier in the ‘setq-local’. The return value of the > ‘setq-local’ form is the value of the last VALUE. > > Note the incorrect unicode quote characters. > > I've just pushed a fix for that, but there's also a more intentional > INVERTED EXCLAMATION MARK unicode character in one of the comments, > though, and I've left this alone. > > ;; ¡Beware! when I tried to edebug this code, Emacs got into a weird state > ;; where all the keys were unbound (i.e. it somehow got triggered > ;; within read-key, apparently). I had to kill it. > > In short, you don't want to be making assumptions about the encoding > of elisp files. > > Tangentially, the commit message related to those quote characters > says "expand the doc string by taking some text from `setq'", so I > believe those fancy unicode quote characters were accidentally copied > and pasted from a *Help* buffer rendering of the `setq' docstring. > I think it's a good idea to set `text-quoting-style' to 'grave to > ensure that can never happen. > > > -Phil Hi, sorry for the later answers, but it was busy day for me today. I just answered you in other, so I won't repeat here. Yes, I realized myself what is going on today; I didn't do any testing and such, I such sent mail, when I saw myself I used 'literal' version there. Anyway, thanks, and I see from the responses between you and Eli that it resulted in some updates to manual and you fixing erronous characters in subr.el, so my goofy misstake at least brought something good :). Anyway, thanks for the help and good job!
bug-gnu-emacs <at> gnu.org
:bug#50646
; Package emacs
.
(Mon, 20 Sep 2021 06:03:01 GMT) Full text and rfc822 format available.Message #67 received at 50646 <at> debbugs.gnu.org (full text, mbox):
From: Lars Ingebrigtsen <larsi <at> gnus.org> To: Arthur Miller <arthur.miller <at> live.com> Cc: Phil Sainty <psainty <at> orcon.net.nz>, 50646 <at> debbugs.gnu.org Subject: Re: bug#50646: 28.0.50; narrow-to-defun sometimes narrows to wrong defun Date: Mon, 20 Sep 2021 08:02:44 +0200
Arthur Miller <arthur.miller <at> live.com> writes: > Thank you for your kind advices and work, it was very nice that you > look through the bug and tried to help me and fixed it. I'm closing this bug report, then. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no
Lars Ingebrigtsen <larsi <at> gnus.org>
to control <at> debbugs.gnu.org
.
(Mon, 20 Sep 2021 06:04:02 GMT) Full text and rfc822 format available.Debbugs Internal Request <help-debbugs <at> gnu.org>
to internal_control <at> debbugs.gnu.org
.
(Mon, 18 Oct 2021 11:24:07 GMT) Full text and rfc822 format available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.