-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add loc command * Add test for loc command * comment out test
- Loading branch information
Showing
6 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (C) 2024 the Eask authors. | ||
* | ||
* 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 | ||
* the Free Software Foundation; either version 3, or (at your option) | ||
* any later version. | ||
* | ||
* This program is 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
exports.command = ['loc [files..]']; | ||
exports.desc = UTIL.hide_cmd('Print LOC information'); | ||
exports.builder = yargs => yargs | ||
.positional( | ||
'[files..]', { | ||
description: 'files to print LOC information', | ||
type: 'array', | ||
}); | ||
|
||
exports.handler = async (argv) => { | ||
await UTIL.e_call(argv, 'core/loc', argv.files); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,11 @@ | |
;; | ||
;; $ eask load | ||
;; | ||
;; | ||
;; Positionals: | ||
;; | ||
;; [files..] specify files to load | ||
;; | ||
|
||
;;; Code: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
;;; core/loc.el --- Print LOC information -*- lexical-binding: t; -*- | ||
|
||
;;; Commentary: | ||
;; | ||
;; Command use to print loc (accept multiple) | ||
;; | ||
;; $ eask loc | ||
;; | ||
;; | ||
;; Positionals: | ||
;; | ||
;; [files..] specify files to print LOC information | ||
;; | ||
|
||
;;; Code: | ||
|
||
(let ((dir (file-name-directory (nth 1 (member "-scriptload" command-line-args))))) | ||
(load (expand-file-name "_prepare.el" | ||
(locate-dominating-file dir "_prepare.el")) | ||
nil t)) | ||
|
||
(defvar eask-loc-lines 0) | ||
(defvar eask-loc-chars 0) | ||
|
||
(defun eask--loc-file (file) | ||
"Insert LOC information for FILE." | ||
(unless (file-directory-p file) | ||
(let ((lines) (chars)) | ||
(with-temp-buffer | ||
(insert-file-contents file) | ||
(setq lines (line-number-at-pos (point-max)) | ||
chars (point-max))) | ||
(cl-incf eask-loc-lines lines) | ||
(cl-incf eask-loc-chars chars) | ||
(insert (format "| %s | %s | %s |\n" file lines chars))))) | ||
|
||
(eask-start | ||
;; Preparation | ||
(eask-with-archives '("gnu" "melpa") | ||
(eask-package-install 'markdown-mode)) | ||
|
||
(require 'markdown-mode) | ||
;; Start LOC | ||
(if-let ((files (or (eask-expand-file-specs (eask-args)) | ||
(eask-package-files))) | ||
(eask-output (get-buffer-create "*eask-output*"))) | ||
(with-current-buffer eask-output | ||
(erase-buffer) | ||
(progn ; Print header | ||
(insert (format "|---|---|---|\n")) | ||
(insert (format "| File | Lines | Characters |\n")) | ||
(insert (format "|---|---|---|\n"))) | ||
(eask-with-progress | ||
"Retrieving LOC information... " | ||
(mapc #'eask--loc-file files) | ||
"done ✓") | ||
(progn ; Print total | ||
(insert (format "|---|---|---|\n")) | ||
(insert (format "| Total | %s | %s |\n" eask-loc-lines eask-loc-chars))) | ||
(progn ; Organize | ||
(goto-char (point-min)) | ||
(markdown-table-align)) | ||
(eask-println "") | ||
(eask-print (buffer-string)) | ||
(eask-println "")) | ||
(eask-info "(No LOC information to print.)"))) | ||
|
||
;;; core/loc.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters