diff options
Diffstat (limited to 'c-conf.el')
-rw-r--r-- | c-conf.el | 45 |
1 files changed, 43 insertions, 2 deletions
@@ -2,7 +2,7 @@ ;; Copyright (C) 2021 李俊緯 -;; Author: 李俊緯 <durand@MacBook-Pro-de-Severe.local> +;; Author: Durand <mmemmew@gmail.com> ;; Keywords: c, convenience, languages ;; This program is free software; you can redistribute it and/or modify @@ -32,8 +32,17 @@ ;; This proves to be too convenient not to bind. (define-key c-mode-map (vector 'S-tab) #'ff-find-other-file) +;;; prefix map +(defvar durand-c-prefix-map '(keymap) + "The keymap of my custom functions. +This will be bound to the key ù.") + +(let ((map durand-c-prefix-map)) + (define-key map (vector ?i) #'durand-c-include) + (define-key map (vector ?p) #'c-generate-pragma)) + ;; generate pragmas automatically. -(define-key c-mode-map (vector ?ù) #'c-generate-pragma) +(define-key c-mode-map (vector ?ù) durand-c-prefix-map) ;;;###autoload (defun c-generate-pragma () @@ -65,5 +74,37 @@ If invoked on a C file, include the corresponding header file." "c\\(p*\\)$" "h\\1" (buffer-name)))) (newline)))) +;;;###autoload +(defun durand-c-include (&optional arg) + "Include a library. +If ARG is non-nil, ask for the type of the include: whether the +angle bracket type or the quote type." + (interactive) + (let* ((library (read-string "Include: ")) + (type (cond + ((null arg) + (cond + ((string-match-p "^\\(std\\|string.h\\)" library) + 'angle) + ('quote))) + (t + (intern + (completing-read "Which type? " + '("angle" "quote") + nil t)))))) + (save-restriction + (widen) + (save-excursion + (goto-char (point-min)) + (re-search-forward "^#include" nil t) + (forward-line 0) + (insert "#include " + (cond ((eq type 'angle) "<") + ((eq type 'quote) "\"")) + library + (cond ((eq type 'angle) ">") + ((eq type 'quote) "\"")) + "\n"))))) + (provide 'c-conf) ;;; c-conf.el ends here |