This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/core/core-funcs.el
Tu Do 55f1207133 Improve Startup buffer
- Modularize and add quickhelp button
  Split the current hardcoded release note display functions into smaller
  reusable functions. Then reuse it for creating quickhelp button.
- fix: bind widget-button-click to left mouse click
  widget-button-press is for keyboard and binding it to a left mouse
  button is not suitable. The clicks on buttons are often ignored. Use the
  proper widget-button-click.
- Since this is develop, point it to 0.102.x
- Beautify org CHANGELOG
  Setting org-indent-mode hides the leading stars of all Org headers except
  the last one just enough to indicate indentation, which make it easier
  to read. Also, put it in read-only-mode so user don't accidentially mess
  up his reading material.
  Also put the CHANGELOG in view-mode for reading and navigating read-only
  content.
- Add Evil and Emacs tutorial buttons to quickhelp
  So it is even easier for first time users.
  Also refactor spacemacs-buffer//insert-release-note:
  - Change it to spacemacs-buffer//insert-note
  - Just insert content. Widgets are optional
  - Insert different widget from the two functions
    spacemacs-buffer//insert-quickhelp-widget and spacemacs-buffer//insert-release-note-widget
- Put the cursor on the quickhelp button
  So that users can start using it immediately. New users only knows RET
  to press a button and learn the rest there.
- Add m to jump back to top menu
  Also update the quickhelp content.
2015-04-19 02:04:42 -04:00

124 lines
4.2 KiB
EmacsLisp

;;; core-funcs.el --- Spacemacs Core File
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defun spacemacs/mplist-get (plist prop)
"Get the values associated to PROP in PLIST, a modified plist.
A modified plist is one where keys are keywords and values are
all non-keywords elements that follow it.
If there are multiple properties with the same keyword, only the first property
and its values is returned.
Currently this function infloops when the list is circular."
(let ((tail plist)
result)
(while (and (consp tail) (not (eq prop (car tail))))
(pop tail))
;; pop the found keyword
(pop tail)
(while (and (consp tail) (not (keywordp (car tail))))
(push (pop tail) result))
(nreverse result)))
(defun spacemacs/mplist-remove (plist prop)
"Return a copy of a modified PLIST without PROP and its values.
If there are multiple properties with the same keyword, only the first property
and its values are removed."
(let ((tail plist)
result)
(while (and (consp tail) (not (eq prop (car tail))))
(push (pop tail) result))
(when (eq prop (car tail))
(pop tail)
(while (and (consp tail) (not (keywordp (car tail))))
(pop tail)))
(while (consp tail)
(push (pop tail) result))
(nreverse result)))
;; From http://stackoverflow.com/questions/2321904/elisp-how-to-save-data-in-a-file
(defun spacemacs/dump-vars-to-file (varlist filename)
"simplistic dumping of variables in VARLIST to a file FILENAME"
(save-excursion
(let ((buf (find-file-noselect filename)))
(set-buffer buf)
(erase-buffer)
(spacemacs/dump varlist buf)
(make-directory (file-name-directory filename) t)
(save-buffer)
(kill-buffer))))
;; From http://stackoverflow.com/questions/2321904/elisp-how-to-save-data-in-a-file
(defun spacemacs/dump (varlist buffer)
"insert into buffer the setq statement to recreate the variables in VARLIST"
(loop for var in varlist do
(print (list 'setq var (list 'quote (symbol-value var)))
buffer)))
(defvar spacemacs--init-redisplay-count 0
"The number of calls to `redisplay'")
(defun spacemacs//redisplay ()
"`redisplay' wrapper."
(setq spacemacs--init-redisplay-count (1+ spacemacs--init-redisplay-count))
(redisplay))
(defun spacemacs//create-key-binding-form (props func)
"Helper which returns a from to bind FUNC to a key according to PROPS.
Supported properties:
`:evil-leader STRING'
One or several key sequence strings to be set with `evil-leader/set-key'.
`:evil-leader-for-mode CONS CELL'
One or several cons cells (MODE . KEY) where MODE is a major-mode symbol
and KEY is a key sequence string to be set with
`evil-leader/set-key-for-mode'.
`:global-key STRING'
One or several key sequence strings to be set with `global-set-key'.
`:define-key CONS CELL'
One or several cons cells (MAP . KEY) where MAP is a mode map and KEY is a
key sequence string to be set with `define-key'. "
(let ((evil-leader (spacemacs/mplist-get props :evil-leader))
(evil-leader-for-mode (spacemacs/mplist-get props :evil-leader-for-mode))
(global-key (spacemacs/mplist-get props :global-key))
(def-key (spacemacs/mplist-get props :define-key)))
`((unless (null ',evil-leader)
(dolist (key ',evil-leader)
(evil-leader/set-key key ',func)))
(unless (null ',evil-leader-for-mode)
(dolist (val ',evil-leader-for-mode)
(evil-leader/set-key-for-mode
(car val) (cdr val) ',func)))
(unless (null ',global-key)
(dolist (key ',global-key)
(global-set-key (kbd key) ',func)))
(unless (null ',def-key)
(dolist (val ',def-key)
(define-key (eval (car val)) (kbd (cdr val)) ',func))))))
(defun spacemacs/open-file (file anchor-text)
"Open the change log for the current version."
(interactive)
;; For now hardcode it
(find-file file)
(org-indent-mode)
(view-mode)
(goto-char (point-min))
(re-search-forward anchor-text)
(beginning-of-line)
(show-subtree))
(provide 'core-funcs)