2016-10-31 19:55:17 -04:00
|
|
|
;;; url-util.el --- Miscellaneous helper routines for URL library -*- lexical-binding: t -*-
|
2004-04-16 22:05:32 +00:00
|
|
|
|
2022-01-01 02:45:51 -05:00
|
|
|
;; Copyright (C) 1996-1999, 2001, 2004-2022 Free Software Foundation,
|
2015-01-01 14:26:41 -08:00
|
|
|
;; Inc.
|
2004-04-16 22:05:32 +00:00
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
;; Author: Bill Perry <wmperry@gnu.org>
|
2019-05-25 13:43:06 -07:00
|
|
|
;; Maintainer: emacs-devel@gnu.org
|
2004-04-04 01:21:46 +00:00
|
|
|
;; Keywords: comm, data, processes
|
|
|
|
|
2004-04-16 22:05:32 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
2008-05-06 04:29:13 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2004-04-16 22:05:32 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 04:29:13 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
2004-04-16 22:05:32 +00:00
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
2008-05-06 04:29:13 +00:00
|
|
|
|
2004-04-16 22:05:32 +00:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2004-04-16 22:05:32 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(require 'url-parse)
|
2010-01-23 17:50:13 -05:00
|
|
|
(require 'url-vars)
|
2004-04-04 01:21:46 +00:00
|
|
|
(autoload 'timezone-parse-date "timezone")
|
|
|
|
(autoload 'timezone-make-date-arpa-standard "timezone")
|
2004-04-12 04:06:01 +00:00
|
|
|
(autoload 'mail-header-extract "mailheader")
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(defvar url-parse-args-syntax-table
|
|
|
|
(copy-syntax-table emacs-lisp-mode-syntax-table)
|
|
|
|
"A syntax table for parsing sgml attributes.")
|
|
|
|
|
|
|
|
(modify-syntax-entry ?' "\"" url-parse-args-syntax-table)
|
|
|
|
(modify-syntax-entry ?` "\"" url-parse-args-syntax-table)
|
|
|
|
(modify-syntax-entry ?{ "(" url-parse-args-syntax-table)
|
|
|
|
(modify-syntax-entry ?} ")" url-parse-args-syntax-table)
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defcustom url-debug nil
|
2010-09-10 18:58:42 -07:00
|
|
|
"What types of debug messages from the URL library to show.
|
2004-04-04 01:21:46 +00:00
|
|
|
Debug messages are logged to the *URL-DEBUG* buffer.
|
|
|
|
|
|
|
|
If t, all messages will be logged.
|
|
|
|
If a number, all messages will be logged, as well shown via `message'.
|
|
|
|
If a list, it is a list of the types of messages to be logged."
|
|
|
|
:type '(choice (const :tag "none" nil)
|
|
|
|
(const :tag "all" t)
|
|
|
|
(checklist :tag "custom"
|
|
|
|
(const :tag "HTTP" :value http)
|
|
|
|
(const :tag "DAV" :value dav)
|
|
|
|
(const :tag "General" :value retrieval)
|
|
|
|
(const :tag "Filename handlers" :value handlers)
|
|
|
|
(symbol :tag "Other")))
|
|
|
|
:group 'url-hairy)
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-debug (tag &rest args)
|
|
|
|
(if (or (eq url-debug t)
|
|
|
|
(numberp url-debug)
|
|
|
|
(and (listp url-debug) (memq tag url-debug)))
|
2004-04-16 22:05:32 +00:00
|
|
|
(with-current-buffer (get-buffer-create "*URL-DEBUG*")
|
2004-04-04 01:21:46 +00:00
|
|
|
(goto-char (point-max))
|
|
|
|
(insert (symbol-name tag) " -> " (apply 'format args) "\n")
|
|
|
|
(if (numberp url-debug)
|
|
|
|
(apply 'message args)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-parse-args (str &optional nodowncase)
|
Update citations of Internet RFCs
For example, RFC 822 has been obsoleted by RFC 2822, which in
turn has been obsoleted by RFC 5322.
* doc/emacs/ack.texi, doc/lispref/os.texi:
* doc/misc/emacs-mime.texi, doc/misc/gnus-coding.texi:
* doc/misc/gnus.texi, doc/misc/sc.texi:
* lisp/calendar/parse-time.el, lisp/gnus/gnus-cite.el:
* lisp/gnus/gnus-util.el, lisp/gnus/message.el:
* lisp/gnus/mm-bodies.el, lisp/gnus/nnrss.el:
* lisp/mail/feedmail.el, lisp/mail/ietf-drums.el:
* lisp/mail/mail-extr.el, lisp/mail/mail-utils.el:
* lisp/mail/mailclient.el, lisp/mail/mailheader.el:
* lisp/mail/rfc2047.el, lisp/mail/rfc822.el, lisp/mail/rmail.el:
* lisp/mail/sendmail.el, lisp/mail/smtpmail.el:
* lisp/mail/supercite.el, lisp/mh-e/mh-e.el:
* lisp/mh-e/mh-utils.el, lisp/net/imap.el:
* lisp/net/newst-backend.el, lisp/org/org-id.el:
* lisp/ps-samp.el, lisp/simple.el, lisp/url/url-util.el:
Update RFC citations.
2019-02-16 11:20:09 -08:00
|
|
|
;; Return an assoc list of attribute/value pairs from a string
|
|
|
|
;; that uses RFC 822 (or later) format.
|
2019-09-24 10:07:26 +02:00
|
|
|
(let (name ; From name=
|
2004-04-04 01:21:46 +00:00
|
|
|
value ; its value
|
|
|
|
results ; Assoc list of results
|
|
|
|
name-pos ; Start of XXXX= position
|
2019-09-24 10:07:26 +02:00
|
|
|
val-pos) ; Start of value position
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert str)
|
|
|
|
(set-syntax-table url-parse-args-syntax-table)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (not (eobp))
|
|
|
|
(skip-chars-forward "; \n\t")
|
|
|
|
(setq name-pos (point))
|
|
|
|
(skip-chars-forward "^ \n\t=;")
|
|
|
|
(unless nodowncase
|
|
|
|
(downcase-region name-pos (point)))
|
|
|
|
(setq name (buffer-substring name-pos (point)))
|
|
|
|
(skip-chars-forward " \t\n")
|
|
|
|
(if (/= (or (char-after (point)) 0) ?=) ; There is no value
|
|
|
|
(setq value nil)
|
|
|
|
(skip-chars-forward " \t\n=")
|
|
|
|
(setq val-pos (point)
|
|
|
|
value
|
|
|
|
(cond
|
|
|
|
((or (= (or (char-after val-pos) 0) ?\")
|
|
|
|
(= (or (char-after val-pos) 0) ?'))
|
|
|
|
(buffer-substring (1+ val-pos)
|
|
|
|
(condition-case ()
|
|
|
|
(prog2
|
|
|
|
(forward-sexp 1)
|
|
|
|
(1- (point))
|
|
|
|
(skip-chars-forward "\""))
|
|
|
|
(error
|
|
|
|
(skip-chars-forward "^ \t\n")
|
|
|
|
(point)))))
|
|
|
|
(t
|
|
|
|
(buffer-substring val-pos
|
|
|
|
(progn
|
|
|
|
(skip-chars-forward "^;")
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
(point)))))))
|
|
|
|
(setq results (cons (cons name value) results))
|
|
|
|
(skip-chars-forward "; \n\t"))
|
|
|
|
results)))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-insert-entities-in-string (string)
|
|
|
|
"Convert HTML markup-start characters to entity references in STRING.
|
|
|
|
Also replaces the \" character, so that the result may be safely used as
|
2012-09-29 22:45:44 +02:00
|
|
|
an attribute value in a tag. Returns a new string with the result of the
|
|
|
|
conversion. Replaces these characters as follows:
|
2004-04-04 01:21:46 +00:00
|
|
|
& ==> &
|
|
|
|
< ==> <
|
|
|
|
> ==> >
|
|
|
|
\" ==> ""
|
|
|
|
(if (string-match "[&<>\"]" string)
|
* url-util.el (url-insert-entities-in-string):
* url-nfs.el (url-nfs-unescape):
* url-ldap.el (url-ldap):
* url-imap.el (url-imap):
* url-cid.el (url-cid-gnus, url-cid): Use with-current-buffer.
* erc.el (erc-display-line-1, erc-process-away):
* erc-truncate.el (erc-truncate-buffer-to-size):
Use with-current-buffer.
* term/ns-win.el (ns-scroll-bar-move, ns-face-at-pos):
* play/mpuz.el (mpuz-create-buffer):
* play/landmark.el (lm-prompt-for-move, lm-print-wts, lm-print-smell)
(lm-print-y,s,noise, lm-print-w0, lm-init):
* play/gomoku.el (gomoku-prompt-for-move):
* play/fortune.el (fortune-in-buffer):
* play/dissociate.el (dissociated-press):
* play/decipher.el (decipher-adjacency-list, decipher-display-regexp)
(decipher-analyze-buffer, decipher-stats-buffer,decipher-stats-buffer):
* mail/supercite.el (sc-eref-show):
* mail/smtpmail.el (smtpmail-send-it):
* mail/rmailsum.el (rmail-summary-next-labeled-message)
(rmail-summary-previous-labeled-message, rmail-summary-wipe)
(rmail-summary-undelete-many, rmail-summary-rmail-update)
(rmail-summary-goto-msg, rmail-summary-expunge)
(rmail-summary-get-new-mail, rmail-summary-search-backward)
(rmail-summary-add-label, rmail-summary-output-menu)
(rmail-summary-output-body):
* mail/rfc822.el (rfc822-addresses):
* mail/reporter.el (reporter-dump-variable, reporter-dump-state):
* mail/mailpost.el (post-mail-send-it):
* mail/hashcash.el (hashcash-generate-payment):
* mail/feedmail.el (feedmail-run-the-queue)
(feedmail-queue-send-edit-prompt-help-first)
(feedmail-send-it-immediately, feedmail-give-it-to-buffer-eater)
(feedmail-deduce-address-list):
* eshell/esh-ext.el (eshell-remote-command):
* eshell/em-unix.el (eshell-occur-mode-mouse-goto):
* emulation/viper-util.el (viper-glob-unix-files, viper-save-setting)
(viper-wildcard-to-regexp, viper-glob-mswindows-files)
(viper-save-string-in-file, viper-valid-marker):
* emulation/viper-keym.el (viper-toggle-key):
* emulation/viper-ex.el (ex-expand-filsyms, viper-get-ex-file)
(ex-edit, ex-global, ex-mark, ex-next-related-buffer, ex-quit)
(ex-get-inline-cmd-args, ex-tag, ex-command, ex-compile):
* emulation/viper-cmd.el (viper-exec-form-in-vi)
(viper-exec-form-in-emacs, viper-brac-function):
* emulation/viper.el (viper-delocalize-var):
* emulation/vip.el (vip-mode, vip-get-ex-token, vip-ex, vip-get-ex-pat)
(vip-get-ex-command, vip-get-ex-opt-gc, vip-get-ex-buffer)
(vip-get-ex-count, vip-get-ex-file, ex-edit, ex-global, ex-mark)
(ex-map, ex-unmap, ex-quit, ex-read, ex-tag, ex-command):
* emulation/vi.el (vi-switch-mode, vi-ex-cmd):
* emulation/edt.el (edt-electric-helpify):
* emulation/cua-rect.el (cua--rectangle-aux-replace):
* emulation/cua-gmrk.el (cua--insert-at-global-mark)
(cua--delete-at-global-mark, cua--copy-rectangle-to-global-mark)
(cua-indent-to-global-mark-column):
* calendar/diary-lib.el (calendar-mark-1):
* calendar/cal-hebrew.el (calendar-hebrew-mark-date-pattern):
Use with-current-buffer.
* emulation/viper.el (viper-delocalize-var): Use dolist.
2009-11-03 02:04:29 +00:00
|
|
|
(with-current-buffer (get-buffer-create " *entity*")
|
2004-04-04 01:21:46 +00:00
|
|
|
(erase-buffer)
|
|
|
|
(buffer-disable-undo (current-buffer))
|
|
|
|
(insert string)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (progn
|
|
|
|
(skip-chars-forward "^&<>\"")
|
|
|
|
(not (eobp)))
|
|
|
|
(insert (cdr (assq (char-after (point))
|
|
|
|
'((?\" . """)
|
|
|
|
(?& . "&")
|
|
|
|
(?< . "<")
|
|
|
|
(?> . ">")))))
|
|
|
|
(delete-char 1))
|
|
|
|
(buffer-string))
|
|
|
|
string))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-normalize-url (url)
|
2015-11-17 15:28:50 -08:00
|
|
|
"Return a \"normalized\" version of URL.
|
2004-04-04 01:21:46 +00:00
|
|
|
Strips out default port numbers, etc."
|
2006-07-31 21:36:43 +00:00
|
|
|
(let (type data retval)
|
2004-04-04 01:21:46 +00:00
|
|
|
(setq data (url-generic-parse-url url)
|
|
|
|
type (url-type data))
|
|
|
|
(if (member type '("www" "about" "mailto" "info"))
|
|
|
|
(setq retval url)
|
2008-09-25 07:41:32 +00:00
|
|
|
;; FIXME all this does, and all this function seems to do in
|
|
|
|
;; most cases, is remove any trailing "#anchor" part of a url.
|
2007-08-31 16:40:05 +00:00
|
|
|
(setf (url-target data) nil)
|
2004-04-04 01:21:46 +00:00
|
|
|
(setq retval (url-recreate-url data)))
|
|
|
|
retval))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-lazy-message (&rest args)
|
|
|
|
"Just like `message', but is a no-op if called more than once a second.
|
2004-04-16 22:05:32 +00:00
|
|
|
Will not do anything if `url-show-status' is nil."
|
2010-10-02 04:04:20 +02:00
|
|
|
(if (or (and url-current-object
|
|
|
|
(url-silent url-current-object))
|
|
|
|
(null url-show-status)
|
2004-04-04 01:21:46 +00:00
|
|
|
(active-minibuffer-window)
|
|
|
|
(= url-lazy-message-time
|
New function time-convert
This replaces the awkward reuse of encode-time to both convert
calendrical timestamps to Lisp timestamps, and to convert Lisp
timestamps to other forms. Now, encode-time does just the
former and the new function does just the latter.
The new function builds on a suggestion by Lars Ingebrigtsen in:
https://lists.gnu.org/r/emacs-devel/2019-07/msg00801.html
and refined by Stefan Monnier in:
https://lists.gnu.org/r/emacs-devel/2019-07/msg00803.html
* doc/lispref/os.texi (Time of Day, Time Conversion):
* doc/misc/emacs-mime.texi (time-date):
* etc/NEWS: Update documentation.
* lisp/calendar/cal-dst.el (calendar-next-time-zone-transition):
* lisp/calendar/time-date.el (seconds-to-time, days-to-time):
* lisp/calendar/timeclock.el (timeclock-seconds-to-time):
* lisp/cedet/ede/detect.el (ede-detect-qtest):
* lisp/completion.el (cmpl-hours-since-origin):
* lisp/ecomplete.el (ecomplete-add-item):
* lisp/emacs-lisp/cl-extra.el (cl--random-time):
* lisp/emacs-lisp/timer.el (timer--time-setter)
(timer-next-integral-multiple-of-time):
* lisp/find-lisp.el (find-lisp-format-time):
* lisp/gnus/gnus-diary.el (gnus-user-format-function-d):
* lisp/gnus/gnus-group.el (gnus-group-set-timestamp):
* lisp/gnus/gnus-icalendar.el (gnus-icalendar-show-org-agenda):
* lisp/gnus/nnrss.el (nnrss-normalize-date):
* lisp/gnus/nnspool.el (nnspool-request-newgroups):
* lisp/net/ntlm.el (ntlm-compute-timestamp):
* lisp/net/pop3.el (pop3-uidl-dele):
* lisp/obsolete/vc-arch.el (vc-arch-add-tagline):
* lisp/org/org-clock.el (org-clock-get-clocked-time)
(org-clock-resolve, org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-sum):
* lisp/org/org-id.el (org-id-uuid, org-id-time-to-b36):
* lisp/org/ox-publish.el (org-publish-cache-ctime-of-src):
* lisp/proced.el (proced-format-time):
* lisp/progmodes/cc-cmds.el (c-progress-init)
(c-progress-update):
* lisp/progmodes/cperl-mode.el (cperl-time-fontification):
* lisp/progmodes/flymake.el (flymake--schedule-timer-maybe):
* lisp/progmodes/vhdl-mode.el (vhdl-update-progress-info)
(vhdl-fix-case-region-1):
* lisp/tar-mode.el (tar-octal-time):
* lisp/time.el (emacs-uptime):
* lisp/url/url-auth.el (url-digest-auth-make-cnonce):
* lisp/url/url-util.el (url-lazy-message):
* lisp/vc/vc-cvs.el (vc-cvs-parse-entry):
* lisp/vc/vc-hg.el (vc-hg-state-fast):
* lisp/xt-mouse.el (xterm-mouse-event):
* test/lisp/emacs-lisp/timer-tests.el:
(timer-next-integral-multiple-of-time-2):
Use time-convert, not encode-time.
* lisp/calendar/icalendar.el (icalendar--decode-isodatetime):
Don’t use now-removed FORM argument for encode-time.
It wasn’t crucial anyway.
* lisp/emacs-lisp/byte-opt.el (side-effect-free-fns): Add time-convert.
* lisp/emacs-lisp/elint.el (elint-unknown-builtin-args):
Update encode-time signature to match current arg set.
* lisp/emacs-lisp/timer.el (timer-next-integral-multiple-of-time):
Use timer-convert with t rather than doing it by hand.
* src/timefns.c (time_hz_ticks, time_form_stamp, lisp_time_form_stamp):
Remove; no longer needed.
(decode_lisp_time): Rturn the form instead of having a *PFORM arg.
All uses changed.
(time_arith): Just return TICKS if HZ is 1.
(Fencode_time): Remove argument FORM. All callers changed.
Do not attempt to encode time values; just encode
decoded (calendrical) times.
Unless CURRENT_TIME_LIST, just return VALUE since HZ is 1.
(Ftime_convert): New function, which does the time value
conversion that bleeding-edge encode-time formerly did.
Return TIME if it is easy to see that it is already
of the correct form.
(Fcurrent_time): Mention in doc that the form is planned to change.
* test/src/timefns-tests.el (decode-then-encode-time):
Don’t use (encode-time nil).
2019-08-05 17:38:52 -07:00
|
|
|
(setq url-lazy-message-time (time-convert nil 'integer))))
|
2004-04-04 01:21:46 +00:00
|
|
|
nil
|
|
|
|
(apply 'message args)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-get-normalized-date (&optional specified-time)
|
2015-11-17 15:28:50 -08:00
|
|
|
"Return a date string that most HTTP servers can understand."
|
2008-02-28 17:41:40 +00:00
|
|
|
(let ((system-time-locale "C"))
|
Simplify use of current-time and friends.
* doc/misc/org.texi (Dynamic blocks):
* lisp/allout-widgets.el (allout-widgets-hook-error-handler):
* lisp/calendar/appt.el (appt-display-message):
* lisp/calendar/icalendar.el (icalendar--convert-float-to-ical):
* lisp/calendar/timeclock.el (timeclock-in, timeclock-when-to-leave)
(timeclock-last-period, timeclock-day-base):
* lisp/eshell/em-ls.el (eshell-ls-file):
* lisp/eshell/esh-util.el (eshell-parse-ange-ls):
* lisp/generic-x.el (named-database-print-serial):
* lisp/net/newst-backend.el (newsticker--get-news-by-url-callback)
(newsticker-get-news, newsticker--sentinel-work)
(newsticker--image-get, newsticker--image-sentinel):
* lisp/net/tramp-sh.el (tramp-get-remote-touch):
* lisp/progmodes/opascal.el (opascal-debug-log):
* lisp/textmodes/remember.el (remember-mail-date)
(remember-store-in-files):
* lisp/vc/vc-annotate.el (vc-annotate-display-autoscale)
(vc-default-annotate-current-time):
* lisp/vc/vc-bzr.el (vc-bzr-shelve-snapshot):
* lisp/vc/vc-cvs.el (vc-cvs-annotate-current-time):
* lisp/vc/vc-rcs.el (vc-rcs-annotate-current-time):
* lisp/url/url-util.el (url-get-normalized-date):
* lisp/erc/erc-backend.el (TOPIC):
* lisp/gnus/gnus-delay.el (gnus-delay-article):
* lisp/gnus/gnus-sum.el (gnus-summary-read-document):
* lisp/gnus/gnus-util.el (gnus-seconds-today, gnus-seconds-month):
* lisp/gnus/message.el (message-make-expires-date):
* lisp/org/org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling):
* lisp/org/org-clock.el (org-resolve-clocks, org-clock-get-sum-start)
(org-clock-special-range):
* lisp/org/org-timer.el (org-timer-seconds):
* lisp/org/org.el (org-read-date-analyze, org-get-cursor-date):
* lisp/org/ox-html.el (org-html-format-spec):
* lisp/org/ox-icalendar.el (org-icalendar--vtodo):
Omit unnecessary call to current-time.
* lisp/calendar/time-date.el (time-to-seconds) [!float-time]:
* lisp/calendar/timeclock.el (timeclock-time-to-date):
* lisp/vc/vc-annotate.el (vc-annotate-convert-time):
Use current time if arg is nil, to be compatible with float-time.
(time-date--day-in-year): New function, with most of the guts of
the old time-to-day-in-year.
(time-to-day-in-year): Use it.
(time-to-days): Use it, to avoid decoding the same time stamp twice.
* lisp/calendar/timeclock.el (timeclock-update-mode-line):
* lisp/cedet/srecode/args.el (srecode-semantic-handle-:time):
* lisp/gnus/gnus-util.el (gnus-seconds-year):
* lisp/org/org.el (org-get-cursor-date):
Don't call current-time twice to get the current time stamp,
as this can lead to inconsistent results.
* lisp/completion.el (cmpl-hours-since-origin):
* lisp/erc/erc.el (erc-emacs-time-to-erc-time):
* lisp/ido.el (ido-time-stamp):
* lisp/vc/vc-annotate.el (vc-annotate-convert-time):
Simplify by using float-time.
* lisp/completion.el (save-completions-to-file):
* lisp/url/url-cache.el (url-cache-prune-cache):
Rename local var to avoid confusion.
* lisp/gnus/gnus-util.el (gnus-float-time):
* lisp/net/rcirc.el (rcirc-float-time):
* lisp/org/org-compat.el (org-float-time):
Simplify to an alias because time-to-seconds now behaves like float-time
with respect to nil arg.
* lisp/subr.el (progress-reporter-do-update):
Don't call float-time unless needed.
* lisp/erc/erc.el (erc-current-time): Simplify by using erc-emacs-time-to-erc-time.
* lisp/org/org-clock.el (org-clock-get-table-data): Omit unnecessary, lossy
conversion from floating point to Emacs time and back.
(org-resolve-clocks): Prefer two-argument floor.
2014-10-28 18:42:51 -07:00
|
|
|
(format-time-string "%a, %d %b %Y %T GMT" specified-time t)))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-eat-trailing-space (x)
|
|
|
|
"Remove spaces/tabs at the end of a string."
|
|
|
|
(let ((y (1- (length x)))
|
|
|
|
(skip-chars (list ? ?\t ?\n)))
|
|
|
|
(while (and (>= y 0) (memq (aref x y) skip-chars))
|
|
|
|
(setq y (1- y)))
|
|
|
|
(substring x 0 (1+ y))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-strip-leading-spaces (x)
|
|
|
|
"Remove spaces at the front of a string."
|
|
|
|
(let ((y (1- (length x)))
|
|
|
|
(z 0)
|
|
|
|
(skip-chars (list ? ?\t ?\n)))
|
|
|
|
(while (and (<= z y) (memq (aref x z) skip-chars))
|
|
|
|
(setq z (1+ z)))
|
|
|
|
(substring x z nil)))
|
|
|
|
|
2013-09-29 09:37:03 +08:00
|
|
|
|
|
|
|
(define-obsolete-function-alias 'url-pretty-length
|
|
|
|
'file-size-human-readable "24.4")
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-display-percentage (fmt perc &rest args)
|
2010-10-02 04:04:20 +02:00
|
|
|
(when (and url-show-status
|
|
|
|
(or (null url-current-object)
|
|
|
|
(not (url-silent url-current-object))))
|
2006-11-23 08:42:06 +00:00
|
|
|
(if (null fmt)
|
|
|
|
(if (fboundp 'clear-progress-display)
|
|
|
|
(clear-progress-display))
|
|
|
|
(if (and (fboundp 'progress-display) perc)
|
|
|
|
(apply 'progress-display fmt perc args)
|
|
|
|
(apply 'message fmt args)))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-percentage (x y)
|
|
|
|
(if (fboundp 'float)
|
|
|
|
(round (* 100 (/ x (float y))))
|
|
|
|
(/ (* x 100) y)))
|
|
|
|
|
2008-11-04 17:11:58 +00:00
|
|
|
;;;###autoload
|
|
|
|
(defalias 'url-basepath 'url-file-directory)
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
;;;###autoload
|
2007-10-13 14:02:50 +00:00
|
|
|
(defun url-file-directory (file)
|
|
|
|
"Return the directory part of FILE, for a URL."
|
2004-04-04 01:21:46 +00:00
|
|
|
(cond
|
|
|
|
((null file) "")
|
2010-10-03 14:37:41 -07:00
|
|
|
((string-match "\\?" file)
|
2012-08-12 13:35:15 -04:00
|
|
|
(url-file-directory (substring file 0 (match-beginning 0))))
|
|
|
|
((string-match "\\(.*\\(/\\|%2[fF]\\)\\)" file)
|
|
|
|
(match-string 1 file))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
2007-10-13 14:02:50 +00:00
|
|
|
;;;###autoload
|
|
|
|
(defun url-file-nondirectory (file)
|
|
|
|
"Return the nondirectory part of FILE, for a URL."
|
|
|
|
(cond
|
|
|
|
((null file) "")
|
2010-10-03 14:37:41 -07:00
|
|
|
((string-match "\\?" file)
|
2012-08-12 13:35:15 -04:00
|
|
|
(url-file-nondirectory (substring file 0 (match-beginning 0))))
|
|
|
|
((string-match ".*\\(?:/\\|%2[fF]\\)\\(.*\\)" file)
|
|
|
|
(match-string 1 file))
|
|
|
|
(t file)))
|
2007-10-13 14:02:50 +00:00
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
;;;###autoload
|
2005-09-01 16:38:39 +00:00
|
|
|
(defun url-parse-query-string (query &optional downcase allow-newlines)
|
2004-04-04 01:21:46 +00:00
|
|
|
(let (retval pairs cur key val)
|
2012-05-15 04:47:38 -04:00
|
|
|
(setq pairs (split-string query "[;&]"))
|
2004-04-04 01:21:46 +00:00
|
|
|
(while pairs
|
|
|
|
(setq cur (car pairs)
|
|
|
|
pairs (cdr pairs))
|
Use string-search instead of string-match[-p]
`string-search` is easier to understand, less error-prone, much
faster, does not pollute the regexp cache, and does not mutate global
state. Use it where applicable and obviously safe (erring on the
conservative side).
* admin/authors.el (authors-canonical-file-name)
(authors-scan-change-log):
* lisp/apropos.el (apropos-command)
(apropos-documentation-property, apropos-symbols-internal):
* lisp/arc-mode.el (archive-arc-summarize)
(archive-zoo-summarize):
* lisp/calc/calc-aent.el (math-read-factor):
* lisp/calc/calc-ext.el (math-read-big-expr)
(math-format-nice-expr, math-format-number-fancy):
* lisp/calc/calc-forms.el (math-read-angle-brackets):
* lisp/calc/calc-graph.el (calc-graph-set-range):
* lisp/calc/calc-keypd.el (calc-keypad-press):
* lisp/calc/calc-lang.el (tex, latex, math-read-big-rec):
* lisp/calc/calc-prog.el (calc-fix-token-name)
(calc-user-define-permanent, math-define-exp):
* lisp/calc/calc.el (calc-record, calcDigit-key)
(calc-count-lines):
* lisp/calc/calcalg2.el (calc-solve-for, calc-poly-roots)
(math-do-integral):
* lisp/calc/calcalg3.el (calc-find-root, calc-find-minimum)
(calc-get-fit-variables):
* lisp/cedet/ede/speedbar.el (ede-tag-expand):
* lisp/cedet/semantic/java.el (semantic-java-expand-tag):
* lisp/cedet/semantic/sb.el (semantic-sb-show-extra)
(semantic-sb-expand-group):
* lisp/cedet/semantic/wisent/python.el
(semantic-python-instance-variable-p):
* lisp/cus-edit.el (get):
* lisp/descr-text.el (describe-text-sexp):
* lisp/dired-aux.el (dired-compress-file):
* lisp/dired-x.el (dired-make-relative-symlink):
* lisp/dired.el (dired-glob-regexp):
* lisp/dos-fns.el (dos-convert-standard-filename, dos-8+3-filename):
* lisp/edmacro.el (edmacro-format-keys):
* lisp/emacs-lisp/eieio-opt.el (eieio-sb-expand):
* lisp/emacs-lisp/eieio-speedbar.el (eieio-speedbar-object-expand):
* lisp/emacs-lisp/lisp-mnt.el (lm-keywords-list):
* lisp/emacs-lisp/warnings.el (display-warning):
* lisp/emulation/viper-ex.el (viper-ex-read-file-name)
(ex-print-display-lines):
* lisp/env.el (read-envvar-name, setenv):
* lisp/epa-mail.el (epa-mail-encrypt):
* lisp/epg.el (epg--start):
* lisp/erc/erc-backend.el (erc-parse-server-response):
* lisp/erc/erc-dcc.el (erc-dcc-member):
* lisp/erc/erc-speedbar.el (erc-speedbar-expand-server)
(erc-speedbar-expand-channel, erc-speedbar-expand-user):
* lisp/erc/erc.el (erc-send-input):
* lisp/eshell/em-glob.el (eshell-glob-entries):
* lisp/eshell/esh-proc.el (eshell-needs-pipe-p):
* lisp/eshell/esh-util.el (eshell-convert):
* lisp/eshell/esh-var.el (eshell-envvar-names):
* lisp/faces.el (x-resolve-font-name):
* lisp/ffap.el (ffap-file-at-point):
* lisp/files.el (wildcard-to-regexp, shell-quote-wildcard-pattern):
* lisp/forms.el (forms--update):
* lisp/frameset.el (frameset-filter-unshelve-param):
* lisp/gnus/gnus-art.el (article-decode-charset):
* lisp/gnus/gnus-kill.el (gnus-kill-parse-rn-kill-file):
* lisp/gnus/gnus-mlspl.el (gnus-group-split-fancy):
* lisp/gnus/gnus-msg.el (gnus-summary-resend-message-insert-gcc)
(gnus-inews-insert-gcc):
* lisp/gnus/gnus-rfc1843.el (rfc1843-decode-article-body):
* lisp/gnus/gnus-search.el (gnus-search-indexed-parse-output)
(gnus-search--complete-key-data):
* lisp/gnus/gnus-spec.el (gnus-parse-simple-format):
* lisp/gnus/gnus-sum.el (gnus-summary-refer-article):
* lisp/gnus/gnus-util.el (gnus-extract-address-components)
(gnus-newsgroup-directory-form):
* lisp/gnus/gnus-uu.el (gnus-uu-grab-view):
* lisp/gnus/gnus.el (gnus-group-native-p, gnus-short-group-name):
* lisp/gnus/message.el (message-check-news-header-syntax)
(message-make-message-id, message-user-mail-address)
(message-make-fqdn, message-get-reply-headers, message-followup):
* lisp/gnus/mm-decode.el (mm-dissect-buffer):
* lisp/gnus/nnheader.el (nnheader-insert):
* lisp/gnus/nnimap.el (nnimap-process-quirk)
(nnimap-imap-ranges-to-gnus-ranges):
* lisp/gnus/nnmaildir.el (nnmaildir--ensure-suffix):
* lisp/gnus/nnmairix.el (nnmairix-determine-original-group-from-path):
* lisp/gnus/nnrss.el (nnrss-match-macro):
* lisp/gnus/nntp.el (nntp-find-group-and-number):
* lisp/help-fns.el (help--symbol-completion-table-affixation):
* lisp/help.el (help-function-arglist):
* lisp/hippie-exp.el (he-concat-directory-file-name):
* lisp/htmlfontify.el (hfy-relstub):
* lisp/ido.el (ido-make-prompt, ido-complete, ido-copy-current-word)
(ido-exhibit):
* lisp/image/image-converter.el (image-convert-p):
* lisp/info-xref.el (info-xref-docstrings):
* lisp/info.el (Info-toc-build, Info-follow-reference)
(Info-backward-node, Info-finder-find-node)
(Info-speedbar-expand-node):
* lisp/international/mule-diag.el (print-fontset-element):
* lisp/language/korea-util.el (default-korean-keyboard):
* lisp/linum.el (linum-after-change):
* lisp/mail/ietf-drums.el (ietf-drums-parse-address):
* lisp/mail/mail-utils.el (mail-dont-reply-to):
* lisp/mail/rfc2047.el (rfc2047-encode-1, rfc2047-decode-string):
* lisp/mail/rfc2231.el (rfc2231-parse-string):
* lisp/mail/rmailkwd.el (rmail-set-label):
* lisp/mail/rmailsum.el (rmail-header-summary):
* lisp/mail/smtpmail.el (smtpmail-maybe-append-domain)
(smtpmail-user-mail-address):
* lisp/mail/uce.el (uce-reply-to-uce):
* lisp/man.el (Man-default-man-entry):
* lisp/mh-e/mh-alias.el (mh-alias-gecos-name)
(mh-alias-minibuffer-confirm-address):
* lisp/mh-e/mh-comp.el (mh-forwarded-letter-subject):
* lisp/mh-e/mh-speed.el (mh-speed-parse-flists-output):
* lisp/mh-e/mh-utils.el (mh-collect-folder-names-filter)
(mh-folder-completion-function):
* lisp/minibuffer.el (completion--make-envvar-table)
(completion-file-name-table, completion-flex-try-completion)
(completion-flex-all-completions):
* lisp/mpc.el (mpc--proc-quote-string, mpc-cmd-special-tag-p)
(mpc-constraints-tag-lookup):
* lisp/net/ange-ftp.el (ange-ftp-send-cmd)
(ange-ftp-allow-child-lookup):
* lisp/net/mailcap.el (mailcap-mime-types):
* lisp/net/mairix.el (mairix-search-thread-this-article):
* lisp/net/pop3.el (pop3-open-server):
* lisp/net/soap-client.el (soap-decode-xs-complex-type):
* lisp/net/socks.el (socks-filter):
* lisp/nxml/nxml-outln.el (nxml-highlighted-qname):
* lisp/nxml/rng-cmpct.el (rng-c-expand-name, rng-c-expand-datatype):
* lisp/nxml/rng-uri.el (rng-uri-file-name-1):
* lisp/obsolete/complete.el (partial-completion-mode)
(PC-do-completion):
* lisp/obsolete/longlines.el (longlines-encode-string):
* lisp/obsolete/nnir.el (nnir-compose-result):
* lisp/obsolete/terminal.el (te-quote-arg-for-sh):
* lisp/obsolete/tpu-edt.el (tpu-check-search-case):
* lisp/obsolete/url-ns.el (isPlainHostName):
* lisp/pcmpl-unix.el (pcomplete/scp):
* lisp/play/dunnet.el (dun-listify-string2, dun-get-path)
(dun-unix-parse, dun-doassign, dun-cat, dun-batch-unix-interface):
* lisp/progmodes/ebnf2ps.el: (ebnf-eps-header-footer-comment):
* lisp/progmodes/gdb-mi.el (gdb-var-delete)
(gdb-speedbar-expand-node, gdbmi-bnf-incomplete-record-result):
* lisp/progmodes/gud.el (gud-find-expr):
* lisp/progmodes/idlw-help.el (idlwave-do-context-help1):
* lisp/progmodes/idlw-shell.el (idlwave-shell-mode)
(idlwave-shell-filter-hidden-output, idlwave-shell-filter):
* lisp/progmodes/idlwave.el (idlwave-skip-label-or-case)
(idlwave-routine-info):
* lisp/progmodes/octave.el (inferior-octave-completion-at-point):
* lisp/progmodes/sh-script.el (sh-add-completer):
* lisp/progmodes/sql.el (defun):
* lisp/progmodes/xscheme.el (xscheme-process-filter):
* lisp/replace.el (query-replace-compile-replacement)
(map-query-replace-regexp):
* lisp/shell.el (shell--command-completion-data)
(shell-environment-variable-completion):
* lisp/simple.el (display-message-or-buffer):
* lisp/speedbar.el (speedbar-dired, speedbar-tag-file)
(speedbar-tag-expand):
* lisp/subr.el (split-string-and-unquote):
* lisp/tar-mode.el (tar-extract):
* lisp/term.el (term-command-hook, serial-read-name):
* lisp/textmodes/bibtex.el (bibtex-print-help-message):
* lisp/textmodes/ispell.el (ispell-lookup-words, ispell-filter)
(ispell-parse-output, ispell-buffer-local-parsing):
* lisp/textmodes/reftex-cite.el (reftex-do-citation):
* lisp/textmodes/reftex-parse.el (reftex-notice-new):
* lisp/textmodes/reftex-ref.el (reftex-show-entry):
* lisp/textmodes/reftex.el (reftex-compile-variables):
* lisp/textmodes/tex-mode.el (tex-send-command)
(tex-start-tex, tex-append):
* lisp/thingatpt.el (thing-at-point-url-at-point):
* lisp/tmm.el (tmm-add-one-shortcut):
* lisp/transient.el (transient-format-key):
* lisp/url/url-auth.el (url-basic-auth)
(url-digest-auth-directory-id-assoc):
* lisp/url/url-news.el (url-news):
* lisp/url/url-util.el (url-parse-query-string):
* lisp/vc/vc-cvs.el (vc-cvs-parse-entry):
* lisp/wid-browse.el (widget-browse-sexp):
* lisp/woman.el (woman-parse-colon-path, woman-mini-help)
(WoMan-getpage-in-background, woman-negative-vertical-space):
* lisp/xml.el:
* test/lisp/emacs-lisp/check-declare-tests.el
(check-declare-tests-warn):
* test/lisp/files-tests.el
(files-tests-file-name-non-special-dired-compress-handler):
* test/lisp/net/network-stream-tests.el (server-process-filter):
* test/src/coding-tests.el (ert-test-unibyte-buffer-dos-eol-decode):
Use `string-search` instead of `string-match` and `string-match-p`.
2021-08-09 11:20:00 +02:00
|
|
|
(unless (string-search "=" cur)
|
2012-05-15 04:47:38 -04:00
|
|
|
(setq cur (concat cur "=")))
|
|
|
|
|
|
|
|
(when (string-match "=" cur)
|
|
|
|
(setq key (url-unhex-string (substring cur 0 (match-beginning 0))
|
|
|
|
allow-newlines))
|
|
|
|
(setq val (url-unhex-string (substring cur (match-end 0) nil)
|
|
|
|
allow-newlines))
|
|
|
|
(if downcase
|
|
|
|
(setq key (downcase key)))
|
|
|
|
(setq cur (assoc key retval))
|
|
|
|
(if cur
|
|
|
|
(setcdr cur (cons val (cdr cur)))
|
|
|
|
(setq retval (cons (list key val) retval)))))
|
2004-04-04 01:21:46 +00:00
|
|
|
retval))
|
|
|
|
|
2012-05-15 04:47:38 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun url-build-query-string (query &optional semicolons keep-empty)
|
|
|
|
"Build a query-string.
|
|
|
|
|
|
|
|
Given a QUERY in the form:
|
2015-09-03 15:31:12 -07:00
|
|
|
((key1 val1)
|
2012-05-15 04:47:38 -04:00
|
|
|
(key2 val2)
|
|
|
|
(key3 val1 val2)
|
|
|
|
(key4)
|
2012-09-29 22:45:44 +02:00
|
|
|
(key5 \"\"))
|
2012-05-15 04:47:38 -04:00
|
|
|
|
|
|
|
\(This is the same format as produced by `url-parse-query-string')
|
|
|
|
|
|
|
|
This will return a string
|
2021-09-14 08:43:18 +02:00
|
|
|
\"key1=val1&key2=val2&key3=val1&key3=val2&key4&key5\". Keys may
|
2012-05-15 04:47:38 -04:00
|
|
|
be strings or symbols; if they are symbols, the symbol name will
|
|
|
|
be used.
|
|
|
|
|
|
|
|
When SEMICOLONS is given, the separator will be \";\".
|
|
|
|
|
|
|
|
When KEEP-EMPTY is given, empty values will show as \"key=\"
|
|
|
|
instead of just \"key\" as in the example above."
|
|
|
|
(mapconcat
|
|
|
|
(lambda (key-vals)
|
|
|
|
(let ((escaped
|
|
|
|
(mapcar (lambda (sym)
|
|
|
|
(url-hexify-string (format "%s" sym))) key-vals)))
|
|
|
|
(mapconcat (lambda (val)
|
|
|
|
(let ((vprint (format "%s" val))
|
|
|
|
(eprint (format "%s" (car escaped))))
|
|
|
|
(concat eprint
|
|
|
|
(if (or keep-empty
|
|
|
|
(and val (not (zerop (length vprint)))))
|
|
|
|
"="
|
|
|
|
"")
|
|
|
|
vprint)))
|
|
|
|
(or (cdr escaped) '("")) (if semicolons ";" "&"))))
|
|
|
|
query (if semicolons ";" "&")))
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
(defun url-unhex (x)
|
|
|
|
(if (> x ?9)
|
|
|
|
(if (>= x ?a)
|
|
|
|
(+ 10 (- x ?a))
|
|
|
|
(+ 10 (- x ?A)))
|
|
|
|
(- x ?0)))
|
|
|
|
|
2004-04-12 04:06:01 +00:00
|
|
|
;; Fixme: Is this definition better, and does it ever matter?
|
|
|
|
|
|
|
|
;; (defun url-unhex-string (str &optional allow-newlines)
|
|
|
|
;; "Remove %XX, embedded spaces, etc in a url.
|
|
|
|
;; If optional second argument ALLOW-NEWLINES is non-nil, then allow the
|
|
|
|
;; decoding of carriage returns and line feeds in the string, which is normally
|
|
|
|
;; forbidden in URL encoding."
|
|
|
|
;; (setq str (or str ""))
|
|
|
|
;; (setq str (replace-regexp-in-string "%[[:xdigit:]]\\{2\\}"
|
|
|
|
;; (lambda (match)
|
|
|
|
;; (string (string-to-number
|
|
|
|
;; (substring match 1) 16)))
|
|
|
|
;; str t t))
|
|
|
|
;; (if allow-newlines
|
|
|
|
;; (replace-regexp-in-string "[\n\r]" (lambda (match)
|
|
|
|
;; (format "%%%.2X" (aref match 0)))
|
|
|
|
;; str t t)
|
|
|
|
;; str))
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
;;;###autoload
|
2012-04-10 19:02:04 +02:00
|
|
|
(defun url-unhex-string (str &optional allow-newlines)
|
2021-07-04 15:04:52 +03:00
|
|
|
"Decode %XX sequences in a percent-encoded URL.
|
2004-04-04 01:21:46 +00:00
|
|
|
If optional second argument ALLOW-NEWLINES is non-nil, then allow the
|
|
|
|
decoding of carriage returns and line feeds in the string, which is normally
|
2021-07-04 15:04:52 +03:00
|
|
|
forbidden in URL encoding.
|
|
|
|
|
|
|
|
The resulting string in general requires decoding using an
|
|
|
|
appropriate coding-system; see `decode-coding-string'."
|
2004-04-04 01:21:46 +00:00
|
|
|
(setq str (or str ""))
|
|
|
|
(let ((tmp "")
|
|
|
|
(case-fold-search t))
|
|
|
|
(while (string-match "%[0-9a-f][0-9a-f]" str)
|
|
|
|
(let* ((start (match-beginning 0))
|
|
|
|
(ch1 (url-unhex (elt str (+ start 1))))
|
|
|
|
(code (+ (* 16 ch1)
|
|
|
|
(url-unhex (elt str (+ start 2))))))
|
|
|
|
(setq tmp (concat
|
|
|
|
tmp (substring str 0 start)
|
|
|
|
(cond
|
|
|
|
(allow-newlines
|
2010-05-19 11:23:53 -04:00
|
|
|
(byte-to-string code))
|
2004-04-04 01:21:46 +00:00
|
|
|
((or (= code ?\n) (= code ?\r))
|
|
|
|
" ")
|
2010-05-19 11:23:53 -04:00
|
|
|
(t (byte-to-string code))))
|
2004-04-04 01:21:46 +00:00
|
|
|
str (substring str (match-end 0)))))
|
2012-04-10 19:03:34 +02:00
|
|
|
(concat tmp str)))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(defconst url-unreserved-chars
|
2012-05-09 16:33:48 +08:00
|
|
|
'(?a ?b ?c ?d ?e ?f ?g ?h ?i ?j ?k ?l ?m ?n ?o ?p ?q ?r ?s ?t ?u ?v ?w ?x ?y ?z
|
2004-04-04 01:21:46 +00:00
|
|
|
?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K ?L ?M ?N ?O ?P ?Q ?R ?S ?T ?U ?V ?W ?X ?Y ?Z
|
|
|
|
?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9
|
2012-05-09 16:33:48 +08:00
|
|
|
?- ?_ ?. ?~)
|
|
|
|
"List of characters that are unreserved in the URL spec.
|
|
|
|
This is taken from RFC 3986 (section 2.3).")
|
|
|
|
|
|
|
|
(defconst url-encoding-table
|
|
|
|
(let ((vec (make-vector 256 nil)))
|
|
|
|
(dotimes (byte 256)
|
2012-05-09 20:20:26 +08:00
|
|
|
;; RFC 3986 (Section 2.1): For consistency, URI producers and
|
|
|
|
;; normalizers should use uppercase hexadecimal digits for all
|
|
|
|
;; percent-encodings.
|
|
|
|
(aset vec byte (format "%%%02X" byte)))
|
2012-05-09 16:33:48 +08:00
|
|
|
vec)
|
|
|
|
"Vector translating bytes to URI-encoded %-sequences.")
|
|
|
|
|
|
|
|
(defun url--allowed-chars (char-list)
|
|
|
|
"Return an \"allowed character\" mask (a 256-slot vector).
|
|
|
|
The Nth element is non-nil if character N is in CHAR-LIST. The
|
|
|
|
result can be passed as the second arg to `url-hexify-string'."
|
|
|
|
(let ((vec (make-vector 256 nil)))
|
|
|
|
(dolist (byte char-list)
|
|
|
|
(ignore-errors (aset vec byte t)))
|
|
|
|
vec))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
2012-05-09 16:33:48 +08:00
|
|
|
(defun url-hexify-string (string &optional allowed-chars)
|
|
|
|
"URI-encode STRING and return the result.
|
|
|
|
If STRING is multibyte, it is first converted to a utf-8 byte
|
|
|
|
string. Each byte corresponding to an allowed character is left
|
|
|
|
as-is, while all other bytes are converted to a three-character
|
2012-05-09 20:20:26 +08:00
|
|
|
string: \"%\" followed by two upper-case hex digits.
|
2012-05-09 16:33:48 +08:00
|
|
|
|
|
|
|
The allowed characters are specified by ALLOWED-CHARS. If this
|
|
|
|
argument is nil, the list `url-unreserved-chars' determines the
|
2019-10-14 06:46:47 +02:00
|
|
|
allowed characters. Otherwise, ALLOWED-CHARS should be either a
|
|
|
|
list of allowed chars, or a vector whose Nth element is non-nil
|
|
|
|
if character N is allowed."
|
|
|
|
(if allowed-chars
|
|
|
|
(unless (vectorp allowed-chars)
|
|
|
|
(setq allowed-chars (url--allowed-chars allowed-chars)))
|
2012-05-09 16:33:48 +08:00
|
|
|
(setq allowed-chars (url--allowed-chars url-unreserved-chars)))
|
2006-07-31 21:36:43 +00:00
|
|
|
(mapconcat (lambda (byte)
|
2012-05-09 16:33:48 +08:00
|
|
|
(if (aref allowed-chars byte)
|
|
|
|
(char-to-string byte)
|
|
|
|
(aref url-encoding-table byte)))
|
|
|
|
(if (multibyte-string-p string)
|
|
|
|
(encode-coding-string string 'utf-8)
|
|
|
|
string)
|
|
|
|
""))
|
|
|
|
|
|
|
|
(defconst url-host-allowed-chars
|
|
|
|
;; Allow % to avoid re-encoding %-encoded sequences.
|
|
|
|
(url--allowed-chars (append '(?% ?! ?$ ?& ?' ?\( ?\) ?* ?+ ?, ?\; ?=)
|
|
|
|
url-unreserved-chars))
|
|
|
|
"Allowed-character byte mask for the host segment of a URI.
|
|
|
|
These characters are specified in RFC 3986, Appendix A.")
|
|
|
|
|
|
|
|
(defconst url-path-allowed-chars
|
|
|
|
(let ((vec (copy-sequence url-host-allowed-chars)))
|
|
|
|
(aset vec ?/ t)
|
|
|
|
(aset vec ?: t)
|
|
|
|
(aset vec ?@ t)
|
|
|
|
vec)
|
|
|
|
"Allowed-character byte mask for the path segment of a URI.
|
|
|
|
These characters are specified in RFC 3986, Appendix A.")
|
|
|
|
|
|
|
|
(defconst url-query-allowed-chars
|
|
|
|
(let ((vec (copy-sequence url-path-allowed-chars)))
|
|
|
|
(aset vec ?? t)
|
|
|
|
vec)
|
|
|
|
"Allowed-character byte mask for the query segment of a URI.
|
|
|
|
These characters are specified in RFC 3986, Appendix A.")
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-encode-url (url)
|
|
|
|
"Return a properly URI-encoded version of URL.
|
|
|
|
This function also performs URI normalization, e.g. converting
|
|
|
|
the scheme to lowercase if it is uppercase. Apart from
|
|
|
|
normalization, if URL is already URI-encoded, this function
|
|
|
|
should return it unchanged."
|
|
|
|
(let* ((obj (url-generic-parse-url url))
|
|
|
|
(user (url-user obj))
|
|
|
|
(pass (url-password obj))
|
2017-05-10 03:34:16 +03:00
|
|
|
(path-and-query (url-path-and-query obj))
|
2012-05-10 14:27:12 +08:00
|
|
|
(path (car path-and-query))
|
|
|
|
(query (cdr path-and-query))
|
|
|
|
(frag (url-target obj)))
|
2012-05-09 16:33:48 +08:00
|
|
|
(if user
|
|
|
|
(setf (url-user obj) (url-hexify-string user)))
|
|
|
|
(if pass
|
|
|
|
(setf (url-password obj) (url-hexify-string pass)))
|
2012-05-10 14:27:12 +08:00
|
|
|
(if path
|
|
|
|
(setq path (url-hexify-string path url-path-allowed-chars)))
|
|
|
|
(if query
|
|
|
|
(setq query (url-hexify-string query url-query-allowed-chars)))
|
|
|
|
(setf (url-filename obj) (if query (concat path "?" query) path))
|
|
|
|
|
2012-05-09 16:33:48 +08:00
|
|
|
(if frag
|
|
|
|
(setf (url-target obj)
|
|
|
|
(url-hexify-string frag url-query-allowed-chars)))
|
|
|
|
(url-recreate-url obj)))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-file-extension (fname &optional x)
|
|
|
|
"Return the filename extension of FNAME.
|
Typo and docstring fixes.
* url.el (url-do-setup):
* url-dired.el (url-dired-minor-mode):
* url-file.el (url-file-find-possibly-compressed-file):
* url-gw.el (url-gateway-broken-resolution):
* url-handlers.el (url-handler-regexp):
* url-imap.el (url-imap-default-port):
* url-methods.el (url-scheme-get-property): Fix typos in docstrings.
* url-auth.el (url-basic-auth-storage, url-digest-auth):
Fix typos in docstrings.
(url-digest-auth-storage, url-register-auth-scheme): Reflow docstrings.
* url-cache.el (url-cache-prepare): Doc fix.
(url-cache-create-filename-human-readable, url-cache-extract):
Fix typos in docstrings.
* url-dav.el (url-intersection, url-dav-iso8601-regexp)
(url-dav-delete-something): Fix typos in docstrings.
(url-dav-http-success-p, url-dav-file-name-all-completions)
(url-dav-directory-files, url-dav-file-name-completion): Doc fixes.
* url-http.el (url-http-idle-sentinel): Doc fix.
* url-irc.el (url-irc-default-port): Fix typo in docstring.
(url-irc-function): Doc fix.
* url-util.el (url-get-url-filename-chars, url-unhex-string):
Fix typos in docstrings.
(url-file-extension): Doc fix.
* url-vars.el (url-current-object, url-current-mime-headers)
(url-privacy-level, url-mail-command, url-mime-language-string):
Fix typos in docstrings.
(url-honor-refresh-requests): Reflow docstring.
(url-using-proxy): Doc fix.
2008-07-02 11:14:38 +00:00
|
|
|
If optional argument X is t, then return the basename
|
|
|
|
of the file with the extension stripped off."
|
2004-04-04 01:21:46 +00:00
|
|
|
(if (and fname
|
2007-10-13 14:02:50 +00:00
|
|
|
(setq fname (url-file-nondirectory fname))
|
2004-04-04 01:21:46 +00:00
|
|
|
(string-match "\\.[^./]+$" fname))
|
|
|
|
(if x (substring fname 0 (match-beginning 0))
|
|
|
|
(substring fname (match-beginning 0) nil))
|
|
|
|
;;
|
|
|
|
;; If fname has no extension, and x then return fname itself instead of
|
|
|
|
;; nothing. When caching it allows the correct .hdr file to be produced
|
|
|
|
;; for filenames without extension.
|
|
|
|
;;
|
|
|
|
(if x
|
|
|
|
fname
|
|
|
|
"")))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-truncate-url-for-viewing (url &optional width)
|
2009-01-13 01:53:45 +00:00
|
|
|
"Return a shortened version of URL that is WIDTH characters wide or less.
|
2004-04-04 01:21:46 +00:00
|
|
|
WIDTH defaults to the current frame width."
|
|
|
|
(let* ((fr-width (or width (frame-width)))
|
|
|
|
(str-width (length url))
|
|
|
|
(fname nil)
|
|
|
|
(modified 0)
|
|
|
|
(urlobj nil))
|
|
|
|
;; The first thing that can go are the search strings
|
|
|
|
(if (and (>= str-width fr-width)
|
Fix regular-expression glitches and typos
Problems reported by Mattias Engdegård in:
https://lists.gnu.org/r/emacs-devel/2019-03/msg00085.html
* admin/admin.el (set-version):
* lisp/allout.el (allout-latexify-one-item):
* lisp/arc-mode.el (archive-arc-rename-entry)
(archive-rar-summarize):
* lisp/calc/calc-graph.el (calc-graph-set-styles)
(calc-graph-hide):
* lisp/calc/calc-help.el (calc-describe-key):
* lisp/calc/calc-lang.el (math-compose-tex-func, eqn):
* lisp/calc/calc.el (calcDigit-key):
* lisp/cedet/ede/makefile-edit.el (makefile-macro-file-list):
* lisp/cedet/ede/speedbar.el (ede-tag-expand):
* lisp/cedet/semantic/sb.el (semantic-sb-show-extra)
(semantic-sb-expand-group):
* lisp/comint.el (comint-substitute-in-file-name):
* lisp/dired.el (dired-actual-switches):
* lisp/emacs-lisp/chart.el (chart-rmail-from):
* lisp/emacs-lisp/eieio-opt.el (eieio-sb-expand):
* lisp/emacs-lisp/eieio-speedbar.el (eieio-speedbar-object-expand):
* lisp/emacs-lisp/rx.el (rx-not, rx-atomic-p):
* lisp/emulation/viper-ex.el (viper-get-ex-token)
(viper-get-ex-pat, ex-set-read-variable):
* lisp/epg.el (epg--status-SIG_CREATED):
* lisp/erc/erc-speedbar.el (erc-speedbar-expand-user):
(erc-speedbar-expand-channel, erc-speedbar-expand-server)
* lisp/erc/erc.el (erc-is-message-ctcp-and-not-action-p)
(erc-banlist-update):
* lisp/eshell/em-dirs.el (eshell-parse-drive-letter, eshell/pwd):
* lisp/find-dired.el (find-dired):
* lisp/frame.el (frame-set-background-mode):
* lisp/generic-x.el (apache-log-generic-mode):
* lisp/gnus/gnus-art.el (gnus-button-valid-localpart-regexp):
* lisp/gnus/gnus.el (gnus-short-group-name):
* lisp/gnus/message.el (message-mailer-swallows-blank-line):
* lisp/ibuffer.el (ibuffer-fontification-alist):
* lisp/ido.el (ido-set-matches-1):
* lisp/info-xref.el (info-xref-lock-file-p):
* lisp/info.el (Info-dir-remove-duplicates)
(Info-unescape-quotes, Info-split-parameter-string)
(Info-speedbar-expand-node):
* lisp/international/mule.el (sgml-html-meta-auto-coding-function):
* lisp/isearch.el (isearch-pre-command-hook):
* lisp/language/ethio-util.el (ethio-fidel-to-tex-buffer):
* lisp/mail/rmail.el (rmail-collect-deleted):
* lisp/mh-e/mh-alias.el (mh-alias-suggest-alias):
* lisp/mh-e/mh-comp.el (mh-forward):
* lisp/mh-e/mh-search.el (mh-index-next-folder)
(mh-index-create-imenu-index):
* lisp/mh-e/mh-xface.el (mh-picon-get-image):
* lisp/minibuffer.el (completion--embedded-envvar-re):
* lisp/net/ange-ftp.el (ange-ftp-ls-parser):
* lisp/net/goto-addr.el (goto-address-mail-regexp)
(goto-address-find-address-at-point):
* lisp/net/pop3.el (pop3-read-response, pop3-user)
(pop3-pass, pop3-apop):
* lisp/net/tramp.el (tramp-ipv6-regexp)
(tramp-replace-environment-variables):
* lisp/nxml/nxml-maint.el (nxml-insert-target-repertoire-glyph-set):
* lisp/nxml/rng-uri.el (rng-uri-escape-multibyte):
* lisp/nxml/rng-xsd.el (rng-xsd-convert-any-uri):
* lisp/obsolete/pgg.el (pgg-fetch-key):
* lisp/obsolete/vip.el (vip-get-ex-token):
* lisp/org/ob-core.el (org-babel-string-read):
* lisp/org/org-agenda.el:
(org-agenda-add-entry-to-org-agenda-diary-file):
* lisp/org/org-element.el (org-element-keyword-parser):
* lisp/org/org-list.el (org-list-indent-item-generic):
* lisp/org/org-mhe.el (org-mhe-get-message-folder-from-index):
* lisp/org/org-mobile.el (org-mobile-apply):
* lisp/org/org-mouse.el (org-mouse-context-menu):
* lisp/org/org-plot.el (org-plot/gnuplot):
* lisp/org/org-protocol.el (org-protocol-flatten-greedy):
* lisp/org/org-table.el (org-table-copy-down)
(org-table-formula-make-cmp-string)
(org-table-get-stored-formulas, org-table-recalculate)
(org-table-edit-formulas):
* lisp/org/org.el (org-translate-link-from-planner)
(org-fill-line-break-nobreak-p):
* lisp/org/ox-ascii.el (org-ascii-item):
* lisp/org/ox-latex.el (org-latex-clean-invalid-line-breaks):
* lisp/org/ox.el (org-export-expand-include-keyword):
* lisp/progmodes/ada-xref.el (ada-treat-cmd-string):
* lisp/progmodes/cfengine.el (cfengine2-font-lock-keywords):
* lisp/progmodes/cperl-mode.el (cperl-to-comment-or-eol)
(cperl-find-pods-heres, cperl-fix-line-spacing)
(cperl-have-help-regexp, cperl-word-at-point-hard)
(cperl-make-regexp-x):
* lisp/progmodes/dcl-mode.el (dcl-option-value-offset):
* lisp/progmodes/etags.el (tag-implicit-name-match-p):
* lisp/progmodes/fortran.el (fortran-fill):
* lisp/progmodes/gdb-mi.el (gdb-speedbar-expand-node)
(gdb-locals-handler-custom):
* lisp/progmodes/grep.el (grep-mode-font-lock-keywords):
* lisp/progmodes/gud.el (gud-jdb-find-source-using-classpath):
* lisp/progmodes/js.el (js--continued-expression-p):
* lisp/progmodes/m4-mode.el (m4-font-lock-keywords):
* lisp/progmodes/meta-mode.el (meta-indent-level-count):
* lisp/progmodes/mixal-mode.el (mixal-font-lock-keywords):
* lisp/progmodes/opascal.el (opascal-find-unit-in-directory):
* lisp/progmodes/pascal.el (pascal-progbeg-re):
* lisp/progmodes/ruby-mode.el (ruby-expression-expansion-re)
(ruby-expr-beg, ruby-parse-partial)
(ruby-toggle-string-quotes, ruby-font-lock-keywords):
* lisp/progmodes/sql.el (sql--make-help-docstring):
* lisp/progmodes/verilog-mode.el (verilog-coverpoint-re)
(verilog-skip-forward-comment-p)
(verilog-read-sub-decls-gate)
(verilog-read-auto-template-middle):
* lisp/progmodes/vhdl-mode.el (vhdl-resolve-env-variable)
(vhdl-speedbar-expand-project, vhdl-speedbar-expand-entity)
(vhdl-speedbar-expand-architecture)
(vhdl-speedbar-expand-config, vhdl-speedbar-expand-package)
(vhdl-speedbar-dired):
* lisp/speedbar.el (speedbar-dired, speedbar-tag-file)
(speedbar-tag-expand):
* lisp/textmodes/dns-mode.el (dns-mode-font-lock-keywords):
* lisp/textmodes/flyspell.el (flyspell-debug-signal-word-checked):
* lisp/textmodes/ispell.el (ispell-process-line):
* lisp/textmodes/reftex-cite.el (reftex-end-of-bib-entry):
* lisp/textmodes/reftex-ref.el (reftex-replace-prefix-escapes):
* lisp/url/url-parse.el (url-generic-parse-url):
* lisp/url/url-util.el (url-truncate-url-for-viewing):
* lisp/vc/diff-mode.el (diff-unified->context):
* lisp/vc/vc-bzr.el (vc-bzr-error-regexp-alist):
* lisp/vc/vc-cvs.el (vc-cvs-parse-status):
* lisp/woman.el (woman0-el, woman-if-ignore)
(woman-change-fonts):
* lisp/xdg.el (xdg--substitute-home-env):
Fix regular-expression infelicities and typos.
Fix regular expression typos
Fix typos reported by Mattias Engdegård in:
that occurred in preloaded modules.
* lisp/frame.el (frame-set-background-mode):
* lisp/international/mule.el (sgml-html-meta-auto-coding-function):
* lisp/isearch.el (isearch-pre-command-hook):
* lisp/minibuffer.el (completion--embedded-envvar-re):
2019-03-04 18:00:00 -08:00
|
|
|
(string-match "\\?" url))
|
2004-04-04 01:21:46 +00:00
|
|
|
(setq url (concat (substring url 0 (match-beginning 0)) "?...")
|
2006-07-31 21:36:43 +00:00
|
|
|
str-width (length url)))
|
2004-04-04 01:21:46 +00:00
|
|
|
(if (< str-width fr-width)
|
|
|
|
nil ; Hey, we are done!
|
|
|
|
(setq urlobj (url-generic-parse-url url)
|
|
|
|
fname (url-filename urlobj)
|
|
|
|
fr-width (- fr-width 4))
|
|
|
|
(while (and (>= str-width fr-width)
|
|
|
|
(string-match "/" fname))
|
|
|
|
(setq fname (substring fname (match-end 0) nil)
|
|
|
|
modified (1+ modified))
|
2007-08-31 16:40:05 +00:00
|
|
|
(setf (url-filename urlobj) fname)
|
2004-04-04 01:21:46 +00:00
|
|
|
(setq url (url-recreate-url urlobj)
|
|
|
|
str-width (length url)))
|
|
|
|
(if (> modified 1)
|
|
|
|
(setq fname (concat "/.../" fname))
|
|
|
|
(setq fname (concat "/" fname)))
|
2007-08-31 16:40:05 +00:00
|
|
|
(setf (url-filename urlobj) fname)
|
2004-04-04 01:21:46 +00:00
|
|
|
(setq url (url-recreate-url urlobj)))
|
|
|
|
url))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-view-url (&optional no-show)
|
|
|
|
"View the current document's URL.
|
|
|
|
Optional argument NO-SHOW means just return the URL, don't show it in
|
|
|
|
the minibuffer.
|
|
|
|
|
|
|
|
This uses `url-current-object', set locally to the buffer."
|
|
|
|
(interactive)
|
|
|
|
(if (not url-current-object)
|
|
|
|
nil
|
|
|
|
(if no-show
|
|
|
|
(url-recreate-url url-current-object)
|
|
|
|
(message "%s" (url-recreate-url url-current-object)))))
|
|
|
|
|
2010-10-03 14:37:41 -07:00
|
|
|
(defvar url-get-url-filename-chars "-%.?@a-zA-Z0-9()_/:~=&"
|
|
|
|
"Valid characters in a URL.")
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(defun url-get-url-at-point (&optional pt)
|
|
|
|
"Get the URL closest to point, but don't change position.
|
|
|
|
Has a preference for looking backward when not directly on a symbol."
|
2019-05-13 15:17:00 -04:00
|
|
|
(declare (obsolete thing-at-point-url-at-point "27.1"))
|
2004-04-04 01:21:46 +00:00
|
|
|
;; Not at all perfect - point must be right in the name.
|
|
|
|
(save-excursion
|
|
|
|
(if pt (goto-char pt))
|
|
|
|
(let (start url)
|
|
|
|
(save-excursion
|
|
|
|
;; first see if you're just past a filename
|
|
|
|
(if (not (eobp))
|
|
|
|
(if (looking-at "[] \t\n[{}()]") ; whitespace or some parens
|
|
|
|
(progn
|
|
|
|
(skip-chars-backward " \n\t\r({[]})")
|
|
|
|
(if (not (bobp))
|
|
|
|
(backward-char 1)))))
|
|
|
|
(if (and (char-after (point))
|
2010-10-03 14:37:41 -07:00
|
|
|
(string-match (concat "[" url-get-url-filename-chars "]")
|
2004-04-04 01:21:46 +00:00
|
|
|
(char-to-string (char-after (point)))))
|
|
|
|
(progn
|
|
|
|
(skip-chars-backward url-get-url-filename-chars)
|
|
|
|
(setq start (point))
|
|
|
|
(skip-chars-forward url-get-url-filename-chars))
|
|
|
|
(setq start (point)))
|
|
|
|
(setq url (buffer-substring-no-properties start (point))))
|
2017-06-18 09:09:34 +02:00
|
|
|
(if (and url (string-match "^(\\(.*\\))\\.?$" url))
|
2004-04-04 01:21:46 +00:00
|
|
|
(setq url (match-string 1 url)))
|
|
|
|
(if (and url (string-match "^URL:" url))
|
|
|
|
(setq url (substring url 4 nil)))
|
|
|
|
(if (and url (string-match "\\.$" url))
|
|
|
|
(setq url (substring url 0 -1)))
|
|
|
|
(if (and url (string-match "^www\\." url))
|
|
|
|
(setq url (concat "http://" url)))
|
|
|
|
(if (and url (not (string-match url-nonrelative-link url)))
|
|
|
|
(setq url nil))
|
|
|
|
url)))
|
|
|
|
|
|
|
|
(defun url-extract-mime-headers ()
|
|
|
|
"Set `url-current-mime-headers' in current buffer."
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(unless url-current-mime-headers
|
2020-12-06 08:50:51 +01:00
|
|
|
(setq-local url-current-mime-headers
|
|
|
|
(mail-header-extract)))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
2007-12-11 05:48:40 +00:00
|
|
|
(defun url-make-private-file (file)
|
|
|
|
"Make FILE only readable and writable by the current user.
|
|
|
|
Creates FILE and its parent directories if they do not exist."
|
|
|
|
(let ((dir (file-name-directory file)))
|
|
|
|
(when dir
|
|
|
|
;; For historical reasons.
|
|
|
|
(make-directory dir t)))
|
|
|
|
;; Based on doc-view-make-safe-dir.
|
|
|
|
(condition-case nil
|
2014-05-14 10:15:15 -07:00
|
|
|
(with-file-modes #o0600
|
|
|
|
(with-temp-buffer
|
|
|
|
(write-region (point-min) (point-max) file nil 'silent nil 'excl)))
|
2007-12-11 05:48:40 +00:00
|
|
|
(file-already-exists
|
Add 'nofollow' flag to set-file-modes etc.
This avoids some race conditions (Bug#39683). E.g., if some other
program changes a file to a symlink between the time Emacs creates
the file and the time it changes the file’s permissions, using the
new flag prevents Emacs from inadvertently changing the
permissions of a victim in some completely unrelated directory.
* admin/merge-gnulib (GNULIB_MODULES): Add fchmodat.
* doc/lispref/files.texi (Testing Accessibility, Changing Files):
* doc/lispref/os.texi (File Notifications):
* etc/NEWS:
Adjust documentation accordingly.
* lib/chmodat.c, lib/fchmodat.c, lib/lchmod.c, m4/fchmodat.m4:
* m4/lchmod.m4: New files, copied from Gnulib.
* lib/gnulib.mk.in: Regenerate.
* lisp/dired-aux.el (dired-do-chmod):
* lisp/doc-view.el (doc-view-make-safe-dir):
* lisp/emacs-lisp/autoload.el (autoload--save-buffer):
* lisp/emacs-lisp/bytecomp.el (byte-compile-file):
* lisp/eshell/em-pred.el (eshell-pred-file-mode):
* lisp/files.el (backup-buffer-copy, copy-directory):
* lisp/gnus/mail-source.el (mail-source-movemail):
* lisp/gnus/mm-decode.el (mm-display-external):
* lisp/gnus/nnmail.el (nnmail-write-region):
* lisp/net/tramp-adb.el (tramp-adb-handle-file-local-copy)
(tramp-adb-handle-write-region):
* lisp/net/tramp-sh.el (tramp-do-copy-or-rename-file-directly):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-write-region):
* lisp/net/tramp.el (tramp-handle-write-region)
(tramp-make-tramp-temp-file):
* lisp/server.el (server-ensure-safe-dir):
* lisp/url/url-util.el (url-make-private-file):
When getting or setting file modes, avoid following symbolic links
when the file is not supposed to be a symbolic link.
* lisp/doc-view.el (doc-view-make-safe-dir):
Omit no-longer-needed separate symlink test.
* lisp/gnus/gnus-util.el (gnus-set-file-modes):
* lisp/net/tramp.el (tramp-handle-file-modes):
* lisp/net/tramp-gvfs.el (tramp-gvfs-handle-set-file-modes):
* src/fileio.c (symlink_nofollow_flag): New function.
(Ffile_modes, Fset_file_modes):
Support an optional FLAG arg. All C callers changed.
* lisp/net/ange-ftp.el (ange-ftp-set-file-modes):
* lisp/net/tramp-adb.el (tramp-adb-handle-set-file-modes):
* lisp/net/tramp-sh.el (tramp-sh-handle-set-file-modes):
* lisp/net/tramp-smb.el (tramp-smb-handle-set-file-modes):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-set-file-modes):
Accept an optional FLAG arg that is currently ignored,
and add a FIXME comment for it.
* m4/gnulib-comp.m4: Regenerate.
2020-02-23 16:19:42 -08:00
|
|
|
(set-file-modes file #o0600 'nofollow))))
|
2007-12-11 05:48:40 +00:00
|
|
|
|
2018-04-19 21:18:24 -04:00
|
|
|
(autoload 'puny-encode-domain "puny")
|
2018-05-01 14:26:27 +02:00
|
|
|
(autoload 'url-domsuf-cookie-allowed-p "url-domsuf")
|
2018-04-13 15:08:18 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-domain (url)
|
2018-05-01 14:29:11 +02:00
|
|
|
"Return the domain of the host of the URL.
|
|
|
|
Return nil if this can't be determined.
|
|
|
|
|
|
|
|
For instance, this function will return \"fsf.co.uk\" if the host in URL
|
|
|
|
is \"www.fsf.co.uk\"."
|
2018-05-01 14:26:27 +02:00
|
|
|
(let* ((host (puny-encode-domain (url-host url)))
|
|
|
|
(parts (nreverse (split-string host "\\.")))
|
|
|
|
(candidate (pop parts))
|
|
|
|
found)
|
|
|
|
;; IP addresses aren't domains.
|
|
|
|
(when (string-match "\\`[0-9.]+\\'" host)
|
|
|
|
(setq parts nil))
|
|
|
|
;; We assume that the top-level domain is never an appropriate
|
|
|
|
;; thing as "the domain", so we start at the next one (eg.
|
|
|
|
;; "fsf.org").
|
|
|
|
(while (and parts
|
|
|
|
(not (setq found
|
|
|
|
(url-domsuf-cookie-allowed-p
|
|
|
|
(setq candidate (concat (pop parts) "."
|
|
|
|
candidate))))))
|
|
|
|
)
|
|
|
|
(and found candidate)))
|
2018-04-13 15:08:18 +02:00
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
(provide 'url-util)
|
2004-04-04 04:44:10 +00:00
|
|
|
|
2004-04-16 22:05:32 +00:00
|
|
|
;;; url-util.el ends here
|