commit 4a51deb993d923767f0eddd4f350e636fe8d7c0b (HEAD, refs/remotes/origin/master) Author: João Távora Date: Tue Jun 5 17:20:43 2018 +0100 When navigating Flymake diagnostics, consider their severity The FILTER arg of flymake-goto-next-error, a list of types, includes every diagnostic with a severity number `eq` to those types. * lisp/progmodes/flymake.el (flymake--severity): New helper. (flymake-goto-next-error, flymake-goto-prev-error): Clarify meaning of FILTER. (flymake-goto-next-error): Interpret filter as a severity filter. (flymake--mode-line-format): Simplify. diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 27bf1bd17a..d8959c8356 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -540,6 +540,11 @@ associated `flymake-category' return DEFAULT." (cadr cat-probe)) default)))) +(defun flymake--severity (type) + "Get the severity for diagnostic TYPE." + (flymake--lookup-type-property type 'severity + (warning-numeric-level :error))) + (defun flymake--fringe-overlay-spec (bitmap &optional recursed) (if (and (symbolp bitmap) (boundp bitmap) @@ -980,8 +985,9 @@ arg, skip any diagnostics with a severity less than `:warning'. If `flymake-wrap-around' is non-nil and no more next diagnostics, resumes search from top. -FILTER is a list of diagnostic types, or nil, if no filter is to -be applied." +FILTER is a list of diagnostic types. Only diagnostics with +matching severities matching are considered. If nil (the +default) no filter is applied." ;; TODO: let filter be a number, a severity below which diags are ;; skipped. (interactive (list 1 @@ -995,9 +1001,12 @@ be applied." ov 'flymake-diagnostic))) (and diag - (or (not filter) - (memq (flymake--diag-type diag) - filter))))) + (or + (not filter) + (cl-find + (flymake--severity + (flymake--diag-type diag)) + filter :key #'flymake--severity))))) :compare (if (cl-plusp n) #'< #'>) :key #'overlay-start)) (tail (cl-member-if (lambda (ov) @@ -1021,10 +1030,10 @@ be applied." (funcall (overlay-get target 'help-echo) (selected-window) target (point))))) (interactive - (user-error "No more Flymake errors%s" + (user-error "No more Flymake diagnostics%s" (if filter - (format " of types %s" filter) - "")))))) + (format " of %s severity" + (mapconcat #'symbol-name filter ", ")) "")))))) (defun flymake-goto-prev-error (&optional n filter interactive) "Go to Nth previous Flymake diagnostic that matches FILTER. @@ -1035,8 +1044,9 @@ prefix arg, skip any diagnostics with a severity less than If `flymake-wrap-around' is non-nil and no more previous diagnostics, resumes search from bottom. -FILTER is a list of diagnostic types found in, or nil, if no -filter is to be applied." +FILTER is a list of diagnostic types. Only diagnostics with +matching severities matching are considered. If nil (the +default) no filter is applied." (interactive (list 1 (if current-prefix-arg '(:error :warning)) t)) @@ -1117,17 +1127,12 @@ filter is to be applied." ,@(unless (or all-disabled (null known)) (cl-loop - with get-severity = (lambda (type) - (flymake--lookup-type-property - type - 'severity - (warning-numeric-level :error))) for (type . severity) in (cl-sort (mapcar (lambda (type) - (cons type (funcall get-severity type))) + (cons type (flymake--severity type))) (cl-union (hash-table-keys diags-by-type) '(:error :warning) - :key get-severity)) + :key #'flymake--severity)) #'> :key #'cdr) for diags = (gethash type diags-by-type) commit fa794d1b603e52e2a80d69c5610b782904ee6a69 Author: João Távora Date: Tue Jun 5 15:13:02 2018 +0100 Obsolete Flymake's flymake-diagnostic-types-alist That varaiable was an association between symbols and properties, effecively duplicating symbol's property lists. It is simpler to just put properties on symbols. Backward compatibility to the old variable has been kept. * doc/misc/flymake.texi (Flymake error types): Don't mention flymake-diagnostic-types-alist. (Flymake error types): Rework section. (Backend functions): Refill a paragraph. (Flymake utility functions): Don't mention flymake-diagnostic-types-alist. (Proc customization variables): Don't mention flymake-diagnostic-types-alist. * etc/NEWS: Mention obsoletion of flymake-diagnostic-types-alist. * lisp/progmodes/flymake-proc.el (flymake-proc--diagnostics-for-pattern): Don't use flymake-diagnostic-types-alist. * lisp/progmodes/flymake.el: Rewrite commentary. (flymake-make-diagnostic, flymake-mode, flymake-goto-next-error) (flymake-goto-prev-error): Don't mention flymake-diagnostic-types-alist in docstring. (flymake-diagnostic-types-alist): Make obsolete. (:error, :warning, :note): Put flymake-category in these symbols. (flymake-error, flymake-warning, flymake-note): Put `flymake-bitmap', not `bitmap' in these symbols. (flymake--lookup-type-property, flymake--highlight-line): Rewrite. Honor flymake-diagnostic-types-alist for backward compatibility. * lisp/progmodes/python.el (python-flymake-msg-alist): Don't mention flymake-diagnostic-types-alist. diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi index 9260f4f22b..e7f4da75bb 100644 --- a/doc/misc/flymake.texi +++ b/doc/misc/flymake.texi @@ -275,54 +275,61 @@ The following sections discuss each approach in detail. @cindex customizing error types @cindex error types, customization -@vindex flymake-diagnostic-types-alist -The variable @code{flymake-diagnostic-types-alist} is looked up by -Flymake every time an annotation for a diagnostic is created in the -buffer. Specifically, this variable holds a table of correspondence -between symbols designating diagnostic types and an additional -sub-table of properties pertaining to each diagnostic type. - -Both tables are laid out in association list (@pxref{Association -Lists,,, elisp, The Emacs Lisp Reference Manual}) format, and thus can -be conveniently accessed with the functions of the @code{assoc} -family. - -You can use any symbol-value association in the properties sub-table, -but some symbols have special meaning as to where and how Flymake -presents the diagnostic: +To customize the appearance of error types, set properties on the +symbols associated with each diagnostic type. The standard diagnostic +symbols are @code{:error}, @code{:warning} and @code{:note} (though +the backend may define more, @pxref{Backend functions}). + +The following properties can be set: @itemize @item @cindex bitmap of diagnostic -@code{bitmap}, an image displayed in the fringe according to +@code{flymake-bitmap}, an image displayed in the fringe according to @code{flymake-fringe-indicator-position}. The value actually follows the syntax of @code{flymake-error-bitmap} (@pxref{Customizable variables}). It is overridden by any @code{before-string} overlay property. @item -@cindex severity of diagnostic -@code{severity} is a non-negative integer specifying the diagnostic's -severity. The higher the value, the more serious is the error. If -the overlay property @code{priority} is not specified, @code{severity} -is used to set it and help sort overlapping overlays. +@code{flymake-overlay-control}, an alist ((@var{OVPROP} . @var{VALUE}) +@var{...}) of further properties used to affect the appearance of +Flymake annotations. With the exception of @code{category} and +@code{evaporate}, these properties are applied directly to the created +overlay (@pxref{Overlay Properties,,, elisp, The Emacs Lisp Reference +Manual}). -@item -Every property pertaining to overlays (@pxref{Overlay Properties,,, -elisp, The Emacs Lisp Reference Manual}), except @code{category} and -@code{evaporate}. These properties are used to affect the appearance -of Flymake annotations. +As an example, here's how to make diagnostics of the type @code{:note} +stand out more prominently: -As an example, here's how to make errors (diagnostics of the type -@code{:error}) stand out even more prominently in the buffer, by -raising the characters using a @code{display} overlay property. +@example +(push '(face . highlight) (get :note 'flymake-overlay-control)) +@end example + +If you push another alist entry in front, it overrides the previous +one. So this effectively removes the face from @code{:note} +diagnostics: @example -(push '(display . (raise 1.2)) - (cdr (assoc :error flymake-diagnostic-types-alist))) +(push '(face . nil) (get :note 'flymake-overlay-control)) @end example +To restore the original look for @code{:note} types, empty or remove +its @code{flymake-overlay-control} property: + +@example +(put :note 'flymake-overlay-control '()) +@end example + +@item +@cindex severity of diagnostic +@code{flymake-severity} is a non-negative integer specifying the +diagnostic's severity. The higher the value, the more serious is the +error. If the overlay property @code{priority} is not specified in +@code{flymake-overlay-control}, @code{flymake-severity} is used to set +it and help sort overlapping overlays. + @item @vindex flymake-category @code{flymake-category} is a symbol whose property list is considered @@ -333,32 +340,29 @@ the default for missing values of any other properties. @vindex flymake-error @vindex flymake-warning @vindex flymake-note -Three default diagnostic types, @code{:error}, @code{:warning} and -@code{:note} are predefined in -@code{flymake-diagnostic-types-alist}. By default each lists a single +Three default diagnostic types are predefined: @code{:error}, +@code{:warning}, and @code{:note}. By default, each one of them has a @code{flymake-category} property whose value is, respectively, the -symbols @code{flymake-error}, @code{flymake-warning} and +category symbol @code{flymake-error}, @code{flymake-warning} and @code{flymake-note}. -These category symbols' plists is where the values of customizable -variables and faces such as @code{flymake-error-bitmap} are found. -Thus, if you change their plists, Flymake may stop honoring these -user customizations. +These category symbols' plist is where the values of customizable +variables and faces (such as @code{flymake-error-bitmap}) are found. +Thus, if you change their plists, Flymake may stop honoring these user +customizations. -The @code{flymake-category} special property is also especially useful -for backends which create diagnostics objects with non-default -types that differ from an existing type by only a few properties -(@pxref{Flymake utility functions}). +The @code{flymake-category} special property is especially useful for +backends which create diagnostics objects with non-default types that +differ from an existing type by only a few properties (@pxref{Flymake +utility functions}). As an example, consider configuring a new diagnostic type -@code{:low-priority-note} that behaves much like the @code{:note} -priority but without an overlay face. +@code{:low-priority-note} that behaves much like @code{:note}, but +without an overlay face. @example -(add-to-list - 'flymake-diagnostic-types-alist - `(:low-priority-note . ((face . nil) - (flymake-category . flymake-note)))) +(put :low-priority-note 'flymake-overlay-control '((face . nil))) +(put :low-priority-note 'flymake-category 'flymake-note) @end example @vindex flymake-diagnostics @@ -389,20 +393,17 @@ Internet search for the text of a @code{:warning} or @code{:error}. (eww-browse-url (concat "https://duckduckgo.com/?q=" - (replace-regexp-in-string " " - "+" - (flymake-diagnostic-text topmost-diag))) + (replace-regexp-in-string + " " "+" (flymake-diagnostic-text topmost-diag))) t))) (dolist (type '(:warning :error)) - (let ((a (assoc type flymake-diagnostic-types-alist))) - (setf (cdr a) - (append `((mouse-face . highlight) - (keymap . ,(let ((map (make-sparse-keymap))) - (define-key map [mouse-2] - 'my-search-for-message) - map))) - (cdr a))))) + (push '(mouse-face . highlight) (get type 'flymake-overlay-control)) + (push `(keymap . ,(let ((map (make-sparse-keymap))) + (define-key map [mouse-2] + 'my-search-for-message) + map)) + (get type 'flymake-overlay-control))) @end example @node Backend functions @@ -436,10 +437,10 @@ the first argument is always @var{report-fn}, a callback function detailed below; @item -the remaining arguments are keyword-value pairs of the -form @w{@code{(@var{:key} @var{value} @var{:key2} @var{value2}...)}}. Currently, -Flymake provides no such arguments, but backend functions must be -prepared to accept (and possibly ignore) any number of them. +the remaining arguments are keyword-value pairs of the form +@w{@code{(@var{:key} @var{value} @var{:key2} @var{value2}...)}}. +Currently, Flymake provides no such arguments, but backend functions +must be prepared to accept (and possibly ignore) any number of them. @end itemize Whenever Flymake or the user decide to re-check the buffer, backend @@ -512,9 +513,9 @@ by calling the function @code{flymake-make-diagnostic}. @deffn Function flymake-make-diagnostic buffer beg end type text Make a Flymake diagnostic for @var{buffer}'s region from @var{beg} to -@var{end}. @var{type} is a key to -@code{flymake-diagnostic-types-alist} and @var{text} is a description -of the problem detected in this region. +@var{end}. @var{type} is a diagnostic symbol (@pxref{Flymake error +types}), and @var{text} is a description of the problem detected in +this region. @end deffn @cindex access diagnostic object @@ -715,14 +716,13 @@ Patterns for error/warning messages in the form @code{(regexp file-idx line-idx col-idx err-text-idx)}. @xref{Parsing the output}. @item flymake-proc-diagnostic-type-pred -A function to classify a diagnostic text as particular type of -error. Should be a function taking an error text and returning one of -the symbols indexing @code{flymake-diagnostic-types-alist}. If non-nil -is returned but there is no such symbol in that table, a warning is -assumed. If nil is returned, an error is assumed. Can also be a -regular expression that should match only warnings. This variable -replaces the old @code{flymake-warning-re} and -@code{flymake-warning-predicate}. +A function to classify a diagnostic text as particular type of error. +Should be a function taking an error text and returning a diagnostic +symbol (@pxref{Flymake error types}). If non-nil is returned but +there is no such symbol in that table, a warning is assumed. If nil +is returned, an error is assumed. Can also be a regular expression +that should match only warnings. This variable replaces the old +@code{flymake-warning-re} and @code{flymake-warning-predicate}. @item flymake-proc-compilation-prevents-syntax-check A flag indicating whether compilation and syntax check of the same diff --git a/etc/NEWS b/etc/NEWS index 1b324986d9..01dcb441a7 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -176,6 +176,13 @@ interface that's more like functions like @code{search-forward}. It now treats the optional 2nd argument to mean that the URL should be shown in the currently selected window. +** Flymake + ++++ +*** The variable 'flymake-diagnostic-types-alist' is obsolete +You should instead set properties on known diagnostic symbols, like +':error' and ':warning', as demonstrated in the Flymake manual. + ** Package *** New 'package-quickstart' feature When 'package-quickstart' is non-nil, package.el precomputes a big autoloads diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el index e38e4a75d4..8600be9b97 100644 --- a/lisp/progmodes/flymake-proc.el +++ b/lisp/progmodes/flymake-proc.el @@ -196,11 +196,10 @@ from compile.el") 'flymake-proc-default-guess "Predicate matching against diagnostic text to detect its type. Takes a single argument, the diagnostic's text and should return -a value suitable for indexing -`flymake-diagnostic-types-alist' (which see). If the returned -value is nil, a type of `:error' is assumed. For some backward -compatibility, if a non-nil value is returned that doesn't -index that alist, a type of `:warning' is assumed. +a diagnostic symbol naming a type. If the returned value is nil, +a type of `:error' is assumed. For some backward compatibility, +if a non-nil value is returned that doesn't name a type, +`:warning' is assumed. Instead of a function, it can also be a string, a regular expression. A match indicates `:warning' type, otherwise @@ -516,8 +515,8 @@ Create parent directories as needed." :error)) ((functionp pred) (let ((probe (funcall pred message))) - (cond ((assoc-default probe - flymake-diagnostic-types-alist) + (cond ((and (symbolp probe) + (get probe 'flymake-category)) probe) (probe :warning) diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index ec933ad16b..27bf1bd17a 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -34,13 +34,77 @@ ;; results produced by these backends, as well as entry points for ;; backends to hook on to. ;; -;; The main entry points are `flymake-mode' and `flymake-start' +;; The main interactive entry point is the `flymake-mode' minor mode, +;; which periodically and automatically initiates checks as the user +;; is editing the buffer. The variables `flymake-no-changes-timeout', +;; `flymake-start-syntax-check-on-newline' and +;; `flymake-start-on-flymake-mode' give finer control over the events +;; triggering a check, as does the interactive command +;; `flymake-start', which immediately starts a check. ;; -;; The docstrings of these variables are relevant to understanding how -;; Flymake works for both the user and the backend programmer: +;; Shortly after each check, a summary of collected diagnostics should +;; appear in the mode-line. If it doesn't, there might not be a +;; suitable Flymake backend for the current buffer's major mode, in +;; which case Flymake will indicate this in the mode-line. The +;; indicator will be `!' (exclamation mark), if all the configured +;; backends errored (or decided to disable themselves) and `?' +;; (question mark) if no backends were even configured. ;; -;; * `flymake-diagnostic-functions' -;; * `flymake-diagnostic-types-alist' +;; For programmers interested in writing a new Flymake backend, the +;; docstring of `flymake-diagnostic-functions', the Flymake manual, +;; and the code of existing backends are probably a good starting +;; point. +;; +;; The user wishing to customize the appearance of error types should +;; set properties on the symbols associated with each diagnostic type. +;; The standard diagnostic symbols are `:error', `:warning' and +;; `:note' (though a specific backend may define and use more). The +;; following properties can be set: +;; +;; * `flymake-bitmap', an image displayed in the fringe according to +;; `flymake-fringe-indicator-position'. The value actually follows +;; the syntax of `flymake-error-bitmap' (which see). It is overridden +;; by any `before-string' overlay property. +;; +;; * `flymake-severity', a non-negative integer specifying the +;; diagnostic's severity. The higher, the more serious. If the +;; overlay property `priority' is not specified, `severity' is used to +;; set it and help sort overlapping overlays. +;; +;; * `flymake-overlay-control', an alist ((OVPROP . VALUE) ...) of +;; further properties used to affect the appearance of Flymake +;; annotations. With the exception of `category' and `evaporate', +;; these properties are applied directly to the created overlay. See +;; Info Node `(elisp)Overlay Properties'. +;; +;; * `flymake-category', a symbol whose property list is considered a +;; default for missing values of any other properties. This is useful +;; to backend authors when creating new diagnostic types that differ +;; from an existing type by only a few properties. The category +;; symbols `flymake-error', `flymake-warning' and `flymake-note' make +;; good candidates for values of this property. +;; +;; For instance, to omit the fringe bitmap displayed for the standard +;; `:note' type, set its `flymake-bitmap' property to nil: +;; +;; (put :note 'flymake-bitmap nil) +;; +;; To change the face for `:note' type, add a `face' entry to its +;; `flymake-overlay-control' property. +;; +;; (push '(face . highlight) (get :note 'flymake-overlay-control)) +;; +;; If you push another alist entry in front, it overrides the previous +;; one. So this effectively removes the face from `:note' +;; diagnostics. +;; +;; (push '(face . nil) (get :note 'flymake-overlay-control)) +;; +;; To erase customizations and go back to the original look for +;; `:note' types: +;; +;; (cl-remf (symbol-plist :note) 'flymake-overlay-control) +;; (cl-remf (symbol-plist :note) 'flymake-bitmap) ;; ;;; Code: @@ -232,10 +296,9 @@ generated it." text &optional data) "Make a Flymake diagnostic for BUFFER's region from BEG to END. -TYPE is a key to `flymake-diagnostic-types-alist' and TEXT is a -description of the problem detected in this region. DATA is any -object that the caller wishes to attach to the created diagnostic -for later retrieval." +TYPE is a key to symbol and TEXT is a description of the problem +detected in this region. DATA is any object that the caller +wishes to attach to the created diagnostic for later retrieval." (flymake--diag-make :buffer buffer :beg beg :end end :type type :text text :data data)) @@ -426,74 +489,56 @@ Currently accepted REPORT-KEY arguments are: (put 'flymake-diagnostic-functions 'safe-local-variable #'null) -(defvar flymake-diagnostic-types-alist - `((:error - . ((flymake-category . flymake-error))) - (:warning - . ((flymake-category . flymake-warning))) - (:note - . ((flymake-category . flymake-note)))) - "Alist ((KEY . PROPS)*) of properties of Flymake diagnostic types. -KEY designates a kind of diagnostic can be anything passed as -`:type' to `flymake-make-diagnostic'. - -PROPS is an alist of properties that are applied, in order, to -the diagnostics of the type designated by KEY. The recognized -properties are: - -* Every property pertaining to overlays, except `category' and - `evaporate' (see Info Node `(elisp)Overlay Properties'), used - to affect the appearance of Flymake annotations. - -* `bitmap', an image displayed in the fringe according to - `flymake-fringe-indicator-position'. The value actually - follows the syntax of `flymake-error-bitmap' (which see). It - is overridden by any `before-string' overlay property. - -* `severity', a non-negative integer specifying the diagnostic's - severity. The higher, the more serious. If the overlay - property `priority' is not specified, `severity' is used to set - it and help sort overlapping overlays. - -* `flymake-category', a symbol whose property list is considered - a default for missing values of any other properties. This is - useful to backend authors when creating new diagnostic types - that differ from an existing type by only a few properties.") +(put :error 'flymake-category 'flymake-error) +(put :warning 'flymake-category 'flymake-warning) +(put :note 'flymake-category 'flymake-note) + +(defvar flymake-diagnostic-types-alist `() "") +(make-obsolete-variable + 'flymake-diagnostic-types-alist + "Set properties on the diagnostic symbols instead. See Info +Node `(Flymake)Flymake error types'" + "27.1") (put 'flymake-error 'face 'flymake-error) -(put 'flymake-error 'bitmap 'flymake-error-bitmap) +(put 'flymake-error 'flymake-bitmap 'flymake-error-bitmap) (put 'flymake-error 'severity (warning-numeric-level :error)) (put 'flymake-error 'mode-line-face 'compilation-error) (put 'flymake-warning 'face 'flymake-warning) -(put 'flymake-warning 'bitmap 'flymake-warning-bitmap) +(put 'flymake-warning 'flymake-bitmap 'flymake-warning-bitmap) (put 'flymake-warning 'severity (warning-numeric-level :warning)) (put 'flymake-warning 'mode-line-face 'compilation-warning) (put 'flymake-note 'face 'flymake-note) -(put 'flymake-note 'bitmap 'flymake-note-bitmap) +(put 'flymake-note 'flymake-bitmap 'flymake-note-bitmap) (put 'flymake-note 'severity (warning-numeric-level :debug)) (put 'flymake-note 'mode-line-face 'compilation-info) (defun flymake--lookup-type-property (type prop &optional default) - "Look up PROP for TYPE in `flymake-diagnostic-types-alist'. -If TYPE doesn't declare PROP in either -`flymake-diagnostic-types-alist' or in the symbol of its + "Look up PROP for diagnostic TYPE. +If TYPE doesn't declare PROP in its plist or in the symbol of its associated `flymake-category' return DEFAULT." - (let ((alist-probe (assoc type flymake-diagnostic-types-alist))) - (cond (alist-probe - (let* ((alist (cdr alist-probe)) - (prop-probe (assoc prop alist))) - (if prop-probe - (cdr prop-probe) - (if-let* ((cat (assoc-default 'flymake-category alist)) - (plist (and (symbolp cat) - (symbol-plist cat))) - (cat-probe (plist-member plist prop))) - (cadr cat-probe) - default)))) - (t - default)))) + ;; This function also consults `flymake-diagnostic-types-alist' for + ;; backward compatibility. + ;; + (if (plist-member (symbol-plist type) prop) + ;; allow nil values to survive + (get type prop) + (let (alist) + (or + (alist-get + prop (setq + alist + (alist-get type flymake-diagnostic-types-alist))) + (when-let* ((cat (or + (get type 'flymake-category) + (alist-get 'flymake-category alist))) + (plist (and (symbolp cat) + (symbol-plist cat))) + (cat-probe (plist-member plist prop))) + (cadr cat-probe)) + default)))) (defun flymake--fringe-overlay-spec (bitmap &optional recursed) (if (and (symbolp bitmap) @@ -510,34 +555,38 @@ associated `flymake-category' return DEFAULT." (list bitmap))))))) (defun flymake--highlight-line (diagnostic) - "Highlight buffer with info in DIAGNOSTIC." - (when-let* ((ov (make-overlay + "Highlight buffer with info in DIGNOSTIC." + (when-let* ((type (flymake--diag-type diagnostic)) + (ov (make-overlay (flymake--diag-beg diagnostic) (flymake--diag-end diagnostic)))) - ;; First set `category' in the overlay, then copy over every other - ;; property. + ;; First set `category' in the overlay ;; - (let ((alist (assoc-default (flymake--diag-type diagnostic) - flymake-diagnostic-types-alist))) - (overlay-put ov 'category (assoc-default 'flymake-category alist)) - (cl-loop for (k . v) in alist - unless (eq k 'category) - do (overlay-put ov k v))) + (overlay-put ov 'category + (flymake--lookup-type-property type 'flymake-category)) + ;; Now "paint" the overlay with all the other non-category + ;; properties. + (cl-loop + for (ov-prop . value) in + (append (reverse ; ensure ealier props override later ones + (flymake--lookup-type-property type 'flymake-overlay-control)) + (alist-get type flymake-diagnostic-types-alist)) + do (overlay-put ov ov-prop value)) ;; Now ensure some essential defaults are set ;; (cl-flet ((default-maybe (prop value) - (unless (or (plist-member (overlay-properties ov) prop) - (let ((cat (overlay-get ov - 'flymake-category))) - (and cat - (plist-member (symbol-plist cat) prop)))) - (overlay-put ov prop value)))) - (default-maybe 'bitmap 'flymake-error-bitmap) + (unless (plist-member (overlay-properties ov) prop) + (overlay-put ov prop (flymake--lookup-type-property + type prop value))))) (default-maybe 'face 'flymake-error) (default-maybe 'before-string (flymake--fringe-overlay-spec - (overlay-get ov 'bitmap))) + (flymake--lookup-type-property + type + 'flymake-bitmap + (alist-get 'bitmap (alist-get type ; backward compat + flymake-diagnostic-types-alist))))) (default-maybe 'help-echo (lambda (window _ov pos) (with-selected-window window @@ -825,7 +874,9 @@ The commands `flymake-goto-next-error' and diagnostics annotated in the buffer. The visual appearance of each type of diagnostic can be changed -in the variable `flymake-diagnostic-types-alist'. +by setting properties `flymake-overlay-control', `flymake-bitmap' +and `flymake-severity' on the symbols of diagnostic types (like +`:error', `:warning' and `:note'). Activation or deactivation of backends used by Flymake in each buffer happens via the special hook @@ -929,9 +980,8 @@ arg, skip any diagnostics with a severity less than `:warning'. If `flymake-wrap-around' is non-nil and no more next diagnostics, resumes search from top. -FILTER is a list of diagnostic types found in -`flymake-diagnostic-types-alist', or nil, if no filter is to be -applied." +FILTER is a list of diagnostic types, or nil, if no filter is to +be applied." ;; TODO: let filter be a number, a severity below which diags are ;; skipped. (interactive (list 1 @@ -985,9 +1035,8 @@ prefix arg, skip any diagnostics with a severity less than If `flymake-wrap-around' is non-nil and no more previous diagnostics, resumes search from bottom. -FILTER is a list of diagnostic types found in -`flymake-diagnostic-types-alist', or nil, if no filter is to be -applied." +FILTER is a list of diagnostic types found in, or nil, if no +filter is to be applied." (interactive (list 1 (if current-prefix-arg '(:error :warning)) t)) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index a09ca2f2f2..6f4a343310 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5209,9 +5209,10 @@ be used." (defcustom python-flymake-msg-alist '(("\\(^redefinition\\|.*unused.*\\|used$\\)" . :warning)) "Alist used to associate messages to their types. -Each element should be a cons-cell (REGEXP . TYPE), where TYPE must be -one defined in the variable `flymake-diagnostic-types-alist'. -For example, when using `flake8' a possible configuration could be: +Each element should be a cons-cell (REGEXP . TYPE), where TYPE +should be a diagnostic type symbol like `:error', `:warning' or +`:note'. For example, when using `flake8' a possible +configuration could be: ((\"\\(^redefinition\\|.*unused.*\\|used$\\)\" . :warning) (\"^E999\" . :error) commit aadac04923c9ae47f0bccc706857b94166c9d355 Author: João Távora Date: Tue Jun 5 14:31:38 2018 +0100 Correctly filter Flymake diagnostic types shown in mode-line Thus, if a package foo has its own types foo-error and foo-warning, and if the buffer has no errors, the mode-line will correctly show `[0 0]' (zero errors and warnings) instead of `[0 0 0 0]' (zero errors, zero foo-errors, zero warnings, zero foo-warnings). * lisp/progmodes/flymake.el (flymake--mode-line-format): Coalesce diagnostic types based on the severity, not the symbol. diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 35d5672544..ec933ad16b 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -1068,14 +1068,17 @@ applied." ,@(unless (or all-disabled (null known)) (cl-loop + with get-severity = (lambda (type) + (flymake--lookup-type-property + type + 'severity + (warning-numeric-level :error))) for (type . severity) in (cl-sort (mapcar (lambda (type) - (cons type (flymake--lookup-type-property - type - 'severity - (warning-numeric-level :error)))) + (cons type (funcall get-severity type))) (cl-union (hash-table-keys diags-by-type) - '(:error :warning))) + '(:error :warning) + :key get-severity)) #'> :key #'cdr) for diags = (gethash type diags-by-type) commit fb759a75007d38a8aea6e8c1a22bbc004453a73f Author: João Távora Date: Tue Jun 5 14:25:47 2018 +0100 Let Flymake backends attach arbitrary data to diagnostics This is easier that setting properties on diagnostics' text. * lisp/progmodes/flymake.el (flymake--diag): Add data slot. (flymake-make-diagnostic): Add DATA arg. (flymake-diagnostic-data): New accessor. diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index ee0da45bd9..35d5672544 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -222,18 +222,22 @@ generated it." (cl-defstruct (flymake--diag (:constructor flymake--diag-make)) - buffer beg end type text backend) + buffer beg end type text backend data) ;;;###autoload (defun flymake-make-diagnostic (buffer beg end type - text) + text + &optional data) "Make a Flymake diagnostic for BUFFER's region from BEG to END. TYPE is a key to `flymake-diagnostic-types-alist' and TEXT is a -description of the problem detected in this region." - (flymake--diag-make :buffer buffer :beg beg :end end :type type :text text)) +description of the problem detected in this region. DATA is any +object that the caller wishes to attach to the created diagnostic +for later retrieval." + (flymake--diag-make :buffer buffer :beg beg :end end + :type type :text text :data data)) ;;;###autoload (defun flymake-diagnostics (&optional beg end) @@ -257,6 +261,7 @@ diagnostics at BEG." (flymake--diag-accessor flymake-diagnostic-beg flymake--diag-beg beg) (flymake--diag-accessor flymake-diagnostic-end flymake--diag-end end) (flymake--diag-accessor flymake-diagnostic-backend flymake--diag-backend backend) +(flymake--diag-accessor flymake-diagnostic-data flymake--diag-data backend) (cl-defun flymake--overlays (&key beg end filter compare key) "Get flymake-related overlays. commit bd4f22b6289d51762db1365d8d05de529ec77aeb Author: João Távora Date: Tue Jun 5 14:20:42 2018 +0100 Update version information for Flymake package and manual * doc/misc/flymake.texi: Update date and version. Make myself the first author. * lisp/progmodes/flymake.el: Update Maintainer and Version fields. * lisp/progmodes/flymake-proc.el (flymake-proc--diagnostics-for-pattern): Update Maintainer and Version fields. diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi index eb82ef04ad..9260f4f22b 100644 --- a/doc/misc/flymake.texi +++ b/doc/misc/flymake.texi @@ -1,8 +1,8 @@ \input texinfo @c -*-texinfo; coding: utf-8 -*- @comment %**start of header @setfilename ../../info/flymake.info -@set VERSION 0.3 -@set UPDATED April 2004 +@set VERSION 1.0 +@set UPDATED June 2018 @settitle GNU Flymake @value{VERSION} @include docstyle.texi @syncodeindex pg cp @@ -37,7 +37,7 @@ modify this GNU manual.'' @titlepage @title GNU Flymake @subtitle for version @value{VERSION}, @value{UPDATED} -@author Pavel Kobiakov(@email{pk_at_work@@yahoo.com}) and João Távora. +@author João Távora and Pavel Kobiakov(@email{pk_at_work@@yahoo.com}). @page @vskip 0pt plus 1filll @insertcopying diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el index 867df7d138..e38e4a75d4 100644 --- a/lisp/progmodes/flymake-proc.el +++ b/lisp/progmodes/flymake-proc.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2003-2018 Free Software Foundation, Inc. ;; Author: Pavel Kobyakov -;; Maintainer: Leo Liu -;; Version: 0.3 +;; Maintainer: João Távora +;; Version: 1.0 ;; Keywords: c languages tools ;; This file is part of GNU Emacs. diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 56f43e4bb3..ee0da45bd9 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2003-2018 Free Software Foundation, Inc. ;; Author: Pavel Kobyakov -;; Maintainer: Leo Liu -;; Version: 0.3 +;; Maintainer: João Távora +;; Version: 1.0 ;; Keywords: c languages tools ;; This file is part of GNU Emacs. commit 5d23382455c8b7a89ab81415a1c2aacd54438a61 Author: Damien Cassou Date: Mon Mar 26 09:04:36 2018 +0200 * lisp/auth-source-pass.el: Update version to 4.0.1 diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index d5c6139814..cebe8c2666 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -4,7 +4,7 @@ ;; Author: Damien Cassou , ;; Nicolas Petton -;; Version: 4.0.0 +;; Version: 4.0.1 ;; Package-Requires: ((emacs "25")) ;; Url: https://github.com/DamienCassou/auth-password-store ;; Created: 07 Jun 2015 commit 47ccee220a49dea8c35318f83b854dfa368606ec Author: Damien Cassou Date: Mon Mar 26 08:56:16 2018 +0200 Test checking that auth-source-pass backend is correctly installed * test/lisp/auth-source-pass-tests.el (auth-source-pass-can-start-from-auth-source-search): Add test. diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 431e4e411d..b30419f44b 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -244,6 +244,13 @@ This function is intended to be set to `auth-source-debug`." (should (auth-source-pass--entry-valid-p "foo")) (should-not (auth-source-pass--entry-valid-p "bar")))) +(ert-deftest auth-source-pass-can-start-from-auth-source-search () + (auth-source-pass--with-store '(("gitlab.com" ("user" . "someone"))) + (auth-source-pass-enable) + (let ((result (car (auth-source-search :host "gitlab.com")))) + (should (equal (plist-get result :user) "someone")) + (should (equal (plist-get result :host) "gitlab.com"))))) + (provide 'auth-source-pass-tests) ;;; auth-source-pass-tests.el ends here commit 03c50fc7aecab0b42f9f80600d7cbc4c53bae54a Author: Damien Cassou Date: Mon Mar 26 06:28:17 2018 +0200 Make sure auth-source-pass is compatible with Emacs 25 * lisp/auth-source-pass.el: Use `advice-add' for Emacs 25 users as `auth-source-backend-parser-functions' does not exist there. diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 1193d67954..d5c6139814 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -92,7 +92,9 @@ See `auth-source-search' for details on SPEC." (when (eq entry 'password-store) (auth-source-backend-parse-parameters entry auth-source-pass-backend))) -(add-hook 'auth-source-backend-parser-functions #'auth-source-pass-backend-parse) +(if (boundp 'auth-source-backend-parser-functions) + (add-hook 'auth-source-backend-parser-functions #'auth-source-pass-backend-parse) + (advice-add 'auth-source-backend-parse :before-until #'auth-source-pass-backend-parse)) (defun auth-source-pass-get (key entry) commit a6cbdd4e6f75d40977719892af53fee5488a2c0e Author: Damien Cassou Date: Fri Mar 23 09:18:54 2018 +0100 * lisp/auth-source-pass.el: Update version to 4.0.0 diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 42c0344756..1193d67954 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -4,7 +4,7 @@ ;; Author: Damien Cassou , ;; Nicolas Petton -;; Version: 3.0.0 +;; Version: 4.0.0 ;; Package-Requires: ((emacs "25")) ;; Url: https://github.com/DamienCassou/auth-password-store ;; Created: 07 Jun 2015 commit a613326e67b568b0b7448331f99dc32a6932c8ad Author: Damien Cassou Date: Fri Mar 23 09:16:25 2018 +0100 Fix prefix messages of auth-source-pass debug messages * lisp/auth-source-pass.el (auth-source-pass--do-debug): Fix message prefix. diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index c8722a5579..42c0344756 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -150,7 +150,7 @@ CONTENTS is the contents of a password-store formatted file." (defun auth-source-pass--do-debug (&rest msg) "Call `auth-source-do-debug` with MSG and a prefix." (apply #'auth-source-do-debug - (cons (concat "auth-source-password-store: " (car msg)) + (cons (concat "auth-source-pass: " (car msg)) (cdr msg)))) (defun auth-source-pass--select-one-entry (entries user) commit 7b2d4754a28bd1d03ff43defaa80282b452dcd50 Author: Damien Cassou Date: Wed Feb 14 14:51:25 2018 +0100 * lisp/auth-source-pass.el: Update version to 3.0.0 diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index ec0fe8c432..c8722a5579 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -4,7 +4,7 @@ ;; Author: Damien Cassou , ;; Nicolas Petton -;; Version: 2.0.0 +;; Version: 3.0.0 ;; Package-Requires: ((emacs "25")) ;; Url: https://github.com/DamienCassou/auth-password-store ;; Created: 07 Jun 2015 commit 24cbb659541b13ad373082f6cf76df7cc5cc1f38 Author: Alex Branham Date: Mon Feb 12 13:28:20 2018 -0600 Silence byte compiler warning in auth-source-pass * lisp/auth-source-pass.el (auth-source-pass-backend): Silence byte compiler warning by only passing a parameter to `auth-source-backend' in Emacs <= 25. diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 461cba02dd..ec0fe8c432 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -81,7 +81,7 @@ See `auth-source-search' for details on SPEC." (defvar auth-source-pass-backend (auth-source-backend - (format "Password store") + (when (<= emacs-major-version 25) "password-store") :source "." ;; not used :type 'password-store :search-function #'auth-source-pass-search) commit 1d2551f8e70ab80a6f57ee11ab70f54aa916adcd Author: Jelle Licht Date: Mon Jan 8 17:34:38 2018 +0100 Fix auth-source-pass.el to properly handle special inputs * lisp/auth-source-pass.el (auth-source-pass-search): Warn when passing multiple hosts in SPEC. Early return and warn when passing a wildcard as host in SPEC. Early return when host is nil. * test/lisp/auth-source-pass-tests.el (auth-source-pass-any-host, auth-source-pass-undefined-host): Add corresponding tests. diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 96aefc8dd7..461cba02dd 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -45,10 +45,18 @@ See `auth-source-search' for details on SPEC." (cl-assert (or (null type) (eq type (oref backend type))) t "Invalid password-store search: %s %s") - (when (listp host) + (when (consp host) + (warn "auth-source-pass ignores all but first host in spec.") ;; Take the first non-nil item of the list of hosts (setq host (seq-find #'identity host))) - (list (auth-source-pass--build-result host port user))) + (cond ((eq host t) + (warn "auth-source-pass does not handle host wildcards.") + nil) + ((null host) + ;; Do not build a result, as none will match when HOST is nil + nil) + (t + (list (auth-source-pass--build-result host port user))))) (defun auth-source-pass--build-result (host port user) "Build auth-source-pass entry matching HOST, PORT and USER." diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 0f072592d0..431e4e411d 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -73,6 +73,17 @@ This function is intended to be set to `auth-source-debug`." (auth-source-pass--debug-log nil)) ,@body))) +(ert-deftest auth-source-pass-any-host () + (auth-source-pass--with-store '(("foo" ("port" . "foo-port") ("host" . "foo-user")) + ("bar")) + (should-not (auth-source-pass-search :host t)))) + +(ert-deftest auth-source-pass-undefined-host () + (auth-source-pass--with-store '(("foo" ("port" . "foo-port") ("host" . "foo-user")) + ("bar")) + (should-not (auth-source-pass-search :host nil)))) + + (ert-deftest auth-source-pass-find-match-matching-at-entry-name () (auth-source-pass--with-store '(("foo")) (should (equal (auth-source-pass--find-match "foo" nil nil) commit b43ed61ef985e01975b90d7e0ec3cac70d0afefa Author: Damien Cassou Date: Thu Nov 9 10:40:19 2017 +0100 auth-source-pass: Take care of matching hosts when port is provided * lisp/auth-source-pass.el (auth-source-pass--find-match): Add PORT parameter and reorganize code by extracting `find-match-unambiguous'. (auth-source-pass--find-match-unambiguous): New function. (auth-source-pass--build-result): Fix the call to `find-match'. (auth-source-pass--hostname, auth-source-pass--hostname-with-user, auth-source-pass--user): Remove functions. * test/lisp/auth-source-pass-tests.el: Fix the calls to `find-match'. (auth-source-pass-find-host-without-port) Add corresponding test. diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 1785ca3255..96aefc8dd7 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -52,7 +52,7 @@ See `auth-source-search' for details on SPEC." (defun auth-source-pass--build-result (host port user) "Build auth-source-pass entry matching HOST, PORT and USER." - (let ((entry (auth-source-pass--find-match host user))) + (let ((entry (auth-source-pass--find-match host user port))) (when entry (let ((retval (list :host host @@ -139,26 +139,6 @@ CONTENTS is the contents of a password-store formatted file." (mapconcat #'identity (cdr pair) ":"))))) (cdr lines))))) -(defun auth-source-pass--hostname (host) - "Extract hostname from HOST." - (let ((url (url-generic-parse-url host))) - (or (url-host url) host))) - -(defun auth-source-pass--hostname-with-user (host) - "Extract hostname and user from HOST." - (let* ((url (url-generic-parse-url host)) - (user (url-user url)) - (hostname (url-host url))) - (cond - ((and user hostname) (format "%s@%s" user hostname)) - (hostname hostname) - (t host)))) - -(defun auth-source-pass--user (host) - "Extract user from HOST and return it. -Return nil if no match was found." - (url-user (url-generic-parse-url host))) - (defun auth-source-pass--do-debug (&rest msg) "Call `auth-source-do-debug` with MSG and a prefix." (apply #'auth-source-do-debug @@ -230,27 +210,39 @@ matching USER." (car matching-entries)) (_ (auth-source-pass--select-one-entry matching-entries user))))) -(defun auth-source-pass--find-match (host user) - "Return a password-store entry name matching HOST and USER. -If many matches are found, return the first one. If no match is -found, return nil." +(defun auth-source-pass--find-match (host user port) + "Return a password-store entry name matching HOST, USER and PORT. + +Disambiguate between user provided inside HOST (e.g., user@server.com) and +inside USER by giving priority to USER. Same for PORT." + (let* ((url (url-generic-parse-url (if (string-match-p ".*://" host) + host + (format "https://%s" host))))) + (auth-source-pass--find-match-unambiguous + (or (url-host url) host) + (or user (url-user url)) + ;; url-port returns 443 (because of the https:// above) by default + (or port (number-to-string (url-port url)))))) + +(defun auth-source-pass--find-match-unambiguous (hostname user port) + "Return a password-store entry name matching HOSTNAME, USER and PORT. +If many matches are found, return the first one. If no match is found, +return nil. + +HOSTNAME should not contain any username or port number." (or - (if (auth-source-pass--user host) - ;; if HOST contains a user (e.g., "user@host.com"), - (auth-source-pass--find-one-by-entry-name (auth-source-pass--hostname-with-user host) user) - ;; otherwise, if USER is provided, search for @ - (when (stringp user) - (auth-source-pass--find-one-by-entry-name (concat user "@" (auth-source-pass--hostname host)) user))) - ;; if that didn't work, search for HOST without its user component, if any - (auth-source-pass--find-one-by-entry-name (auth-source-pass--hostname host) user) - ;; if that didn't work, search for HOST with user extracted from it - (auth-source-pass--find-one-by-entry-name - (auth-source-pass--hostname host) (auth-source-pass--user host)) + (and user port (auth-source-pass--find-one-by-entry-name (format "%s@%s:%s" user hostname port) user)) + (and user (auth-source-pass--find-one-by-entry-name (format "%s@%s" user hostname) user)) + (and port (auth-source-pass--find-one-by-entry-name (format "%s:%s" hostname port) nil)) + (auth-source-pass--find-one-by-entry-name hostname user) ;; if that didn't work, remove subdomain: foo.bar.com -> bar.com - (let ((components (split-string host "\\."))) + (let ((components (split-string hostname "\\."))) (when (= (length components) 3) ;; start from scratch - (auth-source-pass--find-match (mapconcat 'identity (cdr components) ".") user))))) + (auth-source-pass--find-match-unambiguous + (mapconcat 'identity (cdr components) ".") + user + port))))) (provide 'auth-source-pass) ;;; auth-source-pass.el ends here diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 6d471f4e34..0f072592d0 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -75,107 +75,100 @@ This function is intended to be set to `auth-source-debug`." (ert-deftest auth-source-pass-find-match-matching-at-entry-name () (auth-source-pass--with-store '(("foo")) - (should (equal (auth-source-pass--find-match "foo" nil) + (should (equal (auth-source-pass--find-match "foo" nil nil) "foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-part () (auth-source-pass--with-store '(("foo")) - (should (equal (auth-source-pass--find-match "https://foo" nil) + (should (equal (auth-source-pass--find-match "https://foo" nil nil) "foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-ignoring-user () (auth-source-pass--with-store '(("foo")) - (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) + (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) "foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-with-user () (auth-source-pass--with-store '(("SomeUser@foo")) - (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) + (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) "SomeUser@foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full () (auth-source-pass--with-store '(("SomeUser@foo") ("foo")) - (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) + (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) "SomeUser@foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full-reversed () (auth-source-pass--with-store '(("foo") ("SomeUser@foo")) - (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) + (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) "SomeUser@foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain () (auth-source-pass--with-store '(("bar.com")) - (should (equal (auth-source-pass--find-match "foo.bar.com" nil) + (should (equal (auth-source-pass--find-match "foo.bar.com" nil nil) "bar.com")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-user () (auth-source-pass--with-store '(("someone@bar.com")) - (should (equal (auth-source-pass--find-match "foo.bar.com" "someone") + (should (equal (auth-source-pass--find-match "foo.bar.com" "someone" nil) "someone@bar.com")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-bad-user () (auth-source-pass--with-store '(("someoneelse@bar.com")) - (should (equal (auth-source-pass--find-match "foo.bar.com" "someone") + (should (equal (auth-source-pass--find-match "foo.bar.com" "someone" nil) nil)))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-prefer-full () (auth-source-pass--with-store '(("bar.com") ("foo.bar.com")) - (should (equal (auth-source-pass--find-match "foo.bar.com" nil) + (should (equal (auth-source-pass--find-match "foo.bar.com" nil nil) "foo.bar.com")))) (ert-deftest auth-source-pass-dont-match-at-folder-name () (auth-source-pass--with-store '(("foo.bar.com/foo")) - (should (equal (auth-source-pass--find-match "foo.bar.com" nil) + (should (equal (auth-source-pass--find-match "foo.bar.com" nil nil) nil)))) (ert-deftest auth-source-pass-find-match-matching-extracting-user-from-host () (auth-source-pass--with-store '(("foo.com/bar")) - (should (equal (auth-source-pass--find-match "https://bar@foo.com" nil) + (should (equal (auth-source-pass--find-match "https://bar@foo.com" nil nil) "foo.com/bar")))) (ert-deftest auth-source-pass-search-with-user-first () (auth-source-pass--with-store '(("foo") ("user@foo")) - (should (equal (auth-source-pass--find-match "foo" "user") + (should (equal (auth-source-pass--find-match "foo" "user" nil) "user@foo")) (auth-source-pass--should-have-message-containing "Found 1 match"))) (ert-deftest auth-source-pass-give-priority-to-desired-user () (auth-source-pass--with-store '(("foo") ("subdir/foo" ("user" . "someone"))) - (should (equal (auth-source-pass--find-match "foo" "someone") + (should (equal (auth-source-pass--find-match "foo" "someone" nil) "subdir/foo")) (auth-source-pass--should-have-message-containing "Found 2 matches") (auth-source-pass--should-have-message-containing "matching user field"))) (ert-deftest auth-source-pass-give-priority-to-desired-user-reversed () (auth-source-pass--with-store '(("foo" ("user" . "someone")) ("subdir/foo")) - (should (equal (auth-source-pass--find-match "foo" "someone") + (should (equal (auth-source-pass--find-match "foo" "someone" nil) "foo")) (auth-source-pass--should-have-message-containing "Found 2 matches") (auth-source-pass--should-have-message-containing "matching user field"))) (ert-deftest auth-source-pass-return-first-when-several-matches () (auth-source-pass--with-store '(("foo") ("subdir/foo")) - (should (equal (auth-source-pass--find-match "foo" nil) + (should (equal (auth-source-pass--find-match "foo" nil nil) "foo")) (auth-source-pass--should-have-message-containing "Found 2 matches") (auth-source-pass--should-have-message-containing "the first one"))) (ert-deftest auth-source-pass-make-divansantana-happy () (auth-source-pass--with-store '(("host.com")) - (should (equal (auth-source-pass--find-match "smtp.host.com" "myusername@host.co.za") + (should (equal (auth-source-pass--find-match "smtp.host.com" "myusername@host.co.za" nil) "host.com")))) -(ert-deftest auth-source-pass-hostname () - (should (equal (auth-source-pass--hostname "https://foo.bar:443") "foo.bar")) - (should (equal (auth-source-pass--hostname "https://foo.bar") "foo.bar")) - (should (equal (auth-source-pass--hostname "http://foo.bar") "foo.bar")) - (should (equal (auth-source-pass--hostname "https://SomeUser@foo.bar") "foo.bar"))) - -(ert-deftest auth-source-pass-hostname-with-user () - (should (equal (auth-source-pass--hostname-with-user "https://foo.bar:443") "foo.bar")) - (should (equal (auth-source-pass--hostname-with-user "https://foo.bar") "foo.bar")) - (should (equal (auth-source-pass--hostname-with-user "http://foo.bar") "foo.bar")) - (should (equal (auth-source-pass--hostname-with-user "https://SomeUser@foo.bar") "SomeUser@foo.bar"))) +(ert-deftest auth-source-pass-find-host-without-port () + (auth-source-pass--with-store '(("host.com")) + (should (equal (auth-source-pass--find-match "host.com:8888" "someuser" nil) + "host.com")))) (defmacro auth-source-pass--with-store-find-foo (store &rest body) "Use STORE while executing BODY. \"foo\" is the matched entry." @@ -207,7 +200,7 @@ This function is intended to be set to `auth-source-debug`." (ert-deftest auth-source-pass-build-result-passes-full-host-to-find-match () (let (passed-host) (cl-letf (((symbol-function 'auth-source-pass--find-match) - (lambda (host _user) (setq passed-host host)))) + (lambda (host _user _port) (setq passed-host host)))) (auth-source-pass--build-result "https://user@host.com:123" nil nil) (should (equal passed-host "https://user@host.com:123")) (auth-source-pass--build-result "https://user@host.com" nil nil) commit a52661b58bc9cffa13cb5f0749cdb3a4c24fbf74 Author: Damien Cassou Date: Tue Nov 7 09:48:50 2017 +0100 Add missing test cases to auth-source-pass-tests.el * test/lisp/auth-source-pass-tests.el (auth-source-pass-build-result-passes-full-host-to-find-match): Add missing test cases. diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 2ddbcab233..6d471f4e34 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -209,7 +209,13 @@ This function is intended to be set to `auth-source-debug`." (cl-letf (((symbol-function 'auth-source-pass--find-match) (lambda (host _user) (setq passed-host host)))) (auth-source-pass--build-result "https://user@host.com:123" nil nil) - (should (equal passed-host "https://user@host.com:123"))))) + (should (equal passed-host "https://user@host.com:123")) + (auth-source-pass--build-result "https://user@host.com" nil nil) + (should (equal passed-host "https://user@host.com")) + (auth-source-pass--build-result "user@host.com" nil nil) + (should (equal passed-host "user@host.com")) + (auth-source-pass--build-result "user@host.com:443" nil nil) + (should (equal passed-host "user@host.com:443"))))) (ert-deftest auth-source-pass-only-return-entries-that-can-be-open () (cl-letf (((symbol-function 'auth-source-pass-entries) commit 5b31e6de99d2c56ba61ea439b0b44862813d9480 Author: Damien Cassou Date: Tue Nov 7 09:32:30 2017 +0100 Add a test to auth-source-pass-tests.el * test/lisp/auth-source-pass-tests.el (auth-source-pass-build-result-passes-full-host-to-find-match): Add test making sure find-match is called with full host. diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index adb0b5d93f..2ddbcab233 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -204,6 +204,13 @@ This function is intended to be set to `auth-source-debug`." (should (equal (plist-get result :port) 512)) (should (equal (plist-get result :user) "anuser"))))) +(ert-deftest auth-source-pass-build-result-passes-full-host-to-find-match () + (let (passed-host) + (cl-letf (((symbol-function 'auth-source-pass--find-match) + (lambda (host _user) (setq passed-host host)))) + (auth-source-pass--build-result "https://user@host.com:123" nil nil) + (should (equal passed-host "https://user@host.com:123"))))) + (ert-deftest auth-source-pass-only-return-entries-that-can-be-open () (cl-letf (((symbol-function 'auth-source-pass-entries) (lambda () '("foo.site.com" "bar.site.com" "mail/baz.site.com/scott"))) commit 53f044c22f9f94e7663b7343c5100904a68f6de5 Author: Damien Cassou Date: Tue Nov 7 09:33:22 2017 +0100 Fix indentation in auth-source-pass-tests.el * test/lisp/auth-source-pass-tests.el (auth-source-pass-only-return-entries-that-can-be-open): Fix indentation. diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 557a34ff59..adb0b5d93f 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -206,12 +206,10 @@ This function is intended to be set to `auth-source-debug`." (ert-deftest auth-source-pass-only-return-entries-that-can-be-open () (cl-letf (((symbol-function 'auth-source-pass-entries) - (lambda () '("foo.site.com" "bar.site.com" - "mail/baz.site.com/scott"))) + (lambda () '("foo.site.com" "bar.site.com" "mail/baz.site.com/scott"))) ((symbol-function 'auth-source-pass--entry-valid-p) ;; only foo.site.com and "mail/baz.site.com/scott" are valid - (lambda (entry) (member entry '("foo.site.com" - "mail/baz.site.com/scott"))))) + (lambda (entry) (member entry '("foo.site.com" "mail/baz.site.com/scott"))))) (should (equal (auth-source-pass--find-all-by-entry-name "foo.site.com" "someuser") '("foo.site.com"))) (should (equal (auth-source-pass--find-all-by-entry-name "bar.site.com" "someuser") commit 59d44b528e028192a7d3d576795a7957c92da682 Author: Edison Ibañez Date: Tue Nov 7 09:00:43 2017 +0100 * test/lisp/auth-source-pass-tests.el: Add assertions for host:port diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 86f59e5166..557a34ff59 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -166,11 +166,13 @@ This function is intended to be set to `auth-source-debug`." "host.com")))) (ert-deftest auth-source-pass-hostname () + (should (equal (auth-source-pass--hostname "https://foo.bar:443") "foo.bar")) (should (equal (auth-source-pass--hostname "https://foo.bar") "foo.bar")) (should (equal (auth-source-pass--hostname "http://foo.bar") "foo.bar")) (should (equal (auth-source-pass--hostname "https://SomeUser@foo.bar") "foo.bar"))) (ert-deftest auth-source-pass-hostname-with-user () + (should (equal (auth-source-pass--hostname-with-user "https://foo.bar:443") "foo.bar")) (should (equal (auth-source-pass--hostname-with-user "https://foo.bar") "foo.bar")) (should (equal (auth-source-pass--hostname-with-user "http://foo.bar") "foo.bar")) (should (equal (auth-source-pass--hostname-with-user "https://SomeUser@foo.bar") "SomeUser@foo.bar"))) commit a6b1cb01b12752204addc0db2ad016439574e05d Author: Damien Cassou Date: Thu Feb 22 17:58:07 2018 +0100 * lisp/auth-source-pass.el: Fix headers. diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 3e6a9cccbc..1785ca3255 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -5,9 +5,9 @@ ;; Author: Damien Cassou , ;; Nicolas Petton ;; Version: 2.0.0 -;; Package-Requires: ((emacs "24.4") +;; Package-Requires: ((emacs "25")) +;; Url: https://github.com/DamienCassou/auth-password-store ;; Created: 07 Jun 2015 -;; Keywords: pass password-store auth-source username password login ;; This file is part of GNU Emacs.