From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eduardo Ochs Newsgroups: gmane.emacs.help Subject: call-process -> insert -> iso-latin-1-dos problem on Windows Date: Sun, 14 Jan 2024 20:09:41 -0300 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17482"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 15 00:10:45 2024 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rP9cr-0004Lb-HD for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 15 Jan 2024 00:10:45 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rP9cD-0007cl-B6; Sun, 14 Jan 2024 18:10:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rP9cC-0007cd-Fc for help-gnu-emacs@gnu.org; Sun, 14 Jan 2024 18:10:04 -0500 Original-Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rP9cA-0001jQ-I2 for help-gnu-emacs@gnu.org; Sun, 14 Jan 2024 18:10:04 -0500 Original-Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3bd489d75b7so2310000b6e.0 for ; Sun, 14 Jan 2024 15:10:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705273800; x=1705878600; darn=gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=KTQ8l4/AuZBPXH2Hm0Mvm7zi3Yy+MOXqPuKeUV5jojE=; b=TbMb/nooDE50sy4P/ZIWUBHkJeKl6ClrR7LkBgxV7jLptZnVnOwOr8DXMCsKbSCCLq wKH4Aaqy7/qgN3rRfxtXVQCupW++SfevU9NIf+hHIxn7kIBhcMtKdTBLcBes/LHz+cVO YvlSxSnPT56ExRAPaL6CjucURNTWOwxurMeg7qfccLzCrJnd4TREEEhSx+PUhAyfPHiW WkejG8YDJ+rqbhg4/kPxKPQNJZ+TmIBSihjv/E4C4IETUN8SYkMeTAsYTg5xhRp2Wq0L scM1QMYs7EWPM8sVwyW1nNpZQtGxcihM8r7QHuck3y+DpNAPNQuCvuDAdnwpC5UNeVdE VhDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705273800; x=1705878600; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=KTQ8l4/AuZBPXH2Hm0Mvm7zi3Yy+MOXqPuKeUV5jojE=; b=rnCvPJrrpD/QGQnC+oBEkAKOa/XfgRQJRDg2t0vILTKQVofM605qoCqCYY80grHq98 3kRLRHrFiqXZDkdkSSE+qNK4dTFl3Fom9V6K8oK5aVLIDb5g4oPv1n3Qwfc3XJsnK5Mc 16Old/t2g5KS8e99u0UcKBEfXd19wD1w98fd5V1BHoq4I91PBsAe8JAagoRecJNt47/T ooDJa4S95F+xAxnyM86dwSR+kR3HPsSKLQHhD8AXN4RQ4rTZTs2UHzoT5Hn34TMvNNPf HH1VU0BaplHmN7qLeJ4w2v5/3xH1Rm1tSi2n2/N3QpsUA09H1R71MHRJ3eKQwX2W3oJj 51SQ== X-Gm-Message-State: AOJu0YzSmsxnJvQWBUry2uJykW7StkPpjYjF24sU93VrcuJjPS1FZmnc T9yrVbjK9wmFQZ8gPZQX1Vj5LrzdEtwWsfb9MKyNB/SwZFA= X-Google-Smtp-Source: AGHT+IF2VJviNoKuKu/eVghNw61IZNelNhnXxSS3rcaB6JZdoVAbsVM4iXl7nb1NZ5tUTnjtN81DqijrDKyu6Nqj1rI= X-Received: by 2002:a05:6808:bc8:b0:3bd:32e3:9781 with SMTP id o8-20020a0568080bc800b003bd32e39781mr3572273oik.76.1705273800298; Sun, 14 Jan 2024 15:10:00 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::22d; envelope-from=eduardoochs@gmail.com; helo=mail-oi1-x22d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:145733 Archived-At: Hi list, I have a function called `find-wget' that works well in *NIX-like systems - it calls wget, puts the output in the temporary buffer, and on unices Emacs always chooses the right encoding... but when I run it on Windows, and I call wget like this, wget -q -O - http://anggtwu.net/LUA/Dang1.lua where Dang1.lua is a file in UTF-8, then Emacs switches the encoding of output buffer to iso-latin-1-dos... I probably wrote my code relying in undefined behaviors... any suggestions on how to fix it? I'm attaching the file with the test and the comments below, and it's also here: http://anggtwu.net/elisp/find-wget-jan-2024.el.html http://anggtwu.net/elisp/find-wget-jan-2024.el Thanks in advance =/, Eduardo Ochs http://anggtwu.net/eepitch.html http://anggtwu.net/#eev --snip--snip-- ;; This is a simplified version of the `find-wget' from eev: ;; ;; http://anggtwu.net/eev-current/eev-plinks.el.html#find-wget ;; (find-eev "eev-plinks.el" "find-wget") ;; ;; Most functions were copied from the source code of eev without ;; changes; only the ones that are marked as "dummified" were replaced ;; by trivial versions. (defvar ee-wget-program "wget") (defvar ee-find-callprocess00-exit-status nil) ;; Dummified versions (defun ee-expand (fname) fname) (defun ee-goto-rest (list) ()) (defun ee-goto-position (&optional pos-spec &rest rest) ()) (defun find-ebuffer (buffer &rest pos-spec-list) "Hyperlink to an Emacs buffer (existing or not)." (interactive "bBuffer: ") (switch-to-buffer buffer) (apply 'ee-goto-position pos-spec-list)) (defun ee-split (str) "If STR is a string, split it on whitespace and return the resulting list. If STR if a list, return it unchanged." (if (stringp str) (split-string str "[ \t\n]+") str)) (defun find-callprocess00-ne (program-and-args) (let ((argv (ee-split program-and-args))) (with-output-to-string (with-current-buffer standard-output (setq ee-find-callprocess00-exit-status (apply 'call-process (car argv) nil t nil (cdr argv))))))) (defun find-wget (url &rest pos-spec-list) "Download URL with \"wget -q -O - URL\" and display the output. If a buffer named \"*wget: URL*\" already exists then this function visits it instead of running wget again. If wget can't download URL then this function runs `error'." (let* ((eurl (ee-expand url)) (wgetprogandargs (list ee-wget-program "-q" "-O" "-" eurl)) (wgetbufname (format "*wget: %s*" eurl))) (if (get-buffer wgetbufname) (apply 'find-ebuffer wgetbufname pos-spec-list) ;; ;; If the buffer wgetbufname doesn't exist, then: (let* ((wgetoutput (find-callprocess00-ne wgetprogandargs)) (wgetstatus ee-find-callprocess00-exit-status)) ;; (if (not (equal wgetstatus 0)) ;; See: (find-node "(wget)Exit Status") (error "wget can't download: %s" eurl)) ;; (find-ebuffer wgetbufname) ; create buffer (insert wgetoutput) (goto-char (point-min)) (apply 'ee-goto-position pos-spec-list))))) ;; Test: (eval-buffer) ;; (find-wget "http://anggtwu.net/LUA/Dang1.lua") ;; ;; When we run the test above on Debian the double angle brackets in ;; the line 12 of Dang1.lua are displayed correctly as single ;; characters - and when we run `M-x hexlify-buffer' we see that they ;; take are encoded in two bytes each - c2ab and c2bb. From ;; /usr/share/unicode/UnicodeData.txt: ;; ;; 00AB;LEFT-POINTING DOUBLE ANGLE QUOTATION MARK;Pi;0;ON;;;;;Y;LEFT POINTING GUILLEMET;;;; ;; 00BB;RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK;Pf;0;ON;;;;;Y;RIGHT POINTING GUILLEMET;;;; ;; ;; When we run the `find-wget' above in Emacs 29 for Windows the ;; resulting buffer is put in the encoding "iso-latin-1-dos". `M-x ;; hexlify-buffer' shows that they are still two bytes each - c2ab and ;; c2bb - but they are displayed as two characters each, preceded by ;; "c2"s:: ;; ;; 00C2;LATIN CAPITAL LETTER A WITH CIRCUMFLEX;Lu;0;L;0041 0302;;;;N;LATIN CAPITAL LETTER A CIRCUMFLEX;;;00E2; ;; ;; The wget that I am using on Windows was extracted from this zip: ;; ;; https://eternallybored.org/misc/wget/releases/wget-1.21.2-win64.zip