branch: master commit 8e44368d4e404f2b4a1e80cd4a8995f986c58027 Author: Ian Dunn <du...@gnu.org> Commit: Ian Dunn <du...@gnu.org>
Moved enwc-setup to enwc.el, and added it to enwc. * enwc-backend.el (enwc-force-backend-loading): New defcustom to force loading of default backend in enwc-setup. (enwc-load-backend): Load the file that contains the backend. * enwc.el (enwc-display-mode-line): Fixed default. (enwc-auto-scan): Changed default to nil. (enwc--setup-done): New defvar to determine if setup has been run. (enwc-setup): Added. (enwc): Call enwc-setup. --- lisp/enwc-backend.el | 9 ++++++++ lisp/enwc-setup.el | 59 ---------------------------------------------------- lisp/enwc.el | 37 ++++++++++++++++++++++++++------ 3 files changed, 40 insertions(+), 65 deletions(-) diff --git a/lisp/enwc-backend.el b/lisp/enwc-backend.el index fa4083f..a296477 100644 --- a/lisp/enwc-backend.el +++ b/lisp/enwc-backend.el @@ -66,8 +66,14 @@ an enwc-backend struct.") :type 'symbol :group 'enwc) +(defcustom enwc-force-backend-loading nil + "Non-nil if backends should be loaded even if they claim they cannot." + :type 'boolean + :group 'enwc) + (defvar enwc--current-backend nil) +;;;###autoload (defun enwc-register-backend (definition &optional forcep) "Register the backend KEY with DEFINITION. @@ -125,6 +131,9 @@ Signals an error if a backend with KEY already exists and FORCEP is nil." (not (eq (enwc-backend-key enwc--current-backend) backend))) (enwc-unload-current-backend)) + (unless (require (intern (format "enwc-%s" backend)) nil t) + (error "Cannot find enwc feature for backend %s" backend)) + (let ((new-backend (map-elt enwc-registered-backend-alist backend))) (unless new-backend (error "No registered backend %s" backend)) diff --git a/lisp/enwc-setup.el b/lisp/enwc-setup.el deleted file mode 100644 index 5c463c7..0000000 --- a/lisp/enwc-setup.el +++ /dev/null @@ -1,59 +0,0 @@ -;; enwc-setup.el - Setup routines for ENWC - -;; Copyright (C) 2012-2014 Free Software Foundation, Inc. - -;; Author: Ian Dunn <du...@gnu.org> -;; Keywords: network, wicd, manager, nm -;; Version: 2.0 -;; Homepage: https://savannah.nongnu.org/p/enwc - -;; This file is part of GNU Emacs. - -;; GNU Emacs is free software; you can redistribute it and/or modify it -;; under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3, or (at your option) -;; any later version. - -;; 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. - -;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the Free -;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -;; 02110-1301, USA. - -;;; Commentary: - -;;; Code: - -(require 'enwc) -(require 'enwc-backend) -(require 'enwc-wicd) -(require 'enwc-nm) - -;;;###autoload -(defun enwc-setup () - "Set up ENWC. -This sets up ENWC and confirms that one of the backends can be found on D-Bus." - (when enwc-display-mode-line - (enwc-enable-display-mode-line)) - - (when (and enwc-auto-scan - (> enwc-auto-scan-interval 0) - (not enwc-scan-timer)) - (setq enwc-scan-timer - (run-at-time t enwc-auto-scan-interval 'enwc-scan t))) - - (let ((back-list enwc-backends) - cur-back pass) - (while (and back-list (not pass)) - (setq cur-back (pop back-list)) - (setq pass (ignore-errors (enwc-load-backend cur-back)))) - (unless pass - (error "No usable backend was found.")))) - -(provide 'enwc-setup) - -;;; enwc-setup.el ends here diff --git a/lisp/enwc.el b/lisp/enwc.el index 215381a..dfd2511 100644 --- a/lisp/enwc.el +++ b/lisp/enwc.el @@ -35,12 +35,11 @@ ;; ;; In order to use this package, add ;; -;; (require 'enwc) -;; (enwc-load-default-backend) -;; (enwc-enable-auto-scan) -;; (enwc-enable-display-mode-line) +;; (setq enwc-default-backend 'backend-symbol) ;; ;; to your .emacs file (or other init file). +;; +;; Then you can just run `enwc' to start everything. ;;; TODO: ;; @@ -76,13 +75,13 @@ :group 'enwc :type 'string) -(defcustom enwc-display-mode-line 't +(defcustom enwc-display-mode-line t "Non-nil means display network information in the mode line. The specific information can be set using `enwc-mode-line-format'." :group 'enwc :type 'boolean) -(defcustom enwc-auto-scan 't +(defcustom enwc-auto-scan nil "Whether or not to have ENWC automatically scan. If non-nil, then ENWC will automatically scan for networks every `enwc-auto-scan-interval' seconds." @@ -667,6 +666,31 @@ newly created buffer." (unless (get-buffer "*ENWC*") (enwc-setup-buffer t))) +(defvar enwc--setup-done nil + "Non-nil if enwc has already been set up.") + +(defun enwc-setup () + "Set up ENWC. + +If `enwc-display-mode-line' is non-nil, enable the mode line. + +If `enwc-auto-scan' is non-nil, start the auto-scan timer. + +Finally, the default backend is loaded." + (unless enwc--setup-done + (enwc-load-default-backend enwc-force-backend-loading) + + (when enwc-display-mode-line + (enwc-enable-display-mode-line)) + + (when (and enwc-auto-scan + (> enwc-auto-scan-interval 0) + (not enwc-scan-timer)) + (setq enwc-scan-timer + (run-at-time t enwc-auto-scan-interval 'enwc-scan t))) + + (setq enwc--setup-done t))) + ;;;###autoload (defun enwc () "The main front-end to ENWC. @@ -676,6 +700,7 @@ In order to use this, one must have already run \\{enwc-mode-map}" (interactive) + (enwc-setup) (enwc-setup-buffer) (enwc-scan))