Move own Lisp files to lisp/

This commit is contained in:
Gergely Polonkai
2016-09-15 16:08:54 +02:00
parent 2c103a136f
commit bf9369af4b
8 changed files with 16 additions and 12 deletions

7968
lisp/clearcase.el Normal file

File diff suppressed because it is too large Load Diff

65
lisp/gnu-c-header.el Normal file
View File

@@ -0,0 +1,65 @@
;;; gnu-c-header.el --- function to add a header to the C files licensed under the GPL
;; Author: Gergely Polonkai <gergely@polonkai.eu>
;; Copyright: public domain
;; URL: http://gergely.polonkai.eu/blog/2014/09/26/emacs-adding-gnu-c-headers
;; Keywords: gnu, c, header, helper, utilities
;;; Commentary:
;;; Code:
(defun file-name-base-with-extension (&optional filename)
"Return the base name of the FILENAME without its directory path.
FILENAME defaults to `buffer-file-name'."
(file-name-nondirectory (or filename (buffer-file-name))))
(defun add-gnu-c-header (progname purpose)
"Add a GNU GPL header to the current buffer"
(interactive "sProgram name (ie: MyProgram): \nsPurpose of the file (ie: string utility functions): ")
(save-excursion
(goto-char (point-min))
(insert (concat
"/* "
(file-name-base-with-extension buffer-file-name)
" - "
purpose
" for "
progname
"\n"
" *\n"
" * Copyright (C) "
(format-time-string "%Y" (current-time))
" "
(user-full-name)
"\n"
" *\n"))
(let ((start (point)))
(insert (concat
" * "
progname
" is \n * 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 of the License, or (at your option) any later version."))
(let ((end (point)))
(fill-region start end)))
(insert (concat
"\n"
" *\n"))
(let ((start (point)))
(insert (concat
" * "
progname
" is \n * 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."))
(let ((end (point)))
(fill-region start end)))
(insert (concat
"\n"
" *\n"))
(let ((start (point)))
(insert " * You \n * should have received a copy of the GNU General Public License along with this software; if not, see <http://www.gnu.org/licenses/>.")
(let ((end (point)))
(fill-region start end)))
(insert (concat
"\n"
" */\n"))
))
(provide 'gnu-c-header)
;;; gnu-c-header.el ends here

112
lisp/jekyll.el Normal file
View File

@@ -0,0 +1,112 @@
;; Configuration for Jekyll (http://jekyllrb.com/)
(defun jekyll-timestamp ()
"Update existing date: timestamp on a Jekyll page or post."
(interactive)
(save-excursion (goto-char 1)
(re-search-forward "^date:")
(let ((beg (point)))
(end-of-line)
(delete-region beg (point)))
(insert (concat " " (format-time-string "%Y-%m-%d %H:%M:%S %z"))))
)
;; TODO: Make the function add a date variable if none exists.
;; (defun jekyll-timestamp ()
;; "Insert a time stamp suitable for use in a Jekyll page or post. Replaces current text selection."
;; (interactive)
;; (when (region-active-p) (delete-region (region-beginning) (region-end) ) )
;; (insert (format-time-string "%Y-%m-%d %H:%M:%S %z")))
;; All of the below is taken from http://www.gorgnegre.com/linux/using-emacs-orgmode-to-blog-with-jekyll.html
;; (Later tweaked a bit.)
(global-set-key (kbd "C-c j n") 'jekyll-draft-post)
(global-set-key (kbd "C-c j p") 'jekyll-publish-post)
(global-set-key (kbd "C-c j t") 'jekyll-timestamp)
(global-set-key (kbd "C-c j o") (lambda () (interactive) (find-file "~/web/")))
(defcustom jekyll-directory
"~/web/"
"Path to Jekyll blog. It must end "
:type '(directory)
:group 'jekyll)
(defcustom jekyll-drafts-dir
"_drafts/"
"Path to article drafts. Relative to jekyll-directory."
:type '(string)
:group 'jekyll)
(defcustom jekyll-posts-dir
"_posts/"
"Path to articles. Relative to jekyll-directory."
:type '(string)
:group 'jekyll)
(defcustom jekyll-post-ext
".md"
"File extension of Jekyll posts."
:type '(string)
:group 'jekyll)
(defcustom jekyll-post-template
"---\nlayout: post\ntitle: %s\ntags:\ndate: %t\n---\n"
"Default template for Jekyll posts. %s will be replace by the post title, %t will be replaced with the current timestamp"
:type '(string)
:group 'jekyll)
(defun jekyll-make-slug (s) "Turn a string into a slug."
(replace-regexp-in-string " "
"-"
(downcase
(replace-regexp-in-string "[^A-Za-z0-9 ]"
"" s))))
(defun jekyll-yaml-escape (s) "Escape a string for YAML."
(if
(or
(string-match ":" s)
(string-match "\"" s))
(concat "\"" (replace-regexp-in-string "\"" "\\\\\"" s) "\"") s))
(defun jekyll-draft-post (title) "Create a new Jekyll blog post."
(interactive "sPost Title: ")
(let ((draft-file (concat
(file-name-as-directory jekyll-directory)
jekyll-drafts-dir
(jekyll-make-slug title)
jekyll-post-ext)))
(if (file-exists-p draft-file)
(find-file draft-file)
(find-file draft-file)
(insert (format jekyll-post-template (jekyll-yaml-escape title))))))
(defun jekyll-publish-post ()
"Move a draft post to the posts directory, and rename it so that it contains the date."
(interactive)
(cond
((not (equal
(file-name-directory (buffer-file-name (current-buffer)))
(expand-file-name (concat
(file-name-as-directory jekyll-directory)
jekyll-drafts-dir))))
(message "This is not a draft post.")
(insert (file-name-directory (buffer-file-name (current-buffer))) "\n"
(concat
(file-name-as-directory jekyll-directory)
jekyll-drafts-dir)))
((buffer-modified-p)
(message "Can't publish post; buffer has modifications."))
(t
(let ((filename
(concat
(file-name-as-directory jekyll-directory)
jekyll-posts-dir
(format-time-string "%Y-%m-%d-")
(file-name-nondirectory
(buffer-file-name (current-buffer)))))
(old-point (point)))
(rename-file (buffer-file-name (current-buffer))
filename)
(kill-buffer nil)
(find-file filename)
(set-window-point (selected-window) old-point)))))
(provide 'setup-jekyll)

View File

@@ -0,0 +1,19 @@
(defun get-number-at-point ()
(interactive)
(skip-chars-backward "0123456789.-")
(or (looking-at "[0123456789.-]+")
(error "No number at point"))
(string-to-number (match-string 0)))
(defun round-number-at-point-to-decimals (decimal-count)
(interactive "NDecimal count: ")
(let ((mult (expt 10 decimal-count)))
(replace-match (number-to-string
(/
(fround
(*
mult
(get-number-at-point)))
mult)))))
(global-set-key (kbd "C-c r") 'round-number-at-point-to-decimals)

View File

@@ -0,0 +1,27 @@
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))
(error "This works only for two windows!")))
(global-set-key (kbd "C-x |") 'toggle-window-split)

11
lisp/transpose-windows.el Normal file
View File

@@ -0,0 +1,11 @@
(defun transpose-windows (arg)
"Transpose the buffers shown in two windows."
(interactive "p")
(let ((selector (if (>= arg 0) 'next-window 'previous-window)))
(while (/= arg 0)
(let ((this-win (window-buffer))
(next-win (window-buffer (funcall selector))))
(set-window-buffer (selected-window) next-win)
(set-window-buffer (funcall selector) this-win)
(select-window (funcall selector)))
(setq arg (if (plusp arg) (1- arg) (1+ arg))))))

19
lisp/zim.el Normal file
View File

@@ -0,0 +1,19 @@
(defun zim-timestamp ()
(with-temp-buffer
(insert (format-time-string "%Y-%m-%dT%H:%M:%S%z"))
(forward-char -2)
(insert ":")
(buffer-string)))
(defun insert-zim-timestamp ()
(interactive)
(insert (zim-timestamp)))
(defun insert-zim-header ()
(interactive)
(save-excursion
(goto-char (point-min))
(insert
(concat "Content-Type: text/x-zim-wiki\n"
"Wiki-Format: zim 0.4\n"
"Creation-Date: " (zim-timestamp) "\n\n"))))