From 829821cc988be06c1f8a0699d11fecb7a6db972a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 16 Nov 2014 10:45:21 +0000 Subject: Implement sx-initialize --- sx.el | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 53aae84..64c555c 100644 --- a/sx.el +++ b/sx.el @@ -143,10 +143,19 @@ SETTER should be a function of two arguments. If SETTER is nil, (,(or setter #'setq) ,variable ,value)))) nil) -(defun stack-initialize () - (run-hooks - 'sx-init--internal-hook - 'sx-init-hook)) +(defvar sx-initialized nil + "Nil if sx hasn't been initialized yet. +If it has, holds the time at which initialization happened.") + +(defun sx-initialize (&optional force) + "Run initialization hooks if they haven't been run yet. +These are `sx-init--internal-hook' and `sx-init-hook'. +If FORCE is non-nil, run them even if they've already been run." + (when (or force (not sx-initialized)) + (prog1 + (run-hooks 'sx-init--internal-hook + 'sx-init-hook) + (setq sx-initialized (current-time))))) (provide 'sx) ;;; sx.el ends here -- cgit v1.2.3 From bb2d155ef7ae73a00eba53ed7e0d1acee6c0902e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 18 Nov 2014 16:35:19 +0000 Subject: Define sorted insertion macro. --- sx.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 64c555c..387c6bb 100644 --- a/sx.el +++ b/sx.el @@ -27,6 +27,21 @@ ;;; Utility Functions +(defmacro sx-sorted-insert-skip-first (newelt list &optional predicate) + "Inserted NEWELT into LIST sorted by PREDICATE. +This is designed for the (site id id ...) lists. So the first car +is intentionally skipped." + `(let ((tail ,list) + (x ,newelt)) + ;; The first element is never less-than. + (while (and + ;; We're at the end. + (cdr-safe tail) + ;; We're at the right place. + (,(or predicate #'<) x (cadr tail))) + (setq tail (cdr tail))) + (setcdr tail (cons x (cdr tail))))) + (defun sx-message (format-string &rest args) "Display a message" (message "[stack] %s" (apply #'format format-string args))) -- cgit v1.2.3 From f74323d2679be6312c96b0ba1e4cc2fda5b4da50 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 19 Nov 2014 01:44:13 +0000 Subject: Add some package definitions. Also run checkdoc on sx.el --- sx.el | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 387c6bb..4d06c95 100644 --- a/sx.el +++ b/sx.el @@ -1,8 +1,12 @@ -;;; sx.el --- core functions -*- lexical-binding: t; -*- +;;; sx.el --- Core functions of the sx package. -*- lexical-binding: t; -*- ;; Copyright (C) 2014 Sean Allred ;; Author: Sean Allred +;; URL: https://github.com/vermiculus/stack-mode/ +;; Version: 0.1 +;; Keywords: help, hypermedia, tools +;; Package-Requires: ((emacs "24.1") (cl-lib "0.5") (json "1.3")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -24,6 +28,22 @@ ;;; Code: +(defconst sx-version "0.1" "Version of the `sx' package.") + + +;;; User commands +(defun sx-version () + "Print and return the version of the `sx' package." + (interactive) + (message "%s: %s" 'sx-version sx-version) + sx-version) + +;;;###autoload +(defun sx-bug-report () + "File a bug report about the `sx' package." + (interactive) + (browse-url "https://github.com/vermiculus/stack-mode/issues/new")) + ;;; Utility Functions @@ -33,17 +53,15 @@ This is designed for the (site id id ...) lists. So the first car is intentionally skipped." `(let ((tail ,list) (x ,newelt)) - ;; The first element is never less-than. - (while (and - ;; We're at the end. + (while (and ;; We're not at the end. (cdr-safe tail) - ;; We're at the right place. + ;; We're not at the right place. (,(or predicate #'<) x (cadr tail))) (setq tail (cdr tail))) (setcdr tail (cons x (cdr tail))))) (defun sx-message (format-string &rest args) - "Display a message" + "Display a message." (message "[stack] %s" (apply #'format format-string args))) (defun sx-message-help-echo () @@ -52,8 +70,9 @@ is intentionally skipped." (when echo (message "%s" echo)))) (defun sx--thing-as-string (thing &optional sequence-sep) - "Return a string representation of THING. If THING is already -a string, just return it." + "Return a string representation of THING. +If THING is already a string, just return it. +Optional argument SEQUENCE-SEP is the separator applied between elements of a sequence." (cond ((stringp thing) thing) ((symbolp thing) (symbol-name thing)) @@ -63,7 +82,7 @@ a string, just return it." thing (if sequence-sep sequence-sep ";"))))) (defun sx--filter-data (data desired-tree) - "Filters DATA and returns the DESIRED-TREE" + "Filters DATA and return the DESIRED-TREE." (if (vectorp data) (apply #'vector (mapcar (lambda (entry) @@ -141,8 +160,8 @@ This is used internally to set initial values for variables such as filters.") (defun sx--< (property x y &optional pred) - "Non-nil if PROPERTY attribute of question X is less than that of Y. -With optional argument predicate, use it instead of `<'." + "Non-nil if PROPERTY attribute of alist X is less than that of Y. +With optional argument PRED, use it instead of `<'." (funcall (or pred #'<) (cdr (assoc property x)) (cdr (assoc property y)))) @@ -158,7 +177,7 @@ SETTER should be a function of two arguments. If SETTER is nil, (,(or setter #'setq) ,variable ,value)))) nil) -(defvar sx-initialized nil +(defvar sx-initialized nil "Nil if sx hasn't been initialized yet. If it has, holds the time at which initialization happened.") -- cgit v1.2.3 From 681319aeb250a83d982d1e3e02264a7af0ae4120 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 19 Nov 2014 02:06:18 +0000 Subject: Fix missing dependency --- sx.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 4d06c95..eab1ead 100644 --- a/sx.el +++ b/sx.el @@ -6,7 +6,7 @@ ;; URL: https://github.com/vermiculus/stack-mode/ ;; Version: 0.1 ;; Keywords: help, hypermedia, tools -;; Package-Requires: ((emacs "24.1") (cl-lib "0.5") (json "1.3")) +;; Package-Requires: ((emacs "24.1") (cl-lib "0.5") (json "1.3") (markdown-mode "2.0")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -- cgit v1.2.3