### Initialize Ruby Flymake Backend Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/An-annotated-example-backend.html Sets up the required lexical binding and defines the process variable for the Ruby backend. ```elisp ;;; ruby-flymake.el --- A ruby Flymake backend -*- lexical-binding: t; -*- (require 'cl-lib) (defvar-local ruby--flymake-proc nil) ``` -------------------------------- ### Flymake Simple Make Initialization Command Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Example_002d_002d_002dConfiguring-a-tool-called-via-make.html Defines the command line arguments for `make` when used with `flymake-proc-simple-make-init`. It sets the base directory, source files, and syntax check mode. ```emacs-lisp (list "make" (list "-s" "-C" base-dir (concat "CHK_SOURCES=" source) "SYNTAX_CHECK_MODE=1" "check-syntax")) ``` -------------------------------- ### Map Navigation Commands in Flymake Mode Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Finding-diagnostics.html Map `flymake-goto-next-error` and `flymake-goto-prev-error` to M-n and M-p respectively in `flymake-mode` for easier navigation. Add this to your init file. ```emacs-lisp (define-key flymake-mode-map (kbd "M-n") 'flymake-goto-next-error) (define-key flymake-mode-map (kbd "M-p") 'flymake-goto-prev-error) ``` -------------------------------- ### Define Perl initialization function for Flymake Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Example_002d_002d_002dConfiguring-a-tool-called-directly.html Creates a temporary buffer copy and constructs the command line arguments for the Perl syntax checker. ```elisp (defun flymake-proc-perl-init () (let* ((temp-file (flymake-proc-init-create-temp-buffer-copy 'flymake-proc-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list "perl" (list "-wc " local-file)))) ``` -------------------------------- ### Flymake Proc Configuration Variables Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Proc-customization-variables.html Reference documentation for the customization variables used to configure the legacy Flymake Proc backend. ```APIDOC ## Flymake Proc Configuration Variables ### Description Variables used to configure the behavior of the legacy Flymake Proc backend. ### Variables - **flymake-proc-allowed-file-name-masks** (list) - A list of (filename-regexp, init-function, cleanup-function, getfname-function) for configuring syntax check tools. - **flymake-proc-master-file-dirs** (list) - A list of directories for searching a master file. - **flymake-proc-get-project-include-dirs-function** (function) - A function used for obtaining a list of project include directories (C/C++ specific). - **flymake-proc-master-file-count-limit** (integer) - Limit for searching master files. - **flymake-proc-check-file-limit** (integer) - Limit used when looking for a master file. - **flymake-proc-err-line-patterns** (list) - Patterns for error/warning messages in the form (regexp file-idx line-idx col-idx err-text-idx). - **flymake-proc-diagnostic-type-pred** (function/regexp) - A function to classify diagnostic text or a regular expression matching warnings. - **flymake-proc-compilation-prevents-syntax-check** (boolean) - A flag indicating whether compilation and syntax check of the same file cannot be run simultaneously. ``` -------------------------------- ### Register Ruby Flymake Backend Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/An-annotated-example-backend.html Hooks the backend into the Ruby mode diagnostic functions. ```elisp (defun ruby-setup-flymake-backend () (add-hook 'flymake-diagnostic-functions 'ruby-flymake nil t)) (add-hook 'ruby-mode-hook 'ruby-setup-flymake-backend) ``` -------------------------------- ### Define syntax check tool configuration format Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Adding-support-for-a-new-syntax-check-tool.html The structure required for items in the flymake-proc-allowed-file-name-masks list. ```elisp (filename-regexp, init-function, cleanup-function, getfname-function) ``` -------------------------------- ### Flymake Navigation and Display Options Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Customizable-variables.html Variables for controlling navigation between errors and displaying diagnostic summaries. ```APIDOC ## Flymake Navigation and Display Options ### Description Variables that affect buffer navigation for errors and the display of diagnostic summaries. ### Variables - `flymake-wrap-around` (boolean) - If non-`nil`, moving to errors with `flymake-goto-next-error` and `flymake-goto-prev-error` wraps around buffer boundaries. - `flymake-show-diagnostics-at-end-of-line` (boolean) - If non-`nil`, show summarized descriptions of diagnostics at the end of the line. - `flymake-error-eol` (face) - A custom face for summarizing diagnostic error messages. - `flymake-warning-eol` (face) - A custom face for summarizing diagnostic warning messages. - `flymake-note-eol` (face) - A custom face for summarizing diagnostic notes. ``` -------------------------------- ### GNU FDL Notice with Invariant Sections and Cover Texts Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/GNU-Free-Documentation-License.html Use this template to specify Invariant Sections, Front-Cover Texts, and Back-Cover Texts. ```text with the Invariant Sections being list their titles, with the Front-Cover Texts being list, and with the Back-Cover Texts being list. ``` -------------------------------- ### Flymake Backend Function Convention Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Backend-functions.html Describes the expected function signature and arguments for Flymake backend functions. ```APIDOC ## Flymake Backend Function Convention ### Description Flymake backends are Lisp functions that diagnose buffer contents for problems and report them to Flymake. They must adhere to a specific function calling convention. ### Method N/A (Lisp function hook) ### Endpoint N/A (Hook: `flymake-diagnostic-functions`) ### Parameters #### Function Arguments - **report-fn** (callback function) - Required - A callback function to report diagnostics to Flymake. - **keyword-value pairs** (arbitrary) - Optional - Flymake may pass keyword-value pairs such as `:recent-changes`, `:changes-start`, and `:changes-end`. - **:recent-changes** (list) - Optional - A list of recent changes in the buffer since the last call. Each element is `(beg end text)`. - **:changes-start** (integer) - Optional - The minimum buffer position affected by recent changes. Provided with `:recent-changes`. - **:changes-end** (integer) - Optional - The maximum buffer position affected by recent changes. Provided with `:recent-changes`. ### Request Example N/A (Lisp function call) ### Response #### Function Return Value - **Quick return or error signal** - Backends are expected to return quickly or signal an error. Returning successfully means the backend is considered 'running'. #### Callback Usage - **report-fn(report-action, [keyword-value pairs])** - Backends call this callback to report diagnostics or errors. - **report-action** (list or symbol) - Required - Can be a list of diagnostic objects or the symbol `:panic`. - **keyword-value pairs** (list) - Optional - Keyword arguments for reporting, such as `:explanation`, `:force`, `:region`. - **:explanation** (string) - Optional - User-readable details of the situation. - **:force** (boolean) - Optional - Suggests Flymake consider the report even if unexpected. - **:region** (cons) - Optional - A cons cell `(beg . end)` indicating the report's applicable region. ``` -------------------------------- ### Register Perl file extension in Flymake Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Example_002d_002d_002dConfiguring-a-tool-called-directly.html Adds a new entry to flymake-proc-allowed-file-name-masks to associate .pl files with the Perl initialization function. ```elisp (setq flymake-proc-allowed-file-name-masks (cons '(".+\\.pl$" flymake-proc-perl-init flymake-proc-simple-cleanup flymake-proc-get-real-file-name) flymake-proc-allowed-file-name-masks)) ``` -------------------------------- ### Standard GNU FDL License Notice Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/GNU-Free-Documentation-License.html Use this notice for documents without Invariant Sections or Cover Texts. ```text Copyright (C) year your name. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License''. ``` -------------------------------- ### Flymake Error Highlighting and Indicators Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Customizable-variables.html Variables for customizing how errors, warnings, and notes are displayed. ```APIDOC ## Flymake Error Highlighting and Indicators ### Description Variables that control the visual representation of syntax errors, warnings, and notes. ### Variables - `flymake-error` (face) - A custom face for highlighting regions for which an error has been reported. - `flymake-warning` (face) - A custom face for highlighting regions for which a warning has been reported. - `flymake-note` (face) - A custom face for highlighting regions for which a note has been reported. - `flymake-indicator-type` (symbol) - The indicator type which Flymake should use to indicate lines with errors or warnings. Can be `fringes` or `margins`. - `flymake-error-bitmap` (bitmap) - A bitmap used in the fringe to mark lines for which an error has been reported. - `flymake-warning-bitmap` (bitmap) - A bitmap used in the fringe to mark lines for which a warning has been reported. - `flymake-fringe-indicator-position` (symbol) - Which fringe (if any) should show the warning/error bitmaps. - `flymake-margin-indicators-string` (string) - Specifies the string and face to use for the margin indicators, for each error type. - `flymake-margin-indicator-position` (symbol) - Which margin (if any) should show the warning/error strings. - `flymake-autoresize-margins` (boolean) - If non-`nil`, Flymake will resize the margins when `flymake-mode` is turned on or off. Only relevant if `flymake-indicator-type` is set to `margins`. ``` -------------------------------- ### Define Ruby Flymake Backend Function Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/An-annotated-example-backend.html Implements the main backend function to check Ruby files, managing process lifecycle and diagnostic reporting. ```elisp (defun ruby-flymake (report-fn &rest _args) ;; Not having a ruby interpreter is a serious problem which should cause ;; the backend to disable itself, so an error is signaled. ;; (unless (executable-find "ruby") (error "Cannot find a suitable ruby")) ;; If a live process launched in an earlier check was found, that ;; process is killed. When that process's sentinel eventually runs, ;; it will notice its obsoletion, since it have since reset ;; `ruby-flymake-proc' to a different value ;; (when (process-live-p ruby--flymake-proc) (kill-process ruby--flymake-proc)) ``` ```elisp ;; Save the current buffer, the narrowing restriction, remove any ;; narrowing restriction. ;; (let ((source (current-buffer))) (save-restriction (widen) ;; Reset the `ruby--flymake-proc' process to a new process ;; calling the ruby tool. ;; (setq ruby--flymake-proc (make-process :name "ruby-flymake" :noquery t :connection-type 'pipe ;; Make output go to a temporary buffer. ;; :buffer (generate-new-buffer " *ruby-flymake*") :command '("ruby" "-w" "-c") :sentinel (lambda (proc _event) ;; Check that the process has indeed exited, as it might ;; be simply suspended. ;; (when (memq (process-status proc) '(exit signal)) (unwind-protect ;; Only proceed if `proc' is the same as ;; `ruby--flymake-proc', which indicates that ;; `proc' is not an obsolete process. ;; (if (with-current-buffer source (eq proc ruby--flymake-proc)) (with-current-buffer (process-buffer proc) (goto-char (point-min)) ;; Parse the output buffer for diagnostic's ;; messages and locations, collect them in a list ;; of objects, and call `report-fn'. ;; (cl-loop while (search-forward-regexp "^\\(?:.*.rb\\|-\\):\\([0-9]+\\): \\(.*\\)$" nil t) for msg = (match-string 2) for (beg . end) = (flymake-diag-region source (string-to-number (match-string 1))) for type = (if (string-match "^warning" msg) :warning :error) when (and beg end) collect (flymake-make-diagnostic source beg end type msg) into diags finally (funcall report-fn diags))) (flymake-log :warning "Canceling obsolete check %s" proc)) ;; Cleanup the temporary buffer used to hold the ;; check's output. ;; (kill-buffer (process-buffer proc))))))) ;; Send the buffer contents to the process's stdin, followed by ;; an EOF. ;; (process-send-region ruby--flymake-proc (point-min) (point-max)) (process-send-eof ruby--flymake-proc)))) ``` -------------------------------- ### Restore Original Look for :note Diagnostics Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Flymake-error-types.html Resets the 'flymake-overlay-control' property for :note diagnostics to an empty alist, restoring its original appearance settings. ```Emacs Lisp (put :note 'flymake-overlay-control '()) ``` -------------------------------- ### Flymake Syntax Check Behavior Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Customizable-variables.html Variables that control when and how syntax checks are initiated. ```APIDOC ## Flymake Syntax Check Behavior ### Description Variables that determine the automatic triggering and timing of syntax checks. ### Variables - `flymake-no-changes-timeout` (integer) - If any changes are made to the buffer, syntax check is automatically started after this many seconds, unless the user makes another change, which resets the timer. - `flymake-start-on-flymake-mode` (boolean) - A boolean flag indicating whether to start syntax check immediately after enabling `flymake-mode`. - `flymake-start-on-save-buffer` (boolean) - A boolean flag indicating whether to start syntax check after saving the buffer. ``` -------------------------------- ### Configure Perl error line patterns Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Example_002d_002d_002dConfiguring-a-tool-called-directly.html Updates flymake-proc-err-line-patterns to correctly parse Perl error messages. ```elisp (setq flymake-proc-err-line-patterns (cons '("\\(.*\\) at \\([^ \\n]+\\) line \\([0-9]+\\)[,.\\n]" 2 3 nil 1) flymake-proc-err-line-patterns)) ``` -------------------------------- ### Create Interactive Search Annotation for :warning and :error Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Flymake-error-types.html Defines a function 'my-search-for-message' to search DuckDuckGo for the text of a diagnostic. It then configures :warning and :error types to bind mouse-2 (middle click) to this function, also adding a 'highlight' face. ```Emacs Lisp (defun my-search-for-message (event) (interactive "e") (let* ((diags (flymake-diagnostics (posn-point (event-start event)))) (topmost-diag (car diags))) (eww-browse-url (concat "https://duckduckgo.com/?q=" (replace-regexp-in-string " " "+" (flymake-diagnostic-text topmost-diag))) t))) (dolist (type '(:warning :error)) (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))) ``` -------------------------------- ### Makefile Target for GCC Syntax Check Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Example_002d_002d_002dConfiguring-a-tool-called-via-make.html A sample Makefile target `check-syntax` that uses `gcc` to perform syntax checking on C source files. The `|| true` ensures the build does not fail even if `gcc` reports errors. ```makefile check-syntax: gcc -o /dev/null -S ${CHK_SOURCES} || true ``` -------------------------------- ### Make :note Diagnostics Stand Out Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Flymake-error-types.html Adds a 'highlight' face to :note diagnostics to make them more prominent. This modifies the 'flymake-overlay-control' property for the :note symbol. ```Emacs Lisp (push '(face . highlight) (get :note 'flymake-overlay-control)) ``` -------------------------------- ### flymake-log Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Flymake-utility-functions.html Logs messages to the Flymake log buffer for troubleshooting purposes. Supports different logging levels. ```APIDOC ## flymake-log ### Description Log, at level level, the message msg formatted with args. level is passed to `display-warning`, which is used to display the warning in Flymake’s log buffer. ### Macro Signature flymake-log level msg &optional args ### Parameters - **level**: The logging level (passed to `display-warning`). - **msg**: The message string to log. - **args**: Optional arguments for formatting the message. ### Usage This macro is intended for backends to record exceptional or erroneous situations into the Flymake log buffer for debugging. ``` -------------------------------- ### Makefile Target using Automake COMPILE Variable Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Example_002d_002d_002dConfiguring-a-tool-called-via-make.html An alternative Makefile target `check-syntax` that uses the Automake `COMPILE` variable instead of directly calling `gcc`. This is useful when working with Automake projects. ```makefile check-syntax: $(COMPILE) -o /dev/null -S ${CHK_SOURCES} || true ``` -------------------------------- ### Flymake Mode Line Variables Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Customizable-variables.html Variables related to the Flymake mode line indicator and its formatting. ```APIDOC ## Flymake Mode Line Variables ### Description Variables that control the appearance and content of the Flymake mode line indicator. ### Variables - `flymake-mode-line-lighter` (string) - The name of the mode. Defaults to ‘Flymake’. - `flymake-mode-line-format` (string) - Format to use for the Flymake mode line indicator. - `flymake-mode-line-counter-format` (string) - Mode line construct for formatting Flymake diagnostic counters inside the Flymake mode line indicator. ``` -------------------------------- ### Add GCC via Make to Flymake Allowed Masks Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Example_002d_002d_002dConfiguring-a-tool-called-via-make.html Add a new entry to `flymake-proc-allowed-file-name-masks` to enable Flymake's support for C files checked by GCC via Make. This involves specifying the file name mask and the initialization and cleanup functions. ```emacs-lisp (setq flymake-proc-allowed-file-name-masks (cons '(".+\\.c$" flymake-proc-simple-make-init flymake-proc-simple-cleanup flymake-proc-get-real-file-name) flymake-proc-allowed-file-name-masks)) ``` -------------------------------- ### Configure Custom Diagnostic Type :low-priority-note Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Flymake-error-types.html Configures a new diagnostic type ':low-priority-note' to behave like ':note' but without an overlay face. It sets the 'flymake-overlay-control' to '((face . nil))' and 'flymake-category' to 'flymake-note'. ```Emacs Lisp (put :low-priority-note 'flymake-overlay-control '((face . nil))) ``` ```Emacs Lisp (put :low-priority-note 'flymake-category 'flymake-note) ``` -------------------------------- ### flymake-diagnostics Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Flymake-utility-functions.html Retrieves a list of Flymake diagnostic objects within a specified region of the buffer. If no region is specified, it defaults to the entire buffer. ```APIDOC ## flymake-diagnostics ### Description Get a list of Flymake diagnostics in the region determined by beg and end. If neither beg or end is supplied, use the whole buffer, otherwise if beg is non-`nil` and end is `nil`, consider only diagnostics at beg. ### Function Signature flymake-diagnostics beg end ### Parameters - **beg**: The starting position of the region. If `nil`, the whole buffer is considered. - **end**: The ending position of the region. If `nil` and `beg` is non-`nil`, only diagnostics at `beg` are considered. ### Returns A list of Flymake diagnostic objects. ``` -------------------------------- ### flymake-make-diagnostic Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Flymake-utility-functions.html Creates a Flymake diagnostic object for a specified region of text. This function is fundamental for backends to report detected issues. ```APIDOC ## flymake-make-diagnostic ### Description Make a Flymake diagnostic for the region of text in locus’s delimited by beg and end. type is a diagnostic symbol, and text is a description of the problem detected in this region. ### Function Signature flymake-make-diagnostic locus beg end type text &optional data ### Parameters - **locus**: The buffer object or a string naming a file. - **beg**: The starting position of the diagnostic region (buffer position or (line . col)). - **end**: The ending position of the diagnostic region (buffer position or (line . col)). - **type**: A diagnostic symbol (e.g., error, warning). - **text**: A description of the problem detected. - **data**: Optional additional data associated with the diagnostic. ### Related Functions - `flymake-diagnostic-backend` - `flymake-diagnostic-buffer` - `flymake-diagnostic-text` - `flymake-diagnostic-beg` - `flymake-diagnostic-end` - `flymake-diagnostic-type` - `flymake-diagnostic-data` - `flymake-diagnostics` ``` -------------------------------- ### flymake-diag-region Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Flymake-utility-functions.html Converts line and column numbers into buffer positions (beg . end), which is useful for backends that report diagnostics using line/column information. ```APIDOC ## flymake-diag-region ### Description Compute buffer’s region (beg . end) corresponding to line and col. If col is `nil`, return a region just for line. Return `nil` if the region is invalid. This function saves match data. ### Function Signature flymake-diag-region buffer line &optional col ### Parameters - **buffer**: The buffer to compute the region for. - **line**: The line number. - **col**: Optional column number. If `nil`, the region is for the entire line. ### Returns A cons cell `(beg . end)` representing the buffer region, or `nil` if the region is invalid. ``` -------------------------------- ### Remove Face from :note Diagnostics Source: https://www.gnu.org/software/emacs/manual/html_node/flymake/Flymake-error-types.html Removes the 'highlight' face from :note diagnostics by pushing '(face . nil) to its 'flymake-overlay-control'. This effectively disables the custom face. ```Emacs Lisp (push '(face . nil) (get :note 'flymake-overlay-control)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.