Update personal Lisp files so elint is happy

This commit is contained in:
Gergely Polonkai 2018-03-19 12:08:01 +01:00
parent 2972e061a1
commit 7aa17bdfcc
4 changed files with 94 additions and 44 deletions

View File

@ -1,23 +1,27 @@
;;; buf-manipulation --- Summary
;; Some custom functions for buffer content manipulation ;; Some custom functions for buffer content manipulation
;;
;;; Commentary:
;;; Code:
(defun delete-current-line () (defun delete-current-line ()
"Kill the whole line on which point is" "Kill the whole line on which point is."
(interactive) (interactive)
(beginning-of-line) (beginning-of-line)
(kill-line 1)) (kill-line 1))
(defun copy-func-prototype () (defun copy-func-prototype ()
"Copy the current function's prototype to the kill-ring" "Copy the current function's prototype to the kill ring."
(interactive) (interactive)
(save-excursion (save-excursion
(beginning-of-defun) (beginning-of-defun)
(setq protocopy-begin (point)) (let ((protocopy-begin (point)))
(forward-list) (forward-list)
(setq protocopy-end (point)) (let ((protocopy-end (point)))
(kill-ring-save protocopy-begin protocopy-end))) (kill-ring-save protocopy-begin protocopy-end)))))
(defun duplicate-line() (defun duplicate-line()
"Duplicate line at point." "Duplicate line at point."
@ -29,15 +33,16 @@
(kill-line) (kill-line)
(yank) (yank)
(open-line 1) (open-line 1)
(next-line 1) (forward-line 1)
(yank))) (yank)))
;; Based on Xah's toggle letter case defun version 2015-12-22
;;
;; URL: http://ergoemacs.org/emacs/modernization_upcase-word.html
(defun toggle-char-case (arg-move-point) (defun toggle-char-case (arg-move-point)
"Toggle the case of the char after point. Based on Xah's toggle letter "Toggle the case of the char after point.
case defun version 2015-12-22
URL `http://ergoemacs.org/emacs/modernization_upcase-word.html' If prefix argument ARG-MOVE-POINT is non-nil, move point after the char."
Version 2016-02-16"
(interactive "P") (interactive "P")
(let ((case-fold-search nil)) (let ((case-fold-search nil))
(cond (cond
@ -88,8 +93,7 @@ Version 2016-02-16"
; Copied from http://whattheemacsd.com/file-defuns.el-02.html ; Copied from http://whattheemacsd.com/file-defuns.el-02.html
(defun delete-current-buffer-file () (defun delete-current-buffer-file ()
"Removes file connected to current buffer and kills the "Remove file connected to current buffer and kill the buffer."
buffer."
(interactive) (interactive)
(let ((filename (buffer-file-name)) (let ((filename (buffer-file-name))
@ -102,8 +106,8 @@ Version 2016-02-16"
(kill-buffer buffer) (kill-buffer buffer)
(message "File '%s' successfully removed" filename))))) (message "File '%s' successfully removed" filename)))))
; delete-char or close eshell ;; delete-char or close eshell
; Copied from https://ryuslash.org/posts/C-d-to-close-eshell.html ;; Copied from https://ryuslash.org/posts/C-d-to-close-eshell.html
(defun eshell-C-d () (defun eshell-C-d ()
"Either call `delete-char' interactively or quit." "Either call `delete-char' interactively or quit."
(interactive) (interactive)
@ -111,7 +115,7 @@ Version 2016-02-16"
(condition-case err (condition-case err
(call-interactively #'delete-char) (call-interactively #'delete-char)
(error (if (and (eq (car err) 'end-of-buffer) (error (if (and (eq (car err) 'end-of-buffer)
(looking-back eshell-prompt-regexp)) (looking-back eshell-prompt-regexp nil))
(kill-buffer) (kill-buffer)
(signal (car err) (cdr err)))))) (signal (car err) (cdr err))))))
@ -119,7 +123,7 @@ Version 2016-02-16"
"Kill or copy the whole line point is on. "Kill or copy the whole line point is on.
If KILL is non-nil, the line gets killed. Otherwise, it gets just If KILL is non-nil, the line gets killed. Otherwise, it gets just
copied to the kill-ring." copied to the kill ring."
(interactive "P") (interactive "P")
(if kill (if kill
@ -128,15 +132,20 @@ copied to the kill-ring."
(end (progn (end-of-line) (point)))) (end (progn (end-of-line) (point))))
(copy-region-as-kill beginning end)))) (copy-region-as-kill beginning end))))
;; Inspired by Bozhidar Batsov's solution:
;;
;; http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/
(defun gpolonkai/move-to-beginning-of-line () (defun gpolonkai/move-to-beginning-of-line ()
"Move to different beginnings of the line; in order: beginning "Move to different beginnings of the line.
of the visual line if `visual-line-mode' is active, the first
non-whitespace (indentation), the actual beginning of the line.
This function will jump between the first character and the
indentation if used multiple times.
Inspired by Bozhidar Batsov's solution: These are, in order:
http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/"
- beginning of the visual line if `visual-line-mode' is active,
- the first non-whitespace (indentation),
- the actual beginning of the line.
This function will jump between the first character and the
indentation if used multiple times."
(interactive) (interactive)
(let ((last-pos (point))) (let ((last-pos (point)))
(when visual-line-mode (when visual-line-mode
@ -152,9 +161,10 @@ http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-l
(back-to-indentation)))) (back-to-indentation))))
(defun gpolonkai/move-to-end-of-line () (defun gpolonkai/move-to-end-of-line ()
"Move to the end of the line. If `visual-line-mode' is active, "Move to the end of the line.
jump to the end of the visual line first. The jump to the
actual end of the line." If `visual-line-mode' is active, jump to the end of the visual
line first. Then jump to the actual end of the line."
(interactive) (interactive)
(let ((last-pos (point))) (let ((last-pos (point)))
(when visual-line-mode (when visual-line-mode
@ -167,8 +177,9 @@ http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-l
(defvar gpolonkai/last-killed-buffer-file-name (defvar gpolonkai/last-killed-buffer-file-name
nil nil
"The last killed buffer. Used by `gpolonkai/kill-this-buffer' "The last killed buffer.
and `gpolonkai/undo-buffer-kill'.")
Used by `gpolonkai/kill-this-buffer' and `gpolonkai/undo-buffer-kill'.")
(defun gpolonkai/kill-this-buffer () (defun gpolonkai/kill-this-buffer ()
"Kill the current buffer, but save the buffer file name so it can be undone." "Kill the current buffer, but save the buffer file name so it can be undone."
@ -177,10 +188,16 @@ http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-l
(kill-this-buffer)) (kill-this-buffer))
(defun gpolonkai/undo-buffer-kill () (defun gpolonkai/undo-buffer-kill ()
"Undo killing the last buffer. Esentially it visits the file again." "Undo killing the last buffer.
Esentially it visits the file again."
(interactive) (interactive)
(if gpolonkai/last-killed-buffer-file-name (if gpolonkai/last-killed-buffer-file-name
(progn (progn
(find-file gpolonkai/last-killed-buffer-file-name) (find-file gpolonkai/last-killed-buffer-file-name)
(setq gpolonkai/last-killed-buffer-file-name nil)) (setq gpolonkai/last-killed-buffer-file-name nil))
(message "The buffer last killed didnt visit a file."))) (message "The buffer last killed didnt visit a file.")))
(provide 'buf-manipulation)
;;; buf-manipulation.el ends here

View File

@ -1,6 +1,13 @@
;;; file-manip --- Summary
;;; Commentary:
;;; Code:
(defun open-this-file-as-other-user (user) (defun open-this-file-as-other-user (user)
"Edit current file as USER, using `tramp' and `sudo'. If the current "Edit current file as USER, using `tramp' and `sudo'.
buffer is not visiting a file, prompt for a file name."
If the current buffer is not visiting a file, prompt for a file
name."
(interactive "sEdit as user (default: root): ") (interactive "sEdit as user (default: root): ")
(when (string= "" user) (when (string= "" user)
(setq user "root")) (setq user "root"))
@ -22,3 +29,7 @@ buffer is not visiting a file, prompt for a file name."
(interactive) (interactive)
(find-file-other-window (concat (file-name-as-directory org-directory) (find-file-other-window (concat (file-name-as-directory org-directory)
"index.org"))) "index.org")))
(provide 'file-manip)
;;; file-manip.el ends here

View File

@ -1,16 +1,22 @@
;;; gp-prog --- Summary
;;; Commentary:
;;; Code:
(defun gpolonkai/prog-in-string-p () (defun gpolonkai/prog-in-string-p ()
"Return `t' if point is inside a string." "Return t if point is inside a string."
(nth 3 (syntax-ppss))) (nth 3 (syntax-ppss)))
(defun gpolonkai/prog-in-comment-p () (defun gpolonkai/prog-in-comment-p ()
"Return `t' if point is inside a comment." "Return t if point is inside a comment."
(nth 4 (syntax-ppss))) (nth 4 (syntax-ppss)))
(defun gpolonkai/python-add-docstring () (defun gpolonkai/python-add-docstring ()
"Add a Python docstring to the current thing. If point is "Add a Python docstring to the current thing.
inside a function, add docstring to that. If point is in a
class, add docstring to that. If neither, add docstring to the If point is inside a function, add docstring to that. If point
beginning of the file." is in a class, add docstring to that. If neither, add docstring
to the beginning of the file."
(interactive) (interactive)
(save-restriction (save-restriction
(widen) (widen)
@ -35,3 +41,7 @@
(open-line-below) (open-line-below)
(insert "\"\"\"") (insert "\"\"\"")
(open-line-above))) (open-line-above)))
(provide 'gp-prog)
;;; gp-prog.el ends here

View File

@ -1,15 +1,21 @@
;;; package --- Summary
;;; Commentary:
;;; Code:
(defun org-space-key (&optional arg) (defun org-space-key (&optional arg)
"Insert two spaces after a period." "Insert two spaces after a period.
ARG will be passed down verbatim to `self-insert-command'"
(interactive "p") (interactive "p")
(when (looking-back "[.!?…]") (when (looking-back "[.!?…]" nil)
(call-interactively 'self-insert-command arg)) (call-interactively 'self-insert-command arg))
(call-interactively 'self-insert-command arg)) (call-interactively 'self-insert-command arg))
;; From http://pages.sachachua.com/.emacs.d/Sacha.html ;; From http://pages.sachachua.com/.emacs.d/Sacha.html
(defun sachachua/fill-or-unfill-paragraph (&optional unfill region) (defun sachachua/fill-or-unfill-paragraph (&optional unfill region)
"Fill paragraph (or REGION). "Fill (or unfill, if UNFILL is non-nil) paragraph (or REGION)."
With the prefix argument UNFILL, unfill it instead."
(interactive (progn (interactive (progn
(barf-if-buffer-read-only) (barf-if-buffer-read-only)
(list (if current-prefix-arg 'unfill) t))) (list (if current-prefix-arg 'unfill) t)))
@ -20,7 +26,9 @@
(defun so/query-swap-strings (from-string (defun so/query-swap-strings (from-string
to-string to-string
&optional delimited start end) &optional delimited start end)
"Swap occurrences of FROM-STRING and TO-STRING." "Swap occurrences of FROM-STRING and TO-STRING.
DELIMITED, START, and END are passed down verbatim to `perform-replace'."
(interactive (interactive
(let ((common (let ((common
(query-replace-read-args (query-replace-read-args
@ -40,3 +48,7 @@
,to-string ,to-string
,from-string)) ,from-string))
t t delimited nil nil start end)) t t delimited nil nil start end))
(provide 'text-manip)
;;; text-manip.el ends here